Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #12739. Keep namespace when triggering with an Event. Close gh-972.

  • Loading branch information...
commit c6cf30a56e29c7f8e009443611f86a4c0839b689 1 parent b386080
@cobrajs cobrajs authored dmethvin committed
Showing with 40 additions and 2 deletions.
  1. +2 −1  AUTHORS.txt
  2. +1 −1  src/event.js
  3. +37 −0 test/unit/event.js
View
3  AUTHORS.txt
@@ -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>
+James Huston <james@jameshuston.net>
+Allen J Schmidt Jr <cobrasoft@gmail.com>
View
2  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 ) ) {
View
37 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(
+ "<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" );
+});
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.