fixed for-loop scoping on createDropDown() closures
This commit is contained in:
@@ -60,9 +60,11 @@ function createDropDown(title, items) {
|
|||||||
|
|
||||||
// give it a name
|
// give it a name
|
||||||
$(n).data("label",item.label);
|
$(n).data("label",item.label);
|
||||||
jQuery(n).click(function(e) {
|
jQuery(n).click((function(local_idx, local_item) {
|
||||||
item.action(idx, item.label, e.target.checked);
|
return function(e) {
|
||||||
});
|
item.action(local_idx, local_item, e.target.checked);
|
||||||
|
};
|
||||||
|
})(idx, item));
|
||||||
|
|
||||||
// if its checked, its gotta do something, do that here.
|
// if its checked, its gotta do something, do that here.
|
||||||
if (item.checked) {
|
if (item.checked) {
|
||||||
@@ -149,11 +151,11 @@ function drawMapControls() {
|
|||||||
"label": signGroup.label,
|
"label": signGroup.label,
|
||||||
"checked": signGroup.checked,
|
"checked": signGroup.checked,
|
||||||
"icon": iconURL,
|
"icon": iconURL,
|
||||||
"action": function(n, l, checked) {
|
"action": function(n, item, checked) {
|
||||||
jQuery.each(markerCollection[l], function(i,elem) {
|
jQuery.each(markerCollection[item.label], function(i,elem) {
|
||||||
elem.setVisible(checked);
|
elem.setVisible(checked);
|
||||||
});
|
});
|
||||||
//alert(signGroup.label);
|
//alert(item.label);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -170,8 +172,8 @@ function drawMapControls() {
|
|||||||
items.push({
|
items.push({
|
||||||
"label": regionGroup.label,
|
"label": regionGroup.label,
|
||||||
"checked": regionGroup.checked,
|
"checked": regionGroup.checked,
|
||||||
"action": function(n, l, checked) {
|
"action": function(n, item, checked) {
|
||||||
jQuery.each(regionCollection[l], function(i,elem) {
|
jQuery.each(regionCollection[item.label], function(i,elem) {
|
||||||
elem.setMap(checked ? map : null); // Thanks to LeastWeasel for this line!
|
elem.setMap(checked ? map : null); // Thanks to LeastWeasel for this line!
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -186,14 +188,14 @@ function drawMapControls() {
|
|||||||
var items = [];
|
var items = [];
|
||||||
for (idx in overlayMapTypes) {
|
for (idx in overlayMapTypes) {
|
||||||
var overlay = overlayMapTypes[idx];
|
var overlay = overlayMapTypes[idx];
|
||||||
items.push({"label": overlay.name, "checked": false,
|
items.push({"label": overlay.name, "checked": false, "overlay": overlay,
|
||||||
"action": function(i, l, checked) {
|
"action": function(i, item, checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
map.overlayMapTypes.push(overlay);
|
map.overlayMapTypes.push(item.overlay);
|
||||||
} else {
|
} else {
|
||||||
var idx_to_delete = -1;
|
var idx_to_delete = -1;
|
||||||
map.overlayMapTypes.forEach(function(e, j) {
|
map.overlayMapTypes.forEach(function(e, j) {
|
||||||
if (e == overlay) { idx_to_delete = j; }
|
if (e == item.overlay) { idx_to_delete = j; }
|
||||||
});
|
});
|
||||||
if (idx_to_delete >= 0) {
|
if (idx_to_delete >= 0) {
|
||||||
map.overlayMapTypes.removeAt(idx_to_delete);
|
map.overlayMapTypes.removeAt(idx_to_delete);
|
||||||
|
|||||||
Reference in New Issue
Block a user