module("event", { teardown: moduleTeardown }); test("null or undefined handler", function() { expect(2); // Supports Fixes bug #7229 try { jQuery("#firstp").on( "click", null ); ok(true, "Passing a null handler will not throw an exception"); } catch ( e ) {} try { jQuery("#firstp").on( "click", undefined ); ok(true, "Passing an undefined handler will not throw an exception"); } catch ( e ) {} }); test("on() with non-null,defined data", function() { expect(2); var handler = function( event, data ) { equal( data, 0, "non-null, defined data (zero) is correctly passed" ); }; jQuery("#foo").on("foo.on", handler); jQuery("div").on("foo.delegate", "#foo", handler); jQuery("#foo").trigger("foo", 0); jQuery("#foo").off("foo.on", handler); jQuery("div").off("foo.delegate", "#foo"); }); test("Handler changes and .trigger() order", function() { expect(1); var markup = jQuery( "
b
foo
").appendTo( $parent ); $parent.get( 0 ).style.display = "none"; 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.on("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.off(); function error(){ ok( false, "This assertion shouldn't be reached"); } $parent.on("foo", error ); $child.on("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.on("foo", error ); event = new jQuery.Event("foo"); $child.trigger( event, [1,2,3] ).off(); equal( event.result, "result", "Check event.result attribute"); // Will error if it bubbles $child.triggerHandler("foo"); $child.off(); $parent.off().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