Commit b6581df5 authored by Dave Methvin's avatar Dave Methvin

Fix #11621, $(document).trigger() must bubble to window.

parent 7799f213
...@@ -315,14 +315,13 @@ jQuery.event = { ...@@ -315,14 +315,13 @@ jQuery.event = {
bubbleType = special.delegateType || type; bubbleType = special.delegateType || type;
cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode; cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
old = null; for ( old = elem; cur; cur = cur.parentNode ) {
for ( ; cur; cur = cur.parentNode ) {
eventPath.push([ cur, bubbleType ]); eventPath.push([ cur, bubbleType ]);
old = cur; old = cur;
} }
// Only add window if we got to document (e.g., not plain obj or detached DOM) // 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 ]); eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
} }
} }
...@@ -782,7 +781,7 @@ if ( !jQuery.support.submitBubbles ) { ...@@ -782,7 +781,7 @@ if ( !jQuery.support.submitBubbles ) {
}); });
// return undefined since we don't need an event listener // return undefined since we don't need an event listener
}, },
postDispatch: function( event ) { postDispatch: function( event ) {
// If form was submitted by the user, bubble the event up the tree // If form was submitted by the user, bubble the event up the tree
if ( event._submit_bubble ) { if ( event._submit_bubble ) {
......
...@@ -928,7 +928,7 @@ test("trigger() shortcuts", function() { ...@@ -928,7 +928,7 @@ test("trigger() shortcuts", function() {
}); });
test("trigger() bubbling", function() { test("trigger() bubbling", function() {
expect(17); expect(18);
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0; var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
...@@ -964,6 +964,9 @@ test("trigger() bubbling", function() { ...@@ -964,6 +964,9 @@ test("trigger() bubbling", function() {
equal( main, 1, "ap bubble" ); equal( main, 1, "ap bubble" );
equal( ap, 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 // manually clean up events from elements outside the fixture
jQuery(document).unbind("click"); jQuery(document).unbind("click");
jQuery("html, body, #qunit-fixture").unbind("click"); jQuery("html, body, #qunit-fixture").unbind("click");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment