X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=824707fee91cdd28f8b37e9d49431dc56fb91ea5;hb=7a3afc31943865b3536a1596d431278b99ff824d;hp=99ed419363db1ef58577075a5129b0fb51a9a10a;hpb=3e286440d55749382a644ea97b4f0b2587779d65;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index 99ed419..824707f 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -37,6 +37,81 @@ test("bind(), multiple events at once", function() { equals( mouseoverCounter, 1, "bind() with multiple events at once" ); }); +test("bind(), multiple events at once and namespaces", function() { + expect(7); + + var cur, obj = {}; + + var div = jQuery("
").bind("focusin.a", function(e) { + equals( e.type, cur, "Verify right single event was fired." ); + }); + + cur = "focusin"; + div.trigger("focusin.a"); + + div = jQuery("
").bind("click mouseover", obj, function(e) { + equals( e.type, cur, "Verify right multi event was fired." ); + equals( e.data, obj, "Make sure the data came in correctly." ); + }); + + cur = "click"; + div.trigger("click"); + + cur = "mouseover"; + div.trigger("mouseover"); + + div = jQuery("
").bind("focusin.a focusout.b", function(e) { + equals( e.type, cur, "Verify right multi event was fired." ); + }); + + cur = "focusin"; + div.trigger("focusin.a"); + + cur = "focusout"; + div.trigger("focusout.b"); +}); + +test("bind(), namespace with special add", function() { + expect(9); + + var div = jQuery("
").bind("test", function(e) { + ok( true, "Test event fired." ); + }); + + var i = 0; + + jQuery.event.special.test = { + setup: function(){}, + teardown: function(){}, + add: function( handler, data, namespaces ) { + return function(e) { + e.xyz = ++i; + handler.apply( this, arguments ); + }; + }, + remove: function() {} + }; + + div.bind("test.a", {x: 1}, function(e) { + ok( !!e.xyz, "Make sure that the data is getting passed through." ); + equals( e.data.x, 1, "Make sure data is attached properly." ); + }); + + div.bind("test.b", {x: 2}, function(e) { + ok( !!e.xyz, "Make sure that the data is getting passed through." ); + equals( e.data.x, 2, "Make sure data is attached properly." ); + }); + + // Should trigger 5 + div.trigger("test"); + + // Should trigger 2 + div.trigger("test.a"); + + // Should trigger 2 + div.trigger("test.b"); +}); + test("bind(), no data", function() { expect(1); var handler = function(event) { @@ -394,7 +469,7 @@ test("trigger() bubbling", function() { }); test("trigger(type, [data], [fn])", function() { - expect(12); + expect(14); var handler = function(event, a, b, c) { equals( event.type, "click", "check passed data" ); @@ -439,6 +514,34 @@ test("trigger(type, [data], [fn])", function() { pass = false; } ok( pass, "Trigger on a table with a colon in the even type, see #3533" ); + + var form = jQuery("
").appendTo("body"); + + // Make sure it can be prevented locally + form.submit(function(){ + ok( true, "Local bind still works." ); + return false; + }); + + // Trigger 1 + form.trigger("submit"); + + form.unbind("submit"); + + jQuery(document).submit(function(){ + ok( true, "Make sure bubble works up to document." ); + return false; + }); + + // Trigger 1 + form.trigger("submit"); + + jQuery(document).unbind("submit"); + + form.remove(); +}); + +test("jQuery.Event.currentTarget", function(){ }); test("trigger(eventObject, [data], [fn])", function() {