Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -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 ) ) {
Expand Down
56 changes: 56 additions & 0 deletions test/unit/event.js
Expand Up @@ -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();
});