module("event", { teardown: moduleTeardown }); test("null or undefined handler", function() { expect(2); // Supports Fixes bug #7229 try { jQuery("#firstp").click(null); ok(true, "Passing a null handler will not throw an exception"); } catch (e) {} try { jQuery("#firstp").click(undefined); ok(true, "Passing an undefined handler will not throw an exception"); } catch (e) {} }); test("bind(),live(),delegate() with non-null,defined data", function() { expect(3); var handler = function( event, data ) { equal( data, 0, "non-null, defined data (zero) is correctly passed" ); }; jQuery("#foo").bind("foo", handler); jQuery("#foo").live("foo", handler); jQuery("div").delegate("#foo", "foo", handler); jQuery("#foo").trigger("foo", 0); jQuery("#foo").unbind("foo", handler); jQuery("#foo").die("foo", handler); jQuery("div").undelegate("#foo", "foo"); }); test("Handler changes and .trigger() order", function() { expect(1); var markup = jQuery( "
b
foo
").appendTo( $parent ); $parent.get( 0 ).style.display = "none"; var event = jQuery.Event("noNew"); ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" ); equal( event.type, "noNew", "Verify its type" ); equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" ); equal( event.isPropagationStopped(), false, "Verify isPropagationStopped" ); equal( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" ); event.preventDefault(); equal( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" ); event.stopPropagation(); equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); event.isPropagationStopped = function(){ return false; }; event.stopImmediatePropagation(); equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" ); $parent.bind("foo",function(e){ // Tries bubbling equal( e.type, "foo", "Verify event type when passed passing an event object" ); equal( e.target.id, "child", "Verify event.target when passed passing an event object" ); equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" ); equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" ); }); // test with an event object event = new jQuery.Event("foo"); event.secret = "boo!"; $child.trigger(event); // test with a literal object $child.trigger({"type": "foo", "secret": "boo!"}); $parent.unbind(); function error(){ ok( false, "This assertion shouldn't be reached"); } $parent.bind("foo", error ); $child.bind("foo",function(e, a, b, c ){ equal( arguments.length, 4, "Check arguments length"); equal( a, 1, "Check first custom argument"); equal( b, 2, "Check second custom argument"); equal( c, 3, "Check third custom argument"); equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" ); equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" ); equal( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" ); // Skips both errors e.stopImmediatePropagation(); return "result"; }); // We should add this back in when we want to test the order // in which event handlers are iterated. //$child.bind("foo", error ); event = new jQuery.Event("foo"); $child.trigger( event, [1,2,3] ).unbind(); equal( event.result, "result", "Check event.result attribute"); // Will error if it bubbles $child.triggerHandler("foo"); $child.unbind(); $parent.unbind().remove(); // Ensure triggerHandler doesn't molest its event object (#xxx) event = jQuery.Event( "zowie" ); jQuery( document ).triggerHandler( event ); equal( event.type, "zowie", "Verify its type" ); equal( event.isPropagationStopped(), false, "propagation not stopped" ); equal( event.isDefaultPrevented(), false, "default not prevented" ); }); // Explicitly introduce global variable for oldIE so QUnit doesn't complain if checking globals window.onclick = undefined; test(".trigger() bubbling on disconnected elements (#10489)", function() { expect(2); jQuery( window ).on( "click", function(){ ok( false, "click fired on window" ); }); jQuery( "hi
trigger |
onandoff
Gut Feeling
" ) .on( "click", jQuery.noop ) .on( "gutfeeling", jQuery.noop ) .off( "click" ) .trigger( "gutfeeling" ) .remove(); // Ensure special events are removed when only a namespace is provided jQuery( "Gut Feeling
" ) .on( "gutfeeling.Devo", jQuery.noop ) .off( ".Devo" ) .trigger( "gutfeeling" ) .remove(); // Ensure .one() events are removed after their maiden voyage jQuery( "Gut Feeling
" ) .one( "gutfeeling", jQuery.noop ) .trigger( "gutfeeling" ) // This one should .trigger( "gutfeeling" ) // This one should not .remove(); delete jQuery.event.special["gutfeeling"]; }); test(".on and .off, selective mixed removal (#10705)", function() { expect(7); var clockout = 0, timingx = function( e ) { ok( true, "triggered " + e.type ); }; jQuery( "Strange Pursuit
" ) .on( "click", timingx ) .on( "click.duty", timingx ) .on( "click.now", timingx ) .on( "devo", timingx ) .on( "future", timingx ) .trigger( "click" ) // 3 .trigger( "devo" ) // 1 .off( ".duty devo " ) // trailing space .trigger( "future" ) // 1 .trigger( "click" ) // 2 .off( "future click" ) .trigger( "click" ); // 0 }); test(".on( event-map, null-selector, data ) #11130", function() { expect( 1 ); var $p = jQuery("Strange Pursuit
"), data = "bar", map = { "foo": function( event ) { equal( event.data, "bar", "event.data correctly relayed with null selector" ); $p.remove(); } }; $p.on( map, null, data ).trigger("foo"); }); test("clone() delegated events (#11076)", function() { expect(3); var counter = { "center": 0, "fold": 0, "centerfold": 0 }, clicked = function( event ) { counter[ jQuery(this).text().replace(/\s+/, "") ]++; }, table = jQuery( "center | fold |