Ticket #614: panel.patch
| File panel.patch, 3.7 kB (added by crschmidt, 2 years ago) |
|---|
-
lib/OpenLayers/Control/Panel.js
old new 33 33 this.controls = []; 34 34 }, 35 35 36 destroy: function() { 37 OpenLayers.Control.prototype.destroy.apply(this, arguments); 38 for(var i = this.controls.length - 1 ; i >= 0; i--) { 39 OpenLayers.Event.stopObservingElement(this.controls[i].panel_div); 40 this.controls[i].panel_div = null; 41 } 42 }, 43 36 44 activate: function() { 37 45 if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { 38 46 for(var i = 0; i < this.controls.length; i++) { … … 46 54 return false; 47 55 } 48 56 }, 57 49 58 deactivate: function() { 50 59 if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { 51 60 for(var i = 0; i < this.controls.length; i++) { … … 78 87 this.div.innerHTML = ""; 79 88 if (this.active) { 80 89 for (var i = 0; i < this.controls.length; i++) { 81 var element = document.createElement("div"); 82 var textNode = document.createTextNode(" "); 90 var element = this.controls[i].panel_div; 83 91 if (this.controls[i].active) { 84 92 element.className = this.controls[i].displayClass + "ItemActive"; 85 93 } else { 86 94 element.className = this.controls[i].displayClass + "ItemInactive"; 87 95 } 88 var onClick = function (ctrl, evt) {89 OpenLayers.Event.stop(evt ? evt : window.event);90 this.activateControl(ctrl);91 };92 var control = this.controls[i];93 OpenLayers.Event.observe(element, "click",94 onClick.bind(this, control));95 OpenLayers.Event.observe(element, "mousedown",96 OpenLayers.Event.stop.bindAsEventListener());97 OpenLayers.Event.observe(element, "mouseup",98 OpenLayers.Event.stop.bindAsEventListener());99 96 this.div.appendChild(element); 100 97 } 101 98 } … … 128 125 controls = [controls]; 129 126 } 130 127 this.controls = this.controls.concat(controls); 128 129 // Give each control a panel_div which will be used later. 130 // Access to this div is via the panel_div attribute of the 131 // control added to the panel. 132 for (var i = 0; i < controls.length; i++) { 133 var element = document.createElement("div"); 134 var textNode = document.createTextNode(" "); 135 controls[i].panel_div = element; 136 OpenLayers.Event.observe(controls[i].panel_div, "click", 137 this.onClick.bind(this, controls[i])); 138 OpenLayers.Event.observe(controls[i].panel_div, "mousedown", 139 OpenLayers.Event.stop.bindAsEventListener()); 140 OpenLayers.Event.observe(controls[i].panel_div, "mouseup", 141 OpenLayers.Event.stop.bindAsEventListener()); 142 } 143 131 144 if (this.map) { // map.addControl() has already been called on the panel 132 145 for (var i = 0; i < controls.length; i++) { 133 146 this.map.addControl(controls[i]); … … 137 150 } 138 151 }, 139 152 153 onClick: function (ctrl, evt) { 154 OpenLayers.Event.stop(evt ? evt : window.event); 155 this.activateControl(ctrl); 156 }, 157 140 158 /** @final @type String */ 141 159 CLASS_NAME: "OpenLayers.Control.Panel" 142 160 });
