diff --git a/AUTHORS.txt b/AUTHORS.txt index b2dd8bfab..773862920 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -134,4 +134,5 @@ Nikita Govorov Michael Pennisi Markus Staab Daniel Gálvez -James Huston \ No newline at end of file +James Huston +Allen J Schmidt Jr \ No newline at end of file diff --git a/src/event.js b/src/event.js index 8e0f59afc..299f71615 100644 --- a/src/event.js +++ b/src/event.js @@ -212,7 +212,7 @@ jQuery.event = { // Event object or event type var cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType, type = event.type || event, - namespaces = []; + namespaces = event.namespace ? event.namespace.split(".") : []; // focus/blur morphs to focusin/out; ensure we're not firing them right now if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { diff --git a/test/unit/event.js b/test/unit/event.js index d6c24436a..753691995 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2923,3 +2923,40 @@ asyncTest("trigger click on checkbox, fires change event", function() { start(); }).trigger("click"); }); + +test( "Namespace preserved when passed an Event (#12739)", function() { + expect( 4 ); + + var markup = jQuery( + "
" + ), + triggered = 0, + fooEvent; + + markup.find("div") + .addBack() + .on( "foo.bar", function( e ) { + if ( !e.handled ) { + triggered++; + e.handled = true; + equal( e.namespace, "bar", "namespace is bar" ); + jQuery( e.target ).find("div").each(function() { + jQuery( this ).triggerHandler( e ); + }); + } + }) + .on( "foo.bar2", function( e ) { + ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id ); + }); + + markup.trigger("foo.bar"); + markup.trigger( jQuery.Event("foo.bar") ); + fooEvent = jQuery.Event("foo"); + fooEvent.namespace = "bar"; + markup.trigger( fooEvent ); + markup.remove(); + + equal( triggered, 3, "foo.bar triggered" ); +}); + +