OpenLayers OpenLayers

Ticket #614: panel.patch

File panel.patch, 3.7 kB (added by crschmidt, 2 years ago)
  • lib/OpenLayers/Control/Panel.js

    old new  
    3333        this.controls = []; 
    3434    }, 
    3535 
     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 
    3644    activate: function() { 
    3745        if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { 
    3846            for(var i = 0; i < this.controls.length; i++) { 
     
    4654            return false; 
    4755        } 
    4856    }, 
     57     
    4958    deactivate: function() { 
    5059        if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { 
    5160            for(var i = 0; i < this.controls.length; i++) { 
     
    7887        this.div.innerHTML = ""; 
    7988        if (this.active) { 
    8089            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; 
    8391                if (this.controls[i].active) { 
    8492                    element.className = this.controls[i].displayClass + "ItemActive"; 
    8593                } else {     
    8694                    element.className = this.controls[i].displayClass + "ItemInactive"; 
    8795                }     
    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()); 
    9996                this.div.appendChild(element); 
    10097            } 
    10198        } 
     
    128125            controls = [controls]; 
    129126        } 
    130127        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 
    131144        if (this.map) { // map.addControl() has already been called on the panel 
    132145            for (var i = 0; i < controls.length; i++) { 
    133146                this.map.addControl(controls[i]); 
     
    137150        } 
    138151    }, 
    139152     
     153    onClick: function (ctrl, evt) { 
     154        OpenLayers.Event.stop(evt ? evt : window.event); 
     155        this.activateControl(ctrl); 
     156    }, 
     157     
    140158    /** @final @type String */ 
    141159    CLASS_NAME: "OpenLayers.Control.Panel" 
    142160});