aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-12-09 14:43:53 -0800
committerJohn Resig <jeresig@gmail.com>2009-12-09 14:43:53 -0800
commit1052792bb23b56d25dcbacd3816c8b5a08bc9b72 (patch)
tree131224d9b8d49916e0f8e71fd6a22ecb5b841a4d
parent86bbf9cf87784cdd81ca79e4d809ef6f5879ef8b (diff)
downloadjquery-1052792bb23b56d25dcbacd3816c8b5a08bc9b72.tar.gz
jquery-1052792bb23b56d25dcbacd3816c8b5a08bc9b72.zip
Fixed problems with removing live events. Fixes #4894.
-rw-r--r--src/event.js4
-rw-r--r--test/unit/event.js39
2 files changed, 39 insertions, 4 deletions
diff --git a/src/event.js b/src/event.js
index ac45e7e16..e070cb261 100644
--- a/src/event.js
+++ b/src/event.js
@@ -872,9 +872,7 @@ function liveHandler( event ) {
}
function liveConvert( type, selector ) {
- return ["live", type, selector//.replace(/[^\w\s\.]/g, function(ch){ return "\\"+ch})
- .replace(/\./g, "`")
- .replace(/ /g, "|")].join(".");
+ return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "&")].join(".");
}
jQuery.each( ("blur focus load resize scroll unload click dblclick " +
diff --git a/test/unit/event.js b/test/unit/event.js
index 1ad7c3d0c..80a2e6a0b 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -608,7 +608,7 @@ test("toggle(Function, Function, ...)", function() {
});
test(".live()/.die()", function() {
- expect(58);
+ expect(61);
var submit = 0, div = 0, livea = 0, liveb = 0;
@@ -818,6 +818,43 @@ test(".live()/.die()", function() {
jQuery('span#liveSpan1 a').click();
jQuery('span#liveSpan1').die('click');
+
+ // Work with deep selectors
+ livee = 0;
+
+ function clickB(){ livee++; }
+
+ jQuery("#nothiddendiv div").live("click", function(){ livee++; });
+ jQuery("#nothiddendiv div").live("click", clickB);
+ jQuery("#nothiddendiv div").live("mouseover", function(){ livee++; });
+
+ equals( livee, 0, "No clicks, deep selector." );
+
+ livee = 0;
+ jQuery("#nothiddendivchild").trigger("click");
+ equals( livee, 2, "Click, deep selector." );
+
+ livee = 0;
+ jQuery("#nothiddendivchild").trigger("mouseover");
+ equals( livee, 1, "Mouseover, deep selector." );
+
+ jQuery("#nothiddendiv div").die("mouseover");
+
+ livee = 0;
+ jQuery("#nothiddendivchild").trigger("click");
+ equals( livee, 2, "Click, deep selector." );
+
+ livee = 0;
+ jQuery("#nothiddendivchild").trigger("mouseover");
+ equals( livee, 0, "Mouseover, deep selector." );
+
+ jQuery("#nothiddendiv div").die("click", clickB);
+
+ livee = 0;
+ jQuery("#nothiddendivchild").trigger("click");
+ equals( livee, 1, "Click, deep selector." );
+
+ jQuery("#nothiddendiv div").die("click");
});
test("live with change", function(){