minimize triggerEvent code path when no listeners, r=tschaub (closes #2014)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9142 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -693,6 +693,12 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* chain of listeners will stop getting called.
|
||||
*/
|
||||
triggerEvent: function (type, evt) {
|
||||
var listeners = this.listeners[type];
|
||||
|
||||
// fast path
|
||||
if(!listeners || listeners.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// prep evt object with object & div references
|
||||
if (evt == null) {
|
||||
@@ -707,25 +713,21 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
// execute all callbacks registered for specified type
|
||||
// get a clone of the listeners array to
|
||||
// allow for splicing during callbacks
|
||||
var listeners = (this.listeners[type]) ?
|
||||
this.listeners[type].slice() : null;
|
||||
if ((listeners != null) && (listeners.length > 0)) {
|
||||
var continueChain;
|
||||
for (var i=0, len=listeners.length; i<len; i++) {
|
||||
var callback = listeners[i];
|
||||
// bind the context to callback.obj
|
||||
continueChain = callback.func.apply(callback.obj, [evt]);
|
||||
|
||||
if ((continueChain != undefined) && (continueChain == false)) {
|
||||
// if callback returns false, execute no more callbacks.
|
||||
break;
|
||||
}
|
||||
}
|
||||
// don't fall through to other DOM elements
|
||||
if (!this.fallThrough) {
|
||||
OpenLayers.Event.stop(evt, true);
|
||||
var listeners = listeners.slice(), continueChain;
|
||||
for (var i=0, len=listeners.length; i<len; i++) {
|
||||
var callback = listeners[i];
|
||||
// bind the context to callback.obj
|
||||
continueChain = callback.func.apply(callback.obj, [evt]);
|
||||
|
||||
if ((continueChain != undefined) && (continueChain == false)) {
|
||||
// if callback returns false, execute no more callbacks.
|
||||
break;
|
||||
}
|
||||
}
|
||||
// don't fall through to other DOM elements
|
||||
if (!this.fallThrough) {
|
||||
OpenLayers.Event.stop(evt, true);
|
||||
}
|
||||
return continueChain;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user