From b7dd8404c52518bc4d71b0e715c506252d651a3f Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 6 Apr 2011 22:11:58 -0400 Subject: [PATCH] Fixes #8712. Bubble custom events to the window when they are triggered. Ride that, Cowboy! --- src/event.js | 3 ++- test/unit/event.js | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index 424ad02f..0323ffb7 100644 --- a/src/event.js +++ b/src/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 diff --git a/test/unit/event.js b/test/unit/event.js index 6ad112c0..a26f54d2 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -779,10 +779,11 @@ 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++; }); @@ -790,15 +791,18 @@ test("trigger() bubbling", function() { 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" );