X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=2b4d8e59c693bc091f9c3ce1286644eeca8f3938;hb=5cb1163469fb2c9cd80712cd5481b29055821022;hp=16cfb6ce9530b6c99f114bfb7575ff44bf9818e4;hpb=8356871a5522ad59cac80af2ca4695079059b97e;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index 16cfb6c..2b4d8e5 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -45,6 +45,59 @@ test("bind(), no data", function() { jQuery("#firstp").bind("click", handler).trigger("click"); }); +test("bind/one/unbind(Object)", function(){ + expect(6); + + var clickCounter = 0, mouseoverCounter = 0; + function handler(event) { + if (event.type == "click") + clickCounter++; + else if (event.type == "mouseover") + mouseoverCounter++; + }; + + function handlerWithData(event) { + if (event.type == "click") + clickCounter += event.data; + else if (event.type == "mouseover") + mouseoverCounter += event.data; + }; + + function trigger(){ + $elem.trigger("click").trigger("mouseover"); + } + + var $elem = jQuery("#firstp") + // Regular bind + .bind({ + click:handler, + mouseover:handler + }) + // Bind with data + .one({ + click:handlerWithData, + mouseover:handlerWithData + }, 2 ); + + trigger(); + + equals( clickCounter, 3, "bind(Object)" ); + equals( mouseoverCounter, 3, "bind(Object)" ); + + trigger(); + equals( clickCounter, 4, "bind(Object)" ); + equals( mouseoverCounter, 4, "bind(Object)" ); + + jQuery("#firstp").unbind({ + click:handler, + mouseover:handler + }); + + trigger(); + equals( clickCounter, 4, "bind(Object)" ); + equals( mouseoverCounter, 4, "bind(Object)" ); +}); + test("bind(), iframes", function() { // events don't work with iframes, see #939 - this test fails in IE because of contentDocument var doc = jQuery("#loadediframe").contents(); @@ -479,7 +532,7 @@ test("jQuery.Event.currentTarget", function(){ }); test("toggle(Function, Function, ...)", function() { - expect(11); + expect(16); var count = 0, fn1 = function(e) { count++; }, @@ -532,6 +585,22 @@ test("toggle(Function, Function, ...)", function() { $div.unbind('click',fns[0]); var data = jQuery.data( $div[0], 'events' ); ok( !data, "Unbinding one function from toggle unbinds them all"); + + // Test Multi-Toggles + var a = [], b = []; + $div = jQuery("
"); + $div.toggle(function(){ a.push(1); }, function(){ a.push(2); }); + $div.click(); + same( a, [1], "Check that a click worked." ); + + $div.toggle(function(){ b.push(1); }, function(){ b.push(2); }); + $div.click(); + same( a, [1,2], "Check that a click worked with a second toggle." ); + same( b, [1], "Check that a click worked with a second toggle." ); + + $div.click(); + same( a, [1,2,1], "Check that a click worked with a second toggle, second click." ); + same( b, [1,2], "Check that a click worked with a second toggle, second click." ); }); test(".live()/.die()", function() { @@ -745,6 +814,22 @@ test(".live()/.die()", function() { jQuery('span#liveSpan1').die('click'); }); +test("live with submit", function() { + var count = 0; + + jQuery("#testForm").live("submit", function() { + count++; + return false; + }); + + jQuery("#testForm input[name=sub1]")[0].click(); + jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13}); + + equals(2, count); + + jQuery("#testForm").die("submit"); +}); + test("live with focus/blur", function(){ expect(2);