Skip to content

Commit

Permalink
Corrected RegExp to match event namespaces. Fixes #5303.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkatic authored and jeresig committed Nov 25, 2009
1 parent ac00fe5 commit 04dbdb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/event.js
Expand Up @@ -133,7 +133,7 @@ jQuery.event = {
var namespaces = type.split(".");
type = namespaces.shift();
var all = !namespaces.length,
namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join(".*\\.") + "(\\.|$)"),
namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join("\\.(?:.*\\.)?") + "(\\.|$)"),
special = this.special[ type ] || {};

if ( events[ type ] ) {
Expand Down Expand Up @@ -291,7 +291,7 @@ jQuery.event = {
// Cache this now, all = true means, any handler
all = !namespaces.length && !event.exclusive;

var namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join(".*\\.") + "(\\.|$)");
var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join("\\.(?:.*\\.)?") + "(\\.|$)");

handlers = ( jQuery.data(this, "events") || {} )[ event.type ];

Expand Down
4 changes: 4 additions & 0 deletions test/unit/event.js
Expand Up @@ -192,6 +192,10 @@ test("bind(), multi-namespaced events", function() {
jQuery("#firstp").bind("click.test.abc",function(e){
check("click.test.abc", "Namespaced click triggered");
});

// Those would not trigger/unbind (#5303)
jQuery("#firstp").trigger("click.a.test");
jQuery("#firstp").unbind("click.a.test");

// Trigger both bound fn (1)
jQuery("#firstp").trigger("click.test.abc");
Expand Down

0 comments on commit 04dbdb7

Please sign in to comment.