diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index 36d755304c..215a4f0c60 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -96,16 +96,16 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { */ destroy: function() { OpenLayers.Control.prototype.destroy.apply(this, arguments); - for(var i = this.controls.length - 1 ; i >= 0; i--) { - if(this.controls[i].events) { - this.controls[i].events.un({ - "activate": this.redraw, - "deactivate": this.redraw, - scope: this + for (var ctl, i = this.controls.length - 1; i >= 0; i--) { + ctl = this.controls[i]; + if (ctl.events) { + ctl.events.un({ + activate: this.iconOn, + deactivate: this.iconOff }); } - OpenLayers.Event.stopObservingElement(this.controls[i].panel_div); - this.controls[i].panel_div = null; + OpenLayers.Event.stopObservingElement(ctl.panel_div); + ctl.panel_div = null; } this.activeState = null; }, @@ -172,13 +172,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { this.div.innerHTML = ""; if (this.active) { for (var i=0, len=this.controls.length; i 0), "Redraw called on add panel to map " + - panel.redrawsCount + " times."); - t.ok((panel.active),"Panel is active after add panel to map."); - - panel.redrawsCount = 0; + t.eq(getListenerLength(toolControl.events,"activate"), toolEventListenerLength+1, + "toolControl additional listener for \"activate\" after adding Panel to the map."); + t.ok((panel.redrawsCount > 0), "Redraw called on add panel to map " + + panel.redrawsCount + " times."); + t.ok((panel.active),"Panel is active after add panel to map."); + + panel.redrawsCount = 0; panel.addControls(new AnotherToolControl()); t.ok((panel.redrawsCount > 0), "Redraw called on add control to panel after add panel to map " + - panel.redrawsCount + " times."); + panel.redrawsCount + " times."); panel.deactivate(); - panel.redrawsCount = 0; - panel.activate(); + panel.redrawsCount = 0; + panel.activate(); t.ok((panel.redrawsCount > 0),"Redraw called on activate panel " + - panel.redrawsCount + " times."); + panel.redrawsCount + " times."); panel.activateControl(toolControl); t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active && !buttonControl.active, "activated one tool control, the other one is inactive and the toggle & button controls also."); - panel.redrawsCount = 0; panel.activateControl(toggleControl); - t.eq(panel.redrawsCount, 1, "Redraw called on activated toggle " + - panel.redrawsCount + " times."); + t.eq(toggleControl.panel_div.className,"mbControlTestToggleItemActive", + "className of icon div for toggle control is active."); t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active, "activated the toggle control, which has no influence on the tool & togggle controls."); panel.activateControl(buttonControl); @@ -79,16 +94,21 @@ buttonControl.activate(); t.ok(buttonControl.active && toolControl.active && !anotherToolControl.active && toggleControl.active, "activated the button control, which has no influence on the tool & togggle controls."); - - panel.redrawsCount = 0; + panel.activateControl(anotherToolControl); - t.ok((panel.redrawsCount > 0), - "Redraw called on activated tool control " + panel.redrawsCount + - " times."); + t.eq(anotherToolControl.panel_div.className,"mbControlTestToolItemActive", + "className of icon div for anotherToolControl is active."); + t.eq(toolControl.panel_div.className,"olControlZoomBoxItemInactive", + "className of icon div for toolControl is inactive."); t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active, "activated the other tool control, the first one is inactive and the toggle control still active."); t.ok(buttonControl.active, "activated the other tool control, the button control still active."); + + panel.destroy(); + t.eq(getListenerLength(toolControl.events,"activate"), toolEventListenerLength, + "toolControl additional listeners removed after destroy Panel."); + map.destroy(); } function test_Control_Panel_titles (t) { t.plan(2);