patch for #809 - add the addEventType() function to the OpenLayers.Events objects so that subclasses can safely add new event types without modifying their parents' constant values

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3622 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-07-06 18:30:09 +00:00
parent bee797430d
commit a14b5bdc7e
2 changed files with 43 additions and 4 deletions
+27
View File
@@ -304,6 +304,33 @@
}
function test_06_Events_addEventType(t) {
t.plan( 6 );
var mapDiv = OpenLayers.Util.getElement('map');
var obj = {result: 0};
var eventTypes = ["doThingA", "doThingB"];
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
t.eq( events.listeners["doThingA"].length, 0, "event type passed as passed as param to OpenLayers.Events constructor correctly set up" );
t.eq( events.listeners["doThingB"].length, 0, "event type passed as passed as param to OpenLayers.Events constructor correctly set up" );
var newEventType = "onFoo";
t.ok( events.listeners[newEventType] == null, "event type not yet registered has null entry in listeners array");
events.addEventType(newEventType);
t.eq( events.listeners[newEventType].length, 0, "event type passed to addEventType correctly set up" );
var func = function () {};
events.register( "doThingA", obj, func );
t.eq( events.listeners["doThingA"].length, 1, "listener correctly registered" );
events.addEventType("doThingsA");
t.eq( events.listeners["doThingA"].length, 1, "event type passed to addEventType correctly does nothing if clashes with already defined event type" );
}
// -->