diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index 6e1229167d..f5c70c25e6 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -93,6 +93,12 @@ OpenLayers.Control.LayerSwitcher.prototype = */ singleClick: function(evt) { var div = Event.element(evt); + + // See comment about OL #57 fix below. + // If the click occurred on the corner spans we need + // to make sure we act on the actual label tab instead. + div = div.labelElement || div; + var layer = div.layer; if (this.mode == "radio") { for(var i=0; i < this.backdrops.length; i++) { @@ -162,6 +168,14 @@ OpenLayers.Control.LayerSwitcher.prototype = color: "white", blend: false}); + // extend the event handlers to operate on the + // rounded corners as well. (Fixes OL #57.) + var spanElements=backdropLabel.parentNode.getElementsByTagName("span"); + + for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { + this._setEventHandlers(spanElements[currIdx], backdropLabel); + } + this.setTabActivation(backdropLabel, layer.getVisibility()); }, @@ -171,12 +185,18 @@ OpenLayers.Control.LayerSwitcher.prototype = @param {DOMElement} div @param {Boolean} activate */ - _setEventHandlers : function(element) { + _setEventHandlers : function(element, labelDiv) { // We only want to respond to a mousedown event. element.onclick = this.ignoreEvent.bindAsEventListener(this); element.ondblclick = this.ignoreEvent.bindAsEventListener(this); element.onmousedown = this.singleClick.bindAsEventListener(this); + + // If we are operating on a corner span we need to store a + // reference to the actual tab. (See comment about OL #57 fix above.) + if (labelDiv) { + element.labelElement = labelDiv; + } }, /**