]> source.dussan.org Git - jquery.git/commitdiff
Fix #12739. Keep namespace when triggering with an Event. Close gh-972.
authorAllen J Schmidt Jr <cobrasoft@gmail.com>
Tue, 16 Oct 2012 00:22:19 +0000 (20:22 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 19 Oct 2012 20:42:13 +0000 (16:42 -0400)
AUTHORS.txt
src/event.js
test/unit/event.js

index b2dd8bfabc33c8cee68bd5300d5bf1a1ab6c6f03..773862920a9224c379a46babfd51d93e13afcc5c 100644 (file)
@@ -134,4 +134,5 @@ Nikita Govorov <nikita.govorov@gmail.com>
 Michael Pennisi <mike@mikepennisi.com>
 Markus Staab <markus.staab@redaxo.de>
 Daniel Gálvez <dgalvez@editablething.com>
-James Huston <james@jameshuston.net>
\ No newline at end of file
+James Huston <james@jameshuston.net>
+Allen J Schmidt Jr <cobrasoft@gmail.com>
\ No newline at end of file
index 8e0f59afcd41eb55c4a4627c5613f6a168b7714b..299f71615f1e39a9211a2f6f506cfd209e64d8aa 100644 (file)
@@ -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 ) ) {
index d6c24436a3ec82058a28291767a84ad0052a1323..7536919951a043b641535277cabf9cb01debd58f 100644 (file)
@@ -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(
+                       "<div id='parent'><div id='child'></div></div>"
+               ),
+               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" );
+});
+
+