]> source.dussan.org Git - jquery.git/commitdiff
Fix #11621, $(document).trigger() must bubble to window.
authorDave Methvin <dave.methvin@gmail.com>
Sat, 12 May 2012 17:38:33 +0000 (13:38 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Sat, 12 May 2012 18:23:50 +0000 (14:23 -0400)
src/event.js
test/unit/event.js

index 46036c5cf2147510e92b1d8ce93076928fca2b4d..6351d0b53e9a577e846c725ea1d608736a905e1d 100644 (file)
@@ -315,14 +315,13 @@ jQuery.event = {
 
                        bubbleType = special.delegateType || type;
                        cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
-                       old = null;
-                       for ( ; cur; cur = cur.parentNode ) {
+                       for ( old = elem; cur; cur = cur.parentNode ) {
                                eventPath.push([ cur, bubbleType ]);
                                old = cur;
                        }
 
                        // Only add window if we got to document (e.g., not plain obj or detached DOM)
-                       if ( old && old === elem.ownerDocument ) {
+                       if ( old === (elem.ownerDocument || document) ) {
                                eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
                        }
                }
@@ -782,7 +781,7 @@ if ( !jQuery.support.submitBubbles ) {
                        });
                        // return undefined since we don't need an event listener
                },
-               
+
                postDispatch: function( event ) {
                        // If form was submitted by the user, bubble the event up the tree
                        if ( event._submit_bubble ) {
index 57adb0443a90a163b48f2aa21e1c2d8ecd670547..d5582190a999558a3ef1f5a061eb376730434399 100644 (file)
@@ -928,7 +928,7 @@ test("trigger() shortcuts", function() {
 });
 
 test("trigger() bubbling", function() {
-       expect(17);
+       expect(18);
 
        var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
 
@@ -964,6 +964,9 @@ test("trigger() bubbling", function() {
        equal( main, 1, "ap bubble" );
        equal( ap, 1, "ap bubble" );
 
+       jQuery( document ).trigger("click");
+       equal( win, 4, "doc bubble" );
+       
        // manually clean up events from elements outside the fixture
        jQuery(document).unbind("click");
        jQuery("html, body, #qunit-fixture").unbind("click");