Fixed problems with removing live events. Fixes #4894.

This commit is contained in:
John Resig 2009-12-09 14:43:53 -08:00
parent 86bbf9cf87
commit 1052792bb2
2 changed files with 39 additions and 4 deletions

View file

@ -872,9 +872,7 @@ function liveHandler( event ) {
} }
function liveConvert( type, selector ) { function liveConvert( type, selector ) {
return ["live", type, selector//.replace(/[^\w\s\.]/g, function(ch){ return "\\"+ch}) return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "&")].join(".");
.replace(/\./g, "`")
.replace(/ /g, "|")].join(".");
} }
jQuery.each( ("blur focus load resize scroll unload click dblclick " + jQuery.each( ("blur focus load resize scroll unload click dblclick " +

View file

@ -608,7 +608,7 @@ test("toggle(Function, Function, ...)", function() {
}); });
test(".live()/.die()", function() { test(".live()/.die()", function() {
expect(58); expect(61);
var submit = 0, div = 0, livea = 0, liveb = 0; 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 a').click();
jQuery('span#liveSpan1').die('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(){ test("live with change", function(){