X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=1da9b5906fab6429850851e7068941ef51e1e483;hb=9aa0c69c43bad9fce5ef7732692308afb2a38ec6;hp=cbeb9ff0011c9f59650c4b1c653b4a14bb9094db;hpb=d12e8a34e6d96f98ac4f9408a0d61a9ed373f917;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index cbeb9ff..1da9b59 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -474,7 +474,7 @@ test("toggle(Function, Function, ...)", function() { }); test(".live()/.die()", function() { - expect(34); + expect(46); var submit = 0, div = 0, livea = 0, liveb = 0; @@ -533,6 +533,15 @@ test(".live()/.die()", function() { equals( livea, 5, "die Click on inner div" ); equals( liveb, 2, "die Click on inner div" ); + // Make sure that stopPropgation doesn't stop live events + jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); }); + jQuery("div#nothiddendivchild").trigger("click"); + equals( submit, 1, "stopPropagation Click on inner div" ); + equals( div, 6, "stopPropagation Click on inner div" ); + equals( livea, 6, "stopPropagation Click on inner div" ); + equals( liveb, 3, "stopPropagation Click on inner div" ); + + jQuery("div#nothiddendivchild").die("click"); jQuery("div#nothiddendiv").die("click"); jQuery("div").die("click"); jQuery("div").die("submit"); @@ -571,10 +580,60 @@ test(".live()/.die()", function() { equals( called, 3, "Verify that only one click occurred." ); jQuery("#anchor2").trigger("click"); - equals( called, 3, "Verify that only one click occurred." ); + equals( called, 3, "Verify that no click occurred." ); + + // Make sure that it still works if the selector is the same, + // but the event type is different + jQuery("#nothiddendiv").live("foo", callback); // Cleanup jQuery("#nothiddendiv").die("click", callback); + + jQuery("#nothiddendiv").trigger("click"); + equals( called, 3, "Verify that no click occurred." ); + + jQuery("#nothiddendiv").trigger("foo"); + equals( called, 4, "Verify that one foo occurred." ); + + // Cleanup + jQuery("#nothiddendiv").die("foo", callback); + + // Make sure we don't loose the target by DOM modifications + // after the bubble already reached the liveHandler + var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('').get(0); + + jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); }); + jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} }); + + jQuery("#nothiddendiv span").click(); + equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." ); + equals( livec, 1, "Verify that second handler occurred even with nuked target." ); + + // Cleanup + jQuery("#nothiddendivchild").die("click"); + + // Verify that .live() ocurs and cancel buble in the same order as + // we would expect .bind() and .click() without delegation + var lived = 0, livee = 0; + + // bind one pair in one order + jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; }); + jQuery('span#liveSpan1').live('click', function(){ livee++; }); + + jQuery('span#liveSpan1 a').click(); + equals( lived, 1, "Verify that only one first handler occurred." ); + equals( livee, 0, "Verify that second handler don't." ); + + // and one pair in inverse + jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; }); + jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; }); + + jQuery('span#liveSpan2 a').click(); + equals( lived, 2, "Verify that only one first handler occurred." ); + equals( livee, 0, "Verify that second handler don't." ); + + // Cleanup + jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click"); }); /*