[Pkg-javascript-commits] [dojo] 08/13: Fix emit events on 'window' and 'document' objects

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:57 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.9.3
in repository dojo.

commit ec9b4282c097d7b2221e6c87f9f0b276299ffa24
Author: Eduardo Matos <edu.de.matos at hotmail.com>
Date:   Sat Jul 20 10:05:37 2013 -0300

    Fix emit events on 'window' and 'document' objects
---
 on.js          |  3 ++-
 tests/on/on.js | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/on.js b/on.js
index 5b5a7f0..0bcd461 100644
--- a/on.js
+++ b/on.js
@@ -330,7 +330,8 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff", "./
 				// that would be a lot of extra code, with little benefit that I can see, seems 
 				// best to use the generic constructor and copy properties over, making it 
 				// easy to have events look like the ones created with specific initializers
-				var nativeEvent = target.ownerDocument.createEvent("HTMLEvents");
+				var ownerDocument = target.ownerDocument || document;
+				var nativeEvent = ownerDocument.createEvent("HTMLEvents");
 				nativeEvent.initEvent(type, !!event.bubbles, !!event.cancelable);
 				// and copy all our properties over
 				for(var i in event){
diff --git a/tests/on/on.js b/tests/on/on.js
index c5aeecd..bb5c031 100644
--- a/tests/on/on.js
+++ b/tests/on/on.js
@@ -152,6 +152,18 @@ define([
 			signal.remove();
 			signal2.remove();
 
+			// make sure 'document' and 'window' can also emit events
+			var eventEmitted;
+			var globalObjects = [document, window];
+			for(var i = 0, len = globalObjects.length; i < len; i++) {
+				eventEmitted = false;
+				on(globalObjects[i], 'custom-test-event', function () {
+					eventEmitted = true;
+				});
+				on.emit(globalObjects[i], 'custom-test-event', {});
+				t.is(true, eventEmitted);
+			}
+
 			// test out event delegation
 			if(query){
 				// if dojo.query is loaded, test event delegation

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list