Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for keeping namespace when triggering an event using an Event #972

Closed
wants to merge 2 commits into from

2 participants

Commits on Oct 16, 2012
  1. @cobrajs
Commits on Oct 17, 2012
  1. @cobrajs

    Added test cases

    cobrajs authored
This page is out of date. Refresh to see the latest.
Showing with 57 additions and 1 deletion.
  1. +1 −1  src/event.js
  2. +56 −0 test/unit/event.js
View
2  src/event.js
@@ -217,7 +217,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
56 test/unit/event.js
@@ -2947,3 +2947,59 @@ asyncTest("trigger click on checkbox, fires change event", function() {
start();
}).trigger("click");
});
+
+test("Namespace preserved when passed an Event (#12739)", function() {
+ expect(1);
+
+ var markup = jQuery(
+ "<div id='parent'><div id='child'></div></div>"
+ );
+
+ var incorrect = false;
+
+ markup.find( "div" ).andSelf()
+ .on("foo.bar", function(e) {
+ if (!e.handled) {
+ e.handled = true;
+ jQuery(e.target).find("div").each(function() {
+ jQuery(this).triggerHandler(e);
+ });
+ }
+ })
+ .on("foo.bar", function(e) { })
+ .on("foo.bar2", function(e) {
+ incorrect = true;
+ });
+
+ markup.trigger("foo.bar");
+
+ markup.remove();
+
+ ok(!incorrect, "foo.bar2 not called");
+});
+
+test("Namespace preserved when passed a generated Event (#12739)", function() {
+ expect(2);
+
+ var markup = jQuery(
+ "<div id='parent'></div>"
+ );
+
+ markup
+ .on("foo.bar", function(e) {
+ ok(true, "foo.bar called");
+ })
+ .on("foo.bar2", function(e) {
+ ok(true, "foo.bar2 called");
+ });
+
+ var e = jQuery.Event("foo");
+ e.namespace = "bar";
+ markup.trigger(e);
+
+ e = jQuery.Event("foo.bar");
+ markup.trigger(e);
+
+ markup.remove();
+});
+
Something went wrong with that request. Please try again.