From 076632122b8c9d181df709ec0ae9b83c6b385f9e Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 4 Jul 2006 13:54:04 +0000 Subject: [PATCH] update triggerEvent() so that it doesnt bomb if user tries to trigger a non-enabled event. Added thorough testing. git-svn-id: http://svn.openlayers.org/trunk/openlayers@875 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 25 ++++++++++++++++--------- tests/test_Events.html | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index fbdf9ca83a..69d12fe6f0 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -158,15 +158,22 @@ OpenLayers.Events.prototype = { // execute all callbacks registered for specified type var listeners = this.listeners[type]; - for (var i = 0; i < listeners.length; i++) { - var callback = listeners[i]; - - // use the 'call' method to bind the context to callback.obj - var continueChain = callback.func.call(callback.obj, evt); - - if ((continueChain != null) && (continueChain == false)) { - // if callback returns false, execute no more callbacks. - break; + if (listeners != null) { + + 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); + } + + if ((continueChain != null) && (continueChain == false)) { + // if callback returns false, execute no more callbacks. + break; + } } } }, diff --git a/tests/test_Events.html b/tests/test_Events.html index 862712c4f3..4e807a1370 100644 --- a/tests/test_Events.html +++ b/tests/test_Events.html @@ -4,6 +4,7 @@