For controls with multiple handlers, we now tack them on to a handlers object. The base destroy takes care of the handlers. r=crschmidt,uz/2 (closes #1338)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6106 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-08 15:52:03 +00:00
parent 03a827de4d
commit 49e0bff93d
9 changed files with 132 additions and 147 deletions

View File

@@ -14,7 +14,7 @@
"new OpenLayers.Control.DragFeature returns an instance");
t.eq(control.layer, "bar",
"constructor sets layer correctly");
t.eq(control.featureHandler.geometryTypes, "foo",
t.eq(control.handlers.feature.geometryTypes, "foo",
"constructor sets options correctly on feature handler");
}
@@ -24,14 +24,15 @@
var layer = new OpenLayers.Layer.Vector();
map.addLayer(layer);
var control = new OpenLayers.Control.DragFeature(layer);
control.dragHandler.destroy = function() {
control.handlers.drag.destroy = function() {
t.ok(true,
"control.destroy calls destroy on drag handler");
}
control.featureHandler.destroy = function() {
control.handlers.feature.destroy = function() {
t.ok(true,
"control.destroy calls destroy on feature handler");
}
control.destroy();
}
@@ -43,10 +44,10 @@
map.addLayer(layer);
var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control);
t.ok(!control.featureHandler.active,
t.ok(!control.handlers.feature.active,
"feature handler is not active prior to activating control");
control.activate();
t.ok(control.featureHandler.active,
t.ok(control.handlers.feature.active,
"feature handler is active after activating control");
}
@@ -58,11 +59,11 @@
var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control);
control.dragHandler.deactivate = function() {
control.handlers.drag.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on drag handler");
}
control.featureHandler.deactivate = function() {
control.handlers.feature.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on feature handler");
}
@@ -78,7 +79,7 @@
map.addControl(control);
control.activate();
t.ok(!control.dragHandler.active,
t.ok(!control.handlers.drag.active,
"drag handler is not active before over a feature");
// simulate a mouseover on a feature
@@ -89,7 +90,7 @@
t.eq(control.feature, "foo",
"control gets the proper feature from the feature handler");
t.ok(control.dragHandler.active,
t.ok(control.handlers.drag.active,
"drag handler activated when over a feature");
}

View File

@@ -172,7 +172,7 @@
control.handleKeypress(dKey);
// now make sure nothing happens if the vertex is mid-drag
control.dragControl.dragHandler.dragging = true;
control.dragControl.handlers.drag.dragging = true;
control.handleKeypress(delKey);
// reset modified methods
@@ -305,11 +305,11 @@
control.dragControl.map.div = {};
control.dragControl.map.div.style = {};
control.dragControl.map.div.cursor = "foo";
control.dragControl.dragHandler.deactivate = function() {
control.dragControl.handlers.drag.deactivate = function() {
this.active = false;
}
control.resetVertices();
t.ok(!control.dragControl.dragHandler.active, "resetVertices deactivates drag handler");
t.ok(!control.dragControl.handlers.drag.active, "resetVertices deactivates drag handler");
control.dragControl.map = null;
control.destroy();

View File

@@ -5,61 +5,63 @@
function test_Control_Navigation_constructor (t) {
t.plan( 2 );
var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function() {
t.ok(true, "OpenLayers.Control's constructor called");
};
var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function() {
t.ok(true, "OpenLayers.Control's constructor called");
};
var control = new OpenLayers.Control.Navigation();
t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" );
OpenLayers.Control.prototype.initialize = temp;
OpenLayers.Control.prototype.initialize = temp;
}
function test_Control_Navigation_destroy (t) {
t.plan(10);
var temp = OpenLayers.Control.prototype.destroy;
OpenLayers.Control.prototype.destroy = function() {
t.ok(true, "OpenLayers.Control's destroy called");
};
t.plan(9);
var temp = OpenLayers.Control.prototype.destroy;
OpenLayers.Control.prototype.destroy = function() {
t.ok(true, "OpenLayers.Control's destroy called");
temp.call(this);
};
var control = {
'deactivate': function() {
t.ok(true, "navigation control deactivated before being destroyed");
},
'dragPan': {
'destroy': function() {
t.ok(true, "dragPan destroyed");
}
},
'zoomBox': {
'destroy': function() {
t.ok(true, "zoomBox destroyed");
}
},
'wheelHandler': {
'destroy': function() {
t.ok(true, "wheelHandler destroyed");
}
},
'clickHandler': {
'destroy': function() {
t.ok(true, "clickHandler destroyed");
}
}
};
var control = {
'deactivate': function() {
t.ok(true, "navigation control deactivated before being destroyed");
},
'dragPan': {
'destroy': function() {
t.ok(true, "dragPan destroyed");
}
},
'zoomBox': {
'destroy': function() {
t.ok(true, "zoomBox destroyed");
}
},
handlers: {
'wheel': {
'destroy': function() {
t.ok(true, "wheelHandler destroyed");
}
},
'click': {
'destroy': function() {
t.ok(true, "clickHandler destroyed");
}
}
}
};
//this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
//this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.zoomBox, null, "'zoomBox' set to null");
t.eq(control.wheelHandler, null, "'wheelHandler' set to null");
t.eq(control.clickHandler, null, "'clickHandler' set to null");
t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.zoomBox, null, "'zoomBox' set to null");
t.eq(control.handlers, null, "handlers set to null");
OpenLayers.Control.prototype.destroy = temp;
OpenLayers.Control.prototype.destroy = temp;
}
</script>

View File

@@ -51,7 +51,7 @@
t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon");
t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat");
control.dragHandler = {
control.handlers.drag = {
last: new OpenLayers.Pixel(5,5),
destroy: function() {}
};