fix remove() function and add test
git-svn-id: http://svn.openlayers.org/trunk/openlayers@871 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -111,7 +111,7 @@ OpenLayers.Events.prototype = {
|
||||
|
||||
/**
|
||||
* @param {String} type
|
||||
* @param {Object} obj
|
||||
* @param {Object} obj If none specified, defaults to this.object
|
||||
* @param {Function} func
|
||||
*/
|
||||
unregister: function (type, obj, func) {
|
||||
@@ -127,11 +127,15 @@ OpenLayers.Events.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
/** Remove all listeners for a given event type. If type is not registered,
|
||||
* does nothing.
|
||||
*
|
||||
* @param {String} type
|
||||
*/
|
||||
remove: function(type) {
|
||||
this.listeners[type].pop();
|
||||
if (this.listeners[type] != null) {
|
||||
this.listeners[type] = new Array();
|
||||
}
|
||||
},
|
||||
|
||||
/** Trigger a specified registered event
|
||||
|
||||
@@ -105,7 +105,34 @@
|
||||
|
||||
}
|
||||
|
||||
function test_03_Events_triggerEvent(t) {
|
||||
function test_03_Events_remove(t) {
|
||||
|
||||
t.plan( 2 );
|
||||
|
||||
var mapDiv = $('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB", "doThingC"];
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
|
||||
var func = function () { this.result++ }
|
||||
var func2 = function () { this.result-- }
|
||||
var func3 = function () { this.result = this.result + 3; }
|
||||
|
||||
events.register( "doThingA", obj, func );
|
||||
events.register( "doThingA", obj, func2 );
|
||||
events.register( "doThingA", null, func3 );
|
||||
|
||||
events.remove("doThingA");
|
||||
|
||||
t.eq( events.listeners["doThingA"].length, 0, "remove() correctly clears the event listeners" );
|
||||
|
||||
events.remove("chicken");
|
||||
t.ok( events.listeners["chicken"] == null, "remove on non-enabled event does not break or accidentally enable the event");
|
||||
|
||||
}
|
||||
|
||||
function test_04_Events_triggerEvent(t) {
|
||||
|
||||
t.plan( 2 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user