From e023b4c075e61103f68302b293c4b8987ddb05b4 Mon Sep 17 00:00:00 2001 From: follower Date: Thu, 15 Jun 2006 17:35:21 +0000 Subject: [PATCH] Fix #57. Add event handlers to the spans created by adding corners to the layer switcher tabs. (Somewhat hacky.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@603 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/LayerSwitcher.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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; + } }, /**