Adding eventListeners property to layer, control, and map. Setting this property at construction registers the given listeners based on event type key. r=elemoine (closes #1404)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6435 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-03-05 00:07:46 +00:00
parent 0c03b8e631
commit 894c457fdd
7 changed files with 117 additions and 1 deletions

View File

@@ -29,6 +29,31 @@
t.eq( control.title, titleText, "control.title set correctly" );
}
function test_eventListeners(t) {
t.plan(1);
var method = OpenLayers.Events.prototype.on;
// test that events.on is called at control construction
var options = {
eventListeners: {foo: "bar"}
};
OpenLayers.Events.prototype.on = function(obj) {
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
}
var control = new OpenLayers.Control(options);
OpenLayers.Events.prototype.on = method;
control.destroy();
// if events.on is called again, this will fail due to an extra test
// test control without eventListeners
OpenLayers.Events.prototype.on = function(obj) {
t.fail("events.on called without eventListeners");
}
var control2 = new OpenLayers.Control();
OpenLayers.Events.prototype.on = method;
control2.destroy();
}
function test_Control_destroy(t) {
t.plan(3);

View File

@@ -119,6 +119,31 @@
t.eq(layer.numZoomLevels, numZoomLevels, "numZoomLevels set correctly");
}
function test_eventListeners(t) {
t.plan(1);
var method = OpenLayers.Events.prototype.on;
// test that events.on is called at layer construction
var options = {
eventListeners: {foo: "bar"}
};
OpenLayers.Events.prototype.on = function(obj) {
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
}
var layer = new OpenLayers.Layer("test", options);
OpenLayers.Events.prototype.on = method;
layer.destroy();
// if events.on is called again, this will fail due to an extra test
// test layer without eventListeners
OpenLayers.Events.prototype.on = function(obj) {
t.fail("events.on called without eventListeners");
}
var layer2 = new OpenLayers.Layer("test");
OpenLayers.Events.prototype.on = method;
layer2.destroy();
}
function test_Layer_initResolutions(t) {
t.plan(12);
var map = new OpenLayers.Map("map");

View File

@@ -84,6 +84,32 @@
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );
t.eq( map.theme, 'foo', "map theme set correctly." );
}
function test_eventListeners(t) {
t.plan(1);
var method = OpenLayers.Events.prototype.on;
// test that events.on is called at map construction
var options = {
eventListeners: {foo: "bar"},
controls: []
};
OpenLayers.Events.prototype.on = function(obj) {
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
}
var map = new OpenLayers.Map('map', options);
OpenLayers.Events.prototype.on = method;
map.destroy();
// if events.on is called again, this will fail due to an extra test
// test map without eventListeners
OpenLayers.Events.prototype.on = function(obj) {
t.fail("events.on called without eventListeners");
}
var map2 = new OpenLayers.Map("map", {controls: []});
OpenLayers.Events.prototype.on = method;
map2.destroy();
}
function test_05_Map_center(t) {
t.plan(4);