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:
+18
-16
@@ -693,6 +693,12 @@ OpenLayers.Events = OpenLayers.Class({
|
|||||||
* chain of listeners will stop getting called.
|
* chain of listeners will stop getting called.
|
||||||
*/
|
*/
|
||||||
triggerEvent: function (type, evt) {
|
triggerEvent: function (type, evt) {
|
||||||
|
var listeners = this.listeners[type];
|
||||||
|
|
||||||
|
// fast path
|
||||||
|
if(!listeners || listeners.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// prep evt object with object & div references
|
// prep evt object with object & div references
|
||||||
if (evt == null) {
|
if (evt == null) {
|
||||||
@@ -707,25 +713,21 @@ OpenLayers.Events = OpenLayers.Class({
|
|||||||
// execute all callbacks registered for specified type
|
// execute all callbacks registered for specified type
|
||||||
// get a clone of the listeners array to
|
// get a clone of the listeners array to
|
||||||
// allow for splicing during callbacks
|
// allow for splicing during callbacks
|
||||||
var listeners = (this.listeners[type]) ?
|
var listeners = listeners.slice(), continueChain;
|
||||||
this.listeners[type].slice() : null;
|
for (var i=0, len=listeners.length; i<len; i++) {
|
||||||
if ((listeners != null) && (listeners.length > 0)) {
|
var callback = listeners[i];
|
||||||
var continueChain;
|
// bind the context to callback.obj
|
||||||
for (var i=0, len=listeners.length; i<len; i++) {
|
continueChain = callback.func.apply(callback.obj, [evt]);
|
||||||
var callback = listeners[i];
|
|
||||||
// bind the context to callback.obj
|
|
||||||
continueChain = callback.func.apply(callback.obj, [evt]);
|
|
||||||
|
|
||||||
if ((continueChain != undefined) && (continueChain == false)) {
|
if ((continueChain != undefined) && (continueChain == false)) {
|
||||||
// if callback returns false, execute no more callbacks.
|
// if callback returns false, execute no more callbacks.
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
// don't fall through to other DOM elements
|
|
||||||
if (!this.fallThrough) {
|
|
||||||
OpenLayers.Event.stop(evt, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// don't fall through to other DOM elements
|
||||||
|
if (!this.fallThrough) {
|
||||||
|
OpenLayers.Event.stop(evt, true);
|
||||||
|
}
|
||||||
return continueChain;
|
return continueChain;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user