From b0020d6f4087c345f152536963425a5efc4ecf61 Mon Sep 17 00:00:00 2001 From: euzuro Date: Wed, 17 May 2006 02:52:57 +0000 Subject: [PATCH] push constant variables out of the class, make them static. other small coding standards changes. git-svn-id: http://svn.openlayers.org/trunk/openlayers@79 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/LayerSwitcher.js | 62 +++++++++++++++++-------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index 3c215bfa44..e3ac371240 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -2,16 +2,25 @@ * @class */ OpenLayers.Control.LayerSwitcher = Class.create(); + +/** color used in the UI to show a layer is active/displayed +* +* @final +* @type String +*/ +OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR = "darkblue"; + +/** color used in the UI to show a layer is deactivated/hidden +* +* @final +* @type String +*/ +OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR = "lightblue"; + + OpenLayers.Control.LayerSwitcher.prototype = Object.extend( new OpenLayers.Control(), { - /** color used in the UI to show a layer is active/displayed - * @type String */ - ACTIVE_COLOR: "darkblue", - - /** color used in the UI to show a layer is deactivated/hidden - * @type String */ - NONACTIVE_COLOR: "lightblue", /** * @constructor @@ -21,6 +30,7 @@ OpenLayers.Control.LayerSwitcher.prototype = }, /** + * @returns A reference to the DIV DOMElement containing the switcher tabs * @type DOMElement */ draw: function() { @@ -31,6 +41,7 @@ OpenLayers.Control.LayerSwitcher.prototype = }, /** + * @returns A reference to the DIV DOMElement containing the switcher tabs * @type DOMElement */ redraw: function() { @@ -44,17 +55,24 @@ OpenLayers.Control.LayerSwitcher.prototype = new OpenLayers.Size(200, 20)); div.innerHTML = this.map.layers[i].name; - var status = this.map.layers[i].getVisibility(); - if (!status) { - div.style.backgroundColor = this.NONACTIVE_COLOR; - div.style.color = this.ACTIVE_COLOR; + var visible = this.map.layers[i].getVisibility(); + if (!visible) { + div.style.backgroundColor = + OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; + div.style.color = + OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; } else { - div.style.backgroundColor = this.ACTIVE_COLOR; - div.style.color = this.NONACTIVE_COLOR; + div.style.backgroundColor = + OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; + div.style.color = + OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; } div.style.padding = "5px"; + + //tag references onto the div for use in event handlers div.layerid = i; div.map = this.map; + div.ondblclick = this.doubleClick.bindAsEventListener(div); div.onmousedown = this.singleClick.bindAsEventListener(div); } @@ -68,15 +86,19 @@ OpenLayers.Control.LayerSwitcher.prototype = * @param {event} evt */ singleClick: function(evt) { - var status = this.map.layers[this.layerid].getVisibility(); - this.map.layers[this.layerid].setVisibility(!status); - if (status) { - this.style.backgroundColor = this.NONACTIVE_COLOR; - this.style.color = this.ACTIVE_COLOR; + var visible = this.map.layers[this.layerid].getVisibility(); + if (visible) { + this.style.backgroundColor = + OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; + this.style.color = + OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; } else { - this.style.backgroundColor = this.ACTIVE_COLOR; - this.style.color = this.NONACTIVE_COLOR; + this.style.backgroundColor = + OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; + this.style.color = + OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; } + this.map.layers[this.layerid].setVisibility(!visible); Event.stop(evt); },