triggerEvent can now be called with additional arguments for the listeners - this means instead of getting news like 'hey, someone won the lottery' listeners now get news like 'hey, you won the lottery' - in addition, the triggerer gets back the return from the listener, so if a listener wants to say 'dont tell anyone else' the triggerer gets that message - thanks for the reviews (closes #1189)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5398 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -586,13 +586,18 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIMethod: triggerEvent
|
||||
* Trigger a specified registered event
|
||||
* Trigger a specified registered event.
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
* evt - {Event}
|
||||
* evt - {Event}
|
||||
* args - {Array} Optional array of arguments to call the listener with.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The last listener return. If a listener returns false, the
|
||||
* chain of listeners will stop getting called.
|
||||
*/
|
||||
triggerEvent: function (type, evt) {
|
||||
triggerEvent: function (type, evt, args) {
|
||||
|
||||
// prep evt object with object & div references
|
||||
if (evt == null) {
|
||||
@@ -600,6 +605,12 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
}
|
||||
evt.object = this.object;
|
||||
evt.element = this.element;
|
||||
|
||||
if(!args) {
|
||||
args = [evt];
|
||||
} else {
|
||||
args.unshift(evt);
|
||||
}
|
||||
|
||||
// execute all callbacks registered for specified type
|
||||
// get a clone of the listeners array to
|
||||
@@ -607,17 +618,13 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
var listeners = (this.listeners[type]) ?
|
||||
this.listeners[type].slice() : null;
|
||||
if ((listeners != null) && (listeners.length > 0)) {
|
||||
var continueChain;
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
var callback = listeners[i];
|
||||
var continueChain;
|
||||
if (callback.obj != null) {
|
||||
// use the 'call' method to bind the context to callback.obj
|
||||
continueChain = callback.func.call(callback.obj, evt);
|
||||
} else {
|
||||
continueChain = callback.func(evt);
|
||||
}
|
||||
// bind the context to callback.obj
|
||||
continueChain = callback.func.apply(callback.obj, args);
|
||||
|
||||
if ((continueChain != null) && (continueChain == false)) {
|
||||
if ((continueChain != undefined) && (continueChain == false)) {
|
||||
// if callback returns false, execute no more callbacks.
|
||||
break;
|
||||
}
|
||||
@@ -627,6 +634,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
OpenLayers.Event.stop(evt, true);
|
||||
}
|
||||
}
|
||||
return continueChain;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user