I want to create a function that creates several boxes for me by capturing the title, text, photo, link and text of the link. That these values change, but the overall shape of the boxes is a model
each div contain with Different values taken by jquery codes:
<div>
<img></img>
<h3></h3>
<p></p>
<a><span></span></a>
</div>
i try it but not complete and not work:
$(document).ready(function () {
var newDiv = document.getElementById("reports-box");
function makenewDivBox(options) {
var div = document.createElement("div");
for (var i = 0; i < options.length; i++) {
var div = document.createElement("div");
var img = document.createElement("img");
var title = document.createElement("h3");
var description = document.createElement("p");
var link = document.createElement("a");
var linkText = document.createElement("span");
img.id = img1;
img.type = "img";
img.src = options[i].src;
title.id = Title1;
title.type = "h3";
title.text = options[i].text;
description.id = des1;
description.type = "p";
description.text = options[i].text;
link.id = link1;
link.type = "hrefa";
link.text = options[i].text;
linkText.id = des1;
linkText.type = "hrefa";
linkText.text = options[i].text;
div.appendChild(img)
div.appendChild(title)
div.appendChild(description)
div.appendChild(link)
div.appendChild(linkText)
}
newDiv.appendChild(div);
}
var options1 = [{
title="t1",
img: "url('image/j1.png')",
description: "content1",
link: "www.link1.com",
linkText: "click here"
}]
var options2 = [{
title="t2",
img: "url('image/j2.png')",
description: "content2",
link: "www.link2.com",
linkText: "more here"
}]
var options3 = [{
title="t3",
img: "url('image/j3.png')",
description: "content3",
link: "www.link3.com",
linkText: "report here"
}]
var options4 = [{
title="t4",
img: "url('image/j4.png')",
description: "content4",
link: "www.link4.com",
linkText: "more details here"
}]
makenewDivBox(options1);
makenewDivBox(options2);
makenewDivBox(options3);
makenewDivBox(options4);
});
I was able to solve it myself.
I'll put the code here, maybe it will be useful for someone:
in html:
<div class="rowReports"></div>
in jquery:
$(document).ready(function () {
var Titels = [
"title1",
"title2",
"title3",
"title4",
"title5",
"title6",
"title7",
"title8"
];
var imgSrces = [
"/FrontEnd/media/image/Nashriyat.png",
"/FrontEnd/media/image/plan.png",
"/FrontEnd/media/image/majameElmi.png",
"/FrontEnd/media/image/kargahAmuzeshi.png",
"/FrontEnd/media/image/targoman.png",
"/FrontEnd/media/image/scoma.png",
"/FrontEnd/media/image/elmsanji.png",
"/FrontEnd/media/image/tablighat.png"
];
var Descriptions = [
"Desc1",
"Desc2 ",
"Desc3",
"Desc4",
"Desc5",
"Desc6",
"Desc7",
"Desc8",
"Desc9"
]
var Links = [
"/Page/frmDefault1.aspx",
"/Page/frmDefault2.aspx",
"/Page/frmDefault3.aspx",
"/Page/frmDefault4.aspx",
"/Page/frmDefault5.aspx",
"/Page/frmDefault6.aspx",
"/Page/frmDefault7.aspx",
"/Page/frmDefault8.aspx"
];
var TextLinks = [
"more report",
"send email",
"more details",
"join group",
"more info",
"add number",
"more",
"continue"
];
for (i = 0; i<Titels.length; i++)
$('.rowReports').append(
$('<div/>')
.attr("id", "newDiv"+i)
.addClass("newDiv reports-box bloated")
.append(' <a href="' + Links[i] + '">' +
'<img class="servicesPic" alt="info" src="' + imgSrces[i] + '"/>' + '<h3>' + Titels[i] + '</h3>' +
'<p>' + Descriptions[i] + '</p>' +
'<span>' + TextLinks[i] + '</span>'+ '</a>'
)
);
});
Related
I wish to generate a custom dropdown filter, based on categories from a database.
How is this achieved?
In my example, this is (poorly) implemented with some hard coding and duplication.
var serviceOverlays = [
{name:"Cardiology", value:"cardiology"},
{name:"Opthamology", value:"opthamology"}
];
var oSelect = L.control({position : 'topright'});
oSelect.onAdd = function (map) {
var overlayParent = document.getElementById('new-parent'); // overlays div
var node = L.DomUtil.create('select', 'leaflet-control');
node.innerHTML = '<option value="cardiologist">Cardioligist</option><option value="opthamology">Opthamology</option>';
overlayParent.appendChild(node);
L.DomEvent.disableClickPropagation(node);
L.DomEvent.on(node,'change',function(e){
var select = e.target;
for(var name in serviceOverlays){
serviceOverlays[name].removeFrom(map);
}
serviceOverlays[select.value].addTo(map);
});
Fiddle
I created a Control for you:
L.Control.Select = L.Control.extend({
options: {
position : 'topright'
},
initialize(layers,options) {
L.setOptions(this,options);
this.layers = layers;
},
onAdd(map) {
this.overlayParent = L.DomUtil.create('div', 'leaflet-control select-control');
this.node = L.DomUtil.create('select', 'leaflet-control',this.overlayParent);
L.DomEvent.disableClickPropagation(this.node);
this.updateSelectOptions();
L.DomEvent.on(this.node,'change',(e)=>{
var select = e.target;
for(var value in this.layers){
this.layers[value].layer.removeFrom(map);
}
this.layers[select.value].layer.addTo(map);
});
return this.overlayParent;
},
updateSelectOptions(){
var options = "";
if(this.layers){
for(var value in this.layers){
var layer = this.layers[value];
options += '<option value="'+value+'">'+layer.name+'</option>';
}
}
this.node.innerHTML = options;
},
changeLayerData(layers){
this.layers = layers;
this.updateSelectOptions();
}
});
var oSelect = new L.Control.Select(serviceOverlays,{position : 'topright'}).addTo(map);
The data structure have to be:
var serviceOverlays = {
"cardiology": {name:"Cardiology", layer: cities},
"opthamology": {name:"Opthamology", layer: badCities}
};
Demo: https://jsfiddle.net/falkedesign/1rLntbo5/
You can also change the data dynamicl< with oSelect.changeLayerData(serviceOverlays2)
I have this situation with eclipse , whenever I formated the js script of table ,sometimes eclipse changed the code and sometime much complex when there is no backup.
original Code:
if (isEdit == true) {
positionSpanTag = "<span class='position input-group-addon'><i class='fa fa-lock'></i>";
meberSpanTag = "<span class='memberName input-group-addon'><i class='fa fa-lock'></i>";
} else {
positionSpanTag = "<span class='position input-group-addon'><i class='fa fa-search'></i>";
meberSpanTag = "<span class='memberName input-group-addon'><i class='fa fa-search'></i>";
}
var deleteButton = "<a style='cursor:pointer' class='btn-fab-mini' id='btnRemove'><i class='fa fa-trash'></i></a>";
var inputHiddenTag = "<input type='hidden'>";
var inputTag = "<input type='text' class='form-control' style='width: 180px;'>";
var spanCalenderTag = "<span class='input-group-addon '><i class='fa fa-calendar' aria-hidden='true'></i></span>";
After, eclipse changed itself:
if (isEdit == true) {
positionSpanTag = "_$tag_____________________________________$tag__________________$ta";
meberSpanTag = "_$tag_______________________________________$tag__________________$ta";
} else {
positionSpanTag = "_$tag_____________________________________$tag____________________$ta";
meberSpanTag = "_$tag_______________________________________$tag____________________$ta";
}
var deleteButton = "_$tag__________________________________________________________$tag___________________$ta_$ta";
var inputHiddenTag = "_$tag_________________";
var inputTag = "_$tag__________________________________________________________";
var spanCalenderTag = "_$tag_____________________________$tag_________________________________________$ta_$tag__";
I have submitted the bug report on this here.
I created a plugin and widget, the content is generated dynamically in a dialog, when the dialog is closed, the content is inserted into the CKEditor window, but the content itself cannot be edited.
How can I make it that the widget content can be edited from the main CKEditor input after it has been created via the dialog?
Plugin Code
(function() {
CKEDITOR.plugins.add( 'cc_widget', {
icons: "cc_widget_button",
init: function(editor) {
// Styles
editor.addContentsCss( this.path + 'cc-widget.css' + '?' + new Date());
var str_html = "<div class=\"credit-card credit-card-widget\" data-cke-widget-editable=\"true\"> " +
"<div class=\"h3\"><a id=\"card-title-link\" href=\"/card-details/card-name\">CARD NAME</a></div>" +
"<div class=\"card-info\">" +
"<div class=\"card-image\">" +
"<a id=\"card-image-link\" href=\"/card-details/card-name\">" +
"<img id=\"card-image\" alt=\"CARD NAME\" src=\"\">" +
"</a>" +
"</div>" +
"<div class=\"card-details\">" +
"<div class=\"h4\">Fees and interest</div>" +
"<dl id=\"card-attributes\">" +
"<dt>Annual fee:</dt> " +
"<dd id=\"annual-fee\">$ANNUAL FEE</dd>" +
"<dd id=\"annual-fee-note\" class=\"note\">annual fee note</dd>" +
"<dt>Purchase interest rate:</dt> " +
"<dd id=\"int-purch\">INT RATE%</dd>" +
"<dd id=\"int-purch-note\" class=\"note\">intrest rate note</dd>" +
"<dt>Cash advance rate:</dt> " +
"<dd id=\"cash-adv\">CASH ADV RATE%</dd>" +
"<dd id=\"cash-adv-note\" class=\"note\">cash adv note</dd>" +
"<dt>Balance transfer rate:</dt> " +
"<dd id=\"balance-trans\">BALANCE TRANS RATE%</dd>" +
"<dd id=\"balance-trans-note\" class=\"note\">balance trans note</dd>" +
"<dt>Rewards Rate:</dt> " +
"<dd id=\"reward-rate\">REWARDS RATE</dd>" +
"<dt>Bonus Offer:</dt> " +
"<dd id=\"bonus-offer\">BONUS OFFER</dd>" +
"<dt>Card Type:</dt> " +
"<dd id=\"card-type\">CARD TYPE(S)</dd>" +
"<dt>Credit Needed:</dt> " +
"<dd id=\"credit-needed\">CREDIT SCORE</dd>" +
"</dl>" +
"</div>" +
"</div>" +
"<div class=\"card-description\">" +
"<p>Add a card description here</p>" +
"<div class=\"buttons\" style=\"text-align:center;\">" +
"<a class=\"btn secondary\" id=\"learn-more\" href=\"/card-details/card-name\\\">Learn More</a> </div>" +
"</div>" +
"</div>";
// Dialog
CKEDITOR.dialog.add( 'cc_widget', this.path + 'dialog.js' );
// Widget definition
editor.widgets.add("cc_widget",{
dialog : "cc_widget",
init : function(){
var card_title_link = this.element.findOne('#card-title-link');
this.data.card_title_link_url = card_title_link.getAttribute("href");
this.data.card_title_link_text = card_title_link.getHtml();
var card_image_link = this.element.findOne('#card-image-link');
this.data.card_image_link_url = card_image_link.getAttribute("href");
var card_image = this.element.findOne('#card-image');
this.data.card_image_alt = card_image.getAttribute("alt");
this.data.card_image_src = card_image.getAttribute("src");
var annual_fee = this.element.findOne('#annual-fee');
var annual_fee_note = this.element.findOne('#annual-fee-note');
this.data.annual_fee_text = annual_fee.getHtml();
this.data.annual_fee_note_text = annual_fee_note.getHtml();
var purchase_interest_rate = this.element.findOne('#int-purch');
var interest_info = this.element.findOne('#int-purch-note');
this.data.purchase_interest_rate = purchase_interest_rate.getHtml();
this.data.purchase_interest_rate_note = interest_info.getHtml();
var cash_advance_rate = this.element.findOne('#cash-adv');
var cash_advance_info = this.element.findOne('#cash-adv-note');
this.data.cash_advance_rate = cash_advance_rate.getHtml();
this.data.cash_advance_rate_note = cash_advance_info.getHtml();
var balance_transfer_rate = this.element.findOne('#balance-trans');
var balance_transfer_info = this.element.findOne('#balance-trans-note');
this.data.balance_transfer_rate = balance_transfer_rate.getHtml();
this.data.balance_transfer_rate_note = balance_transfer_info.getHtml();
var reward_rate = this.element.findOne('#reward-rate');
this.data.reward_rate = reward_rate.getHtml();
var bonus_offer = this.element.findOne('#bonus-offer');
this.data.bonus_offer = bonus_offer.getHtml();
var card_type = this.element.findOne('#card-type');
this.data.card_type = card_type.getHtml();
var credit_needed = this.element.findOne('#credit-needed');
this.data.credit_needed = credit_needed.getHtml();
var learn_more = this.element.findOne('#learn-more');
this.data.learn_more = learn_more.getAttribute("href");
var card_data = this.element.findOne('#card_data');
this.data.card_data = (card_data ? card_data : '');
},
upcast : function(element) {
return element.hasClass("credit-card-widget");
},
template : str_html ,
editables : {
card_title_link: {
selector: '#card-title-link'
},
card_image_link: {
selector: '#card-image-link'
},
card_image: {
selector: '#card-image'
},
annual_fee: {
selector: '#annual-fee'
},
annual_fee_note: {
selector: '#annual-fee-note'
},
purchase_interest_rate: {
selector: '#int-purch'
},
interest_info: {
selector: '#int-purch-note'
},
cash_advance_rate: {
selector: '#cash-adv'
},
cash_advance_info: {
selector: '#cash-adv-note'
},
balance_transfer_rate: {
selector: '#balance-trans'
},
balance_transfer_info: {
selector: '#balance-trans-note'
},
reward_rate: {
selector: '#reward-rate'
},
bonus_offer: {
selector: '#bonus-offer'
},
card_type: {
selector: '#card-type'
},
credit_needed: {
selector: '#credit-needed'
},
card_description: {
selector: '#card-description'
},
},
data : function() {
console.log(this);
console.log(this.data);
var card_title_link = this.element.findOne('#card-title-link');
card_title_link.setHtml(this.data.card_data.card_name);
card_title_link.setAttribute('href', '/card-details/' + this.data.card_data.card_slug);
var card_image_link = this.element.findOne('#card-image-link');
card_image_link.setAttribute('href', '/card-details/' + this.data.card_data.card_slug);
var card_image = this.element.findOne('#card-image');
card_image.setAttribute('alt', this.data.card_data.card_name);
card_image.setAttribute('src', this.data.card_data.card_image);
var annual_fee = this.element.findOne('#annual-fee');
var annual_fee_note = this.element.findOne('#annual-fee-note');
annual_fee.setHtml('$' + this.data.card_data.annual_fee);
if(this.data.card_data.annual_fee_info){
annual_fee_note.removeAttribute( 'style' );
annual_fee_note.setHtml(this.data.card_data.annual_fee_info);
}else {
annual_fee_note.setAttribute('style', 'display:none;');
annual_fee_note.setHtml('');
}
var purchase_interest_rate = this.element.findOne('#int-purch');
var purchase_interest_rate_note = this.element.findOne('#int-purch-note');
purchase_interest_rate.setHtml(this.data.card_data.purchase_interest_rate);
if(this.data.card_data.annual_fee_info){
purchase_interest_rate_note.removeAttribute( 'style' );
purchase_interest_rate_note.setHtml(this.data.card_data.interest_info);
}else {
purchase_interest_rate_note.setAttribute('style', 'display:none;');
purchase_interest_rate_note.setHtml('');
}
var cash_advance_rate = this.element.findOne('#cash-adv');
var cash_advance_info = this.element.findOne('#cash-adv-note');
cash_advance_rate.setHtml(this.data.card_data.cash_advance_rate + '%');
if(this.data.card_data.annual_fee_info){
cash_advance_info.removeAttribute( 'style' );
cash_advance_info.setHtml(this.data.card_data.cash_advance_info);
}else {
cash_advance_info.setAttribute('style', 'display:none;');
cash_advance_info.setHtml('');
}
var balance_transfer_rate = this.element.findOne('#balance-trans');
var balance_transfer_info = this.element.findOne('#balance-trans-note');
balance_transfer_rate.setHtml(this.data.card_data.balance_transfer_rate + '%');
if(this.data.card_data.annual_fee_info){
balance_transfer_info.removeAttribute( 'style' );
balance_transfer_info.setHtml(this.data.card_data.balance_transfer_info);
}else {
balance_transfer_info.setAttribute('style', 'display:none;');
balance_transfer_info.setHtml('');
}
var reward_rate = this.element.findOne('#reward-rate');
reward_rate.setHtml(this.data.card_data.rewards_rate);
var bonus_offer = this.element.findOne('#bonus-offer');
bonus_offer.setHtml(this.data.card_data.bonus_offer);
var card_type = this.element.findOne('#card-type');
card_type.setHtml(this.data.card_data.card_type);
var credit_needed = this.element.findOne('#credit-needed');
credit_needed.setHtml(this.data.card_data.credit_needed);
var learn_more = this.element.findOne('#learn-more');
learn_more.setAttribute('href', '/card-details/' + this.data.card_data.card_slug);
}
});
// Button action
editor.addCommand( 'add_cc_widget_box', {
exec : function(editor) {
editor.execCommand("cc_widget");
}
});
// Button definition
editor.ui.addButton( 'cc_widget_button', {
label: 'Add cc-widget link',
command: 'add_cc_widget_box',
icon: this.path + 'cc-widget.png'
});
}
});})();
TIA
You should try to set contenteditable="false" attribute to root tag of content which you insert into ckeditor
I am using typeahead to add autosuggest functions to a wordpress searchform. As a result I expect two columns, column 1 -> Posttype Post, column 2 -> Posttype page seperation like a hr, followd by posttype media.
I am using three datasets (for every posttype a unique dataset), so frontend renders 3 "tt-dataset". As I am using foundation I would need to add a div class="row"before the datasets, add a "large-6 column" after the "tt-dataset" class and add a closing after every "tt-dataset" as well a a closing div for the row.
I think I could add these classes using JS, but I just doesn't feels right. is there any out-of-the-box solution I am missing? Thank you guys!
My Code up to now, it's hardcoded as I am prototyping right now.
<script type="text/javascript" src="typeahead.bundle.js"></script>
<script type="text/javascript">
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
var posts = new Array();
posts[0] = new Object();
posts[0]["name"] = "test Name";
posts[0]["url"] = "http://www.google.com";
posts[0]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[0]["tokens"] = "Post", "Thumbnail", "test";
posts[1] = new Object();
posts[1]["name"] = "test Name2";
posts[1]["url"] = "http://www.bing.com";
posts[1]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[1]["tokens"] = "Post", "Thumbnail", "test";
posts[2] = new Object();
posts[2]["name"] = "test Name3";
posts[2]["url"] = "http://www.yahoo.com";
posts[2]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[2]["tokens"] = "Post", "Thumbnail", "test";
posts[3] = new Object();
posts[3]["name"] = "test Name4";
posts[3]["url"] = "http://www.google.com";
posts[3]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[3]["tokens"] = "Post", "Thumbnail", "test";
posts[4] = new Object();
posts[4]["name"] = "test Name5";
posts[4]["url"] = "http://www.bing.com";
posts[4]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[4]["tokens"] = ['Post', 'Thumbnail', 'test'];
posts[5] = new Object();
posts[5]["name"] = "test Name6";
posts[5]["url"] = "http://www.yahoo.com";
posts[5]["image"] = "https://placeholdit.imgix.net/~text?txtsize=19&txt=the_post_thumbnail%28%29&w=450&h=250&txttrack=0";
posts[5]["tokens"] = ['Post', 'Thumbnail', 'test'];
console.log(posts);
var pages = new Array();
pages[0] = new Object();
pages[0]["name"] = "Page 1";
pages[0]["url"] = "http://www.google.com";
pages[0]["tokens"] = "Impressum", "Imprint";
pages[1] = new Object();
pages[1]["name"] = "Page 2";
pages[1]["url"] = "http://www.bing.com";
pages[1]["tokens"] = "Datenschutz";
pages[2] = new Object();
pages[2]["name"] = "Page 3";
pages[2]["url"] = "http://www.yahoo.com";
pages[2]["tokens"] = "AGB";
pages[3] = new Object();
pages[3]["name"] = "Page 4";
pages[3]["url"] = "http://www.google.com";
pages[3]["tokens"] = "Kontakt", "contact";
var cpts = new Array();
cpts[0] = new Object();
cpts[0]["name"] = "CPT 1";
cpts[0]["url"] = "http://www.google.com";
cpts[0]["tokens"] = "John", "Doe";
cpts[1] = new Object();
cpts[1]["name"] = "CPT 2";
cpts[1]["url"] = "http://www.bing.com";
cpts[1]["tokens"] = "Jane", "Doe";
cpts[2] = new Object();
cpts[2]["name"] = "CPT 3";
cpts[2]["url"] = "http://www.yahoo.com";
cpts[2]["tokens"] = "Max", "Muster";
cpts[3] = new Object();
cpts[3]["name"] = "CPT 4";
cpts[3]["url"] = "http://www.google.com";
cpts[3]["tokens"] = "Marianne", "Muster";
$('.typeahead').typeahead({
hint: true,
highlight: "any",
minLength: 0,
maxItem: 15,
maxItemPerGroup: 2,
searchOnFocus: true,
matcher: function () { return true; },
},
{
name: 'posts',
source: substringMatcher(posts),
display: ['tokens','name','url'],
templates: {
empty: [
'<div class="empty-message">',
'Zu Ihrer Suchanfrage konnten leider keine Treffer gefunden werden.',
'</div>'
].join('\n'),
footer : [
'<div class="see-all-results">',
'Alle Ergebnisse <i class="fa fa-chevron-right"></i>',
'<div>'
].join('\n'),
header : [
'<strong>Beiträge</strong>'
].join('\n'),
suggestion: function(data) {
return '<div class="headline-pic" style="background-image: url("' + data.image + '"); background-size: cover;">' + data.name + '</div>';
}
}
},
{
name: 'pages',
source: substringMatcher(pages),
templates: {
header : [
'<strong>Seiten</strong>'
].join('\n'),
suggestion: function(data) {
return '' + data.name + '<br />';
}
}
}
{
name: 'customs',
source: substringMatcher(cpts),
templates: {
header : [
'<strong>Mitarbeiter</strong>'
].join('\n'),
suggestion: function(data) {
return '' + data.name + '<br />';
}
}
});
</script>
I'm not really sure why the GeoLocation works on my PC, but not my iPhone ... I've got sensor=true within the script call to the API, but apart from that, I'm at a loss. Here's the entire script:
<div id="info"></div>
<div id="map_canvas" style="width:908px; height:420px"></div>
<input type="text" id="addressInput" size="10"/>
<select id="radiusSelect">
<option value="5" selected>5mi</option>
<option value="15" selected>15mi</option>
<option value="25" selected>25mi</option>
<option value="100">100mi</option>
<option value="200">200mi</option>
<option value="4000">4000mi</option>
</select>
<input type="button" value="Search" onclick="searchLocations();">
<div><select id="locationSelect" style="width:100%;visibility:hidden"></select></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCe49sI29q0AVNo9iVvQ-lDlDwZpFZuA4o&sensor=true"></script>
<script type="text/javascript" src="http://gmaps-samples-v3.googlecode.com/svn/trunk/geolocate/geometa.js"></script>
<script type="text/javascript">
var map;
var markers = [];
var infoWindow;
var locationSelect;
function load() {
map = new google.maps.Map(document.getElementById("map_canvas"), {
center: new google.maps.LatLng(40, -100),
zoom: 4,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
infoWindow = new google.maps.InfoWindow();
locationSelect = document.getElementById("locationSelect");
locationSelect.onchange = function() {
var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
if (markerNum != "none") {
google.maps.event.trigger(markers[markerNum], 'click');
}
};
// geolocation
prepareGeolocation();
doGeolocation();
}
function doGeolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
} else {
positionError(-1);
}
}
function positionError(err) {
var msg;
switch(err.code) {
case err.UNKNOWN_ERROR:
msg = "Unable to find your location";
break;
case err.PERMISSION_DENINED:
msg = "Permission denied in finding your location";
break;
case err.POSITION_UNAVAILABLE:
msg = "Your location is currently unknown";
break;
case err.BREAK:
msg = "Attempt to find location took too long";
break;
default:
msg = "Location detection not supported in browser";
}
document.getElementById('info').innerHTML = msg;
}
function positionSuccess(position) {
// Centre the map on the new location
var coords = position.coords || position.coordinate || position;
var latLng = new google.maps.LatLng(coords.latitude, coords.longitude);
map.setCenter(latLng);
map.setZoom(15);
var marker = new google.maps.Marker({
map: map,
position: latLng,
title: 'Why, there you are!'
});
document.getElementById('info').innerHTML = 'Looking for <b>' +
coords.latitude + ', ' + coords.longitude + '</b>...';
// And reverse geocode.
(new google.maps.Geocoder()).geocode({latLng: latLng}, function(resp) {
var place = "You're around here somewhere!";
if (resp[0]) {
var bits = [];
for (var i = 0, I = resp[0].address_components.length; i < I; ++i) {
var component = resp[0].address_components[i];
if (contains(component.types, 'political')) {
bits.push('<b>' + component.long_name + '</b>');
}
}
if (bits.length) {
place = bits.join(' > ');
}
marker.setTitle(resp[0].formatted_address);
}
document.getElementById('info').innerHTML = place;
});
}
function contains(array, item) {
for (var i = 0, I = array.length; i < I; ++i) {
if (array[i] == item) return true;
}
return false;
}
function searchLocations() {
console.log("searching locations...");
var address = document.getElementById("addressInput").value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
searchLocationsNear(results[0].geometry.location);
} else {
alert(address + ' not found');
}
});
}
function clearLocations() {
//infoWindow.close();
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers.length = 0;
locationSelect.innerHTML = "";
var option = document.createElement("option");
option.value = "none";
option.innerHTML = "See all results:";
locationSelect.appendChild(option);
locationSelect.style.visibility = "visible";
}
function searchLocationsNear(center) {
clearLocations();
var radius = document.getElementById('radiusSelect').value;
/* var searchUrl = 'phpsqlajax_search.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius; */
var searchUrl = 'http://dev-imac.local/phpsqlajax_search.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
console.log(searchUrl);
downloadUrl(searchUrl, function(data) {
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markerNodes.length; i++) {
var name = markerNodes[i].getAttribute("name");
var address = markerNodes[i].getAttribute("address");
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
var latlng = new google.maps.LatLng(
parseFloat(markerNodes[i].getAttribute("lat")),
parseFloat(markerNodes[i].getAttribute("lng")));
createOption(name, distance, i);
createMarker(latlng, name, address);
bounds.extend(latlng);
}
map.fitBounds(bounds);
});
}
function createMarker(latlng, name, address) {
var html = "<b>" + name + "</b> <br/>" + address;
var marker = new google.maps.Marker({
map: map,
position: latlng
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
markers.push(marker);
}
function createOption(name, distance, num) {
var option = document.createElement("option");
option.value = num;
option.innerHTML = name + "(" + distance.toFixed(1) + ")";
locationSelect.appendChild(option);
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function parseXml(str) {
if (window.ActiveXObject) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
} else if (window.DOMParser) {
return (new DOMParser).parseFromString(str, 'text/xml');
}
}
function doNothing() {}
window.onload = load();
</script>
First of all,
mapTypeId: 'roadmap',
should be:
mapTypeId: google.maps.MapTypeId.ROADMAP,
but that should cause it to fail in your PC as well.
Other than that, your <script> section should be in the <head> section of the document and not in the <body>. Maybe the iPhone browser is more strict about this than the browser on your PC. What browser(s) are you using in each system? (I'm guessing you're using IE on the PC. Have you tried other browsers?)