X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=test%2Funit%2Fevent.js;h=840c98a5c3e39bff55a9ceddf6526d32661d1bba;hb=0a1b0db347119a2e45d3d31285223ead27b64506;hp=e12f3b753c9e8be5cec65e5b2abfd861b1a0c51a;hpb=ec7baf230d3c246dadf00c94115e6668425b9354;p=jquery.git
diff --git a/test/unit/event.js b/test/unit/event.js
index e12f3b7..840c98a 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -417,6 +417,20 @@ test("trigger(eventObject, [data], [fn])", function() {
$parent.unbind().remove();
});
+test("jQuery.Event.currentTarget", function(){
+ expect(2);
+
+ var counter = 0,
+ $elem = jQuery('').click(function(e){
+ equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
+ });
+
+ // Fake event
+ $elem.trigger('click');
+ // Native event (#4033)
+ triggerEvent( $elem[0], 'click' );
+});
+
test("toggle(Function, Function, ...)", function() {
expect(11);
@@ -474,7 +488,7 @@ test("toggle(Function, Function, ...)", function() {
});
test(".live()/.die()", function() {
- expect(36);
+ expect(46);
var submit = 0, div = 0, livea = 0, liveb = 0;
@@ -533,6 +547,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");
@@ -588,6 +611,43 @@ test(".live()/.die()", function() {
// 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");
});
/*