Skip to content
Permalink
Browse files

Fixes #8712. Bubble custom events to the window when they are trigger…

…ed. Ride that, Cowboy!
  • Loading branch information...
dmethvin committed Apr 7, 2011
1 parent 879be3d commit b7dd8404c52518bc4d71b0e715c506252d651a3f
Showing with 8 additions and 3 deletions.
  1. +2 −1 src/event.js
  2. +6 −2 test/unit/event.js
@@ -359,7 +359,8 @@ jQuery.event = {
}
} catch ( ieError1 ) {}

cur = cur.parentNode || cur.ownerDocument;
// Bubble up to document, then to window
cur = cur.parentNode || cur.ownerDocument || cur === event.target.ownerDocument && window;
} while ( cur && !event.isPropagationStopped() );

// If nobody prevented the default action, do it now
@@ -779,26 +779,30 @@ test("trigger() shortcuts", function() {
});

test("trigger() bubbling", function() {
expect(14);
expect(17);

var doc = 0, html = 0, body = 0, main = 0, ap = 0;
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;

jQuery(window).bind("click", function(e){ win++; });
jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
jQuery("html").bind("click", function(e){ html++; });
jQuery("body").bind("click", function(e){ body++; });
jQuery("#main").bind("click", function(e){ main++; });
jQuery("#ap").bind("click", function(){ ap++; return false; });

jQuery("html").trigger("click");
equals( win, 1, "HTML bubble" );
equals( doc, 1, "HTML bubble" );
equals( html, 1, "HTML bubble" );

jQuery("body").trigger("click");
equals( win, 2, "Body bubble" );
equals( doc, 2, "Body bubble" );
equals( html, 2, "Body bubble" );
equals( body, 1, "Body bubble" );

jQuery("#main").trigger("click");
equals( win, 3, "Main bubble" );
equals( doc, 3, "Main bubble" );
equals( html, 3, "Main bubble" );
equals( body, 2, "Main bubble" );

0 comments on commit b7dd840

Please sign in to comment.
You can’t perform that action at this time.