X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=99ed419363db1ef58577075a5129b0fb51a9a10a;hb=3e286440d55749382a644ea97b4f0b2587779d65;hp=70c721f823d0160631dd329b66d9d535b2bf35ee;hpb=5dc6b7ce3469eaadb37a151d449e8d36571d1894;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index 70c721f..99ed419 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -232,8 +232,8 @@ test("bind(), with different this object", function() { }; jQuery("#firstp") - .bind("click", handler1, thisObject).click().unbind("click", handler1) - .bind("click", data, handler2, thisObject).click().unbind("click", handler2); + .bind("click", jQuery.proxy(handler1, thisObject)).click().unbind("click", handler1) + .bind("click", data, jQuery.proxy(handler2, thisObject)).click().unbind("click", handler2); ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." ); }); @@ -608,7 +608,7 @@ test("toggle(Function, Function, ...)", function() { }); test(".live()/.die()", function() { - expect(61); + expect(62); var submit = 0, div = 0, livea = 0, liveb = 0; @@ -675,6 +675,13 @@ test(".live()/.die()", function() { equals( livea, 6, "stopPropagation Click on inner div" ); equals( liveb, 3, "stopPropagation Click on inner div" ); + // Make sure click events only fire with primary click + var event = jQuery.Event("click"); + event.button = 1; + jQuery("div#nothiddendiv").trigger(event); + + equals( livea, 6, "live secondary click" ); + jQuery("div#nothiddendivchild").die("click"); jQuery("div#nothiddendiv").die("click"); jQuery("div").die("click"); @@ -706,15 +713,15 @@ test(".live()/.die()", function() { jQuery("#foo").trigger("click", true).die("click"); // Test binding with different this object - jQuery("#foo").live("click", function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" }); + jQuery("#foo").live("click", jQuery.proxy(function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" })); jQuery("#foo").trigger("click").die("click"); // Test binding with different this object, event data, and trigger data - jQuery("#foo").live("click", true, function(e, data){ + jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){ equals( e.data, true, "live with with different this object, event data, and trigger data" ); equals( this.foo, "bar", "live with with different this object, event data, and trigger data" ); equals( data, true, "live with with different this object, event data, and trigger data") - }, { foo: "bar" }); + }, { foo: "bar" })); jQuery("#foo").trigger("click", true).die("click"); // Verify that return false prevents default action @@ -857,6 +864,35 @@ test(".live()/.die()", function() { jQuery("#nothiddendiv div").die("click"); }); +test("die all bound events", function(){ + expect(1); + + var count = 0; + var div = jQuery("div#nothiddendivchild"); + + div.live("click submit", function(){ count++; }); + div.die(); + + div.trigger("click"); + div.trigger("submit"); + + equals( count, 0, "Make sure no events were triggered." ); +}); + +test("live with multiple events", function(){ + expect(1); + + var count = 0; + var div = jQuery("div#nothiddendivchild"); + + div.live("click submit", function(){ count++; }); + + div.trigger("click"); + div.trigger("submit"); + + equals( count, 2, "Make sure both the click and submit were triggered." ); +}); + test("live with change", function(){ var selectChange = 0, checkboxChange = 0;