From: Dave Methvin Date: Sun, 27 Jan 2013 04:48:59 +0000 (-0500) Subject: Fix #12656. Make event shorthands excludable. X-Git-Tag: 1.9.1~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=24e76245544537e9f085e09d15d3b08efb171b4c;p=jquery.git Fix #12656. Make event shorthands excludable. --- diff --git a/Gruntfile.js b/Gruntfile.js index 582676503..5d72c24ad 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -45,6 +45,7 @@ module.exports = function( grunt ) { { flag: "css", src: "src/css.js" }, "src/serialize.js", + { flag: "event-alias", src: "src/event-alias.js" }, { flag: "ajax", src: "src/ajax.js" }, { flag: "ajax/script", src: "src/ajax/script.js", needs: ["ajax"] }, { flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] }, diff --git a/src/event-alias.js b/src/event-alias.js new file mode 100644 index 000000000..0a87c5965 --- /dev/null +++ b/src/event-alias.js @@ -0,0 +1,15 @@ +jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + + "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) { + + // Handle event binding + jQuery.fn[ name ] = function( data, fn ) { + return arguments.length > 0 ? + this.on( name, null, data, fn ) : + this.trigger( name ); + }; +}); + +jQuery.fn.hover = function( fnOver, fnOut ) { + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); +}; diff --git a/src/event.js b/src/event.js index ca8719b7f..7b8b77709 100644 --- a/src/event.js +++ b/src/event.js @@ -450,10 +450,18 @@ jQuery.event = { } // Create a writable copy of the event object and normalize some properties - var i, prop, + var i, prop, copy, + type = event.type, originalEvent = event, - fixHook = jQuery.event.fixHooks[ event.type ] || {}, - copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; + fixHook = this.fixHooks[ type ]; + + if ( !fixHook ) { + this.fixHooks[ type ] = fixHook = + rmouseEvent.test( type ) ? this.mouseHooks : + rkeyEvent.test( type ) ? this.keyHooks : + {}; + } + copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; event = new jQuery.Event( originalEvent ); @@ -980,29 +988,5 @@ jQuery.fn.extend({ if ( elem ) { return jQuery.event.trigger( type, data, elem, true ); } - }, - - hover: function( fnOver, fnOut ) { - return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); - } -}); - -jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + - "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + - "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) { - - // Handle event binding - jQuery.fn[ name ] = function( data, fn ) { - return arguments.length > 0 ? - this.on( name, null, data, fn ) : - this.trigger( name ); - }; - - if ( rkeyEvent.test( name ) ) { - jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks; - } - - if ( rmouseEvent.test( name ) ) { - jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks; } }); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 072240049..03c3d62ec 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -316,7 +316,7 @@ test( "attr(String, Object)", function() { equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" ); var $radios = jQuery("#checkedtest").find("input[type='radio']"); - $radios.eq( 1 ).click(); + $radios.eq( 1 ).trigger("click"); equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" ); equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" ); diff --git a/test/unit/core.js b/test/unit/core.js index 373373185..8a91de4cd 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -34,9 +34,8 @@ test("jQuery()", function() { div = jQuery("

"), exec = false, lng = "", - expected = 22, + expected = 21, attrObj = { - "click": function() { ok( exec, "Click executed." ); }, "text": "test", "class": "test2", "id": "test3" @@ -44,6 +43,10 @@ test("jQuery()", function() { // The $(html, props) signature can stealth-call any $.fn method, check for a // few here but beware of modular builds where these methods may be excluded. + if ( jQuery.fn.click ) { + expected++; + attrObj["click"] = function() { ok( exec, "Click executed." ); }; + } if ( jQuery.fn.width ) { expected++; attrObj["width"] = 10; @@ -133,7 +136,7 @@ test("jQuery()", function() { equal( elem[0].id, "test3", "jQuery() quick setter id"); exec = true; - elem.click(); + elem.trigger("click"); // manually clean up detached elements elem.remove(); diff --git a/test/unit/event.js b/test/unit/event.js index bde9f7f43..b252a4654 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -4,12 +4,12 @@ test("null or undefined handler", function() { expect(2); // Supports Fixes bug #7229 try { - jQuery("#firstp").click(null); + jQuery("#firstp").on( "click", null ); ok(true, "Passing a null handler will not throw an exception"); } catch (e) {} try { - jQuery("#firstp").click(undefined); + jQuery("#firstp").on( "click", undefined ); ok(true, "Passing an undefined handler will not throw an exception"); } catch (e) {} }); @@ -66,7 +66,7 @@ test("bind(), with data", function() { ok( event.data, "bind() with data, check passed data exists" ); equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" ); }; - jQuery("#firstp").bind("click", {"foo": "bar"}, handler).click().unbind("click", handler); + jQuery("#firstp").bind("click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler); ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); @@ -74,7 +74,7 @@ test("bind(), with data", function() { var handler2 = function(event) { equal( event.data, test, "bind() with function data, Check value of passed data" ); }; - jQuery("#firstp").bind("click", test, handler2).click().unbind("click", handler2); + jQuery("#firstp").bind("click", test, handler2).trigger("click").unbind("click", handler2); }); test("click(), with data", function() { @@ -83,7 +83,7 @@ test("click(), with data", function() { ok( event.data, "bind() with data, check passed data exists" ); equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" ); }; - jQuery("#firstp").click({"foo": "bar"}, handler).click().unbind("click", handler); + jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler); ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); }); @@ -391,7 +391,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() { $jq[0].click(); // IE } }; - $anchor2.click(function(e) { + $anchor2.on( "click", function(e) { e.preventDefault(); }); $main.delegate("#foo", "click", function(e) { @@ -408,7 +408,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() { fakeClick( $anchor2 ); $anchor2.unbind( "click" ); $main.undelegate( "click" ); - $anchor2.click(function(e) { + $anchor2.on( "click", function(e) { // Let the default action occur }); $main.delegate("#foo", "click", function(e) { @@ -427,7 +427,7 @@ test("bind(), iframes", function() { jQuery("div", doc).bind("click", function() { ok( true, "Binding to element inside iframe" ); - }).click().unbind("click"); + }).trigger("click").unbind("click"); }); test("bind(), trigger change on select", function() { @@ -489,7 +489,7 @@ test("bind(), namespaced events, cloned events", 18, function() { }).trigger("tester"); // Make sure events stick with appendTo'd elements (which are cloned) #2027 - jQuery("test").click(function(){ return false; }).appendTo("#qunit-fixture"); + jQuery("test").on( "click", function(){ return false; }).appendTo("#qunit-fixture"); ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); }); @@ -603,8 +603,8 @@ test("bind(), with different this object", function() { }; jQuery("#firstp") - .bind("click", jQuery.proxy(handler1, thisObject)).click().unbind("click", handler1) - .bind("click", data, jQuery.proxy(handler2, thisObject)).click().unbind("click", handler2); + .bind("click", jQuery.proxy(handler1, thisObject)).trigger("click").unbind("click", handler1) + .bind("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").unbind("click", handler2); ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." ); }); @@ -738,7 +738,7 @@ test("unbind(type)", function() { jQuery( document ) .bind( "click", func ) .unbind( "click", func ) - .click() + .trigger("click") .unbind( "click" ); }); @@ -778,33 +778,35 @@ test("unbind(eventObject)", function() { assert( 0 ); }); -test("hover() mouseenter mouseleave", function() { - expect(1); +if ( jQuery.fn.hover ) { + test("hover() mouseenter mouseleave", function() { + expect(1); - var times = 0, - handler1 = function( event ) { ++times; }, - handler2 = function( event ) { ++times; }; + var times = 0, + handler1 = function( event ) { ++times; }, + handler2 = function( event ) { ++times; }; - jQuery("#firstp") - .hover(handler1, handler2) - .mouseenter().mouseleave() - .unbind("mouseenter", handler1) - .unbind("mouseleave", handler2) - .hover(handler1) - .mouseenter().mouseleave() - .unbind("mouseenter mouseleave", handler1) - .mouseenter().mouseleave(); + jQuery("#firstp") + .hover(handler1, handler2) + .mouseenter().mouseleave() + .unbind("mouseenter", handler1) + .unbind("mouseleave", handler2) + .hover(handler1) + .mouseenter().mouseleave() + .unbind("mouseenter mouseleave", handler1) + .mouseenter().mouseleave(); - equal( times, 4, "hover handlers fired" ); + equal( times, 4, "hover handlers fired" ); -}); + }); +} test("mouseover triggers mouseenter", function() { expect(1); var count = 0, elem = jQuery(""); - elem.mouseenter(function () { + elem.on( "mouseenter", function () { count++; }); elem.trigger("mouseover"); @@ -835,65 +837,71 @@ test("withinElement implemented with jQuery.contains()", function() { test("mouseenter, mouseleave don't catch exceptions", function() { expect(2); - var elem = jQuery("#firstp").hover(function() { throw "an Exception"; }); + var elem = jQuery("#firstp").on( "mouseenter mouseleave", function() { + throw "an Exception"; + }); try { - elem.mouseenter(); + elem.trigger("mouseenter"); } catch (e) { equal( e, "an Exception", "mouseenter doesn't catch exceptions" ); } try { - elem.mouseleave(); + elem.trigger("mouseleave"); } catch (e) { equal( e, "an Exception", "mouseleave doesn't catch exceptions" ); } }); -test("trigger() shortcuts", function() { - expect(6); +if ( jQuery.fn.click ) { - var elem = jQuery("
  • Change location
  • ").prependTo("#firstUL"); - elem.find("a").bind("click", function() { - var close = jQuery("spanx", this); // same with jQuery(this).find("span"); - equal( close.length, 0, "Context element does not exist, length must be zero" ); - ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); - return false; - }).click(); + test("trigger() shortcuts", function() { + expect(6); - // manually clean up detached elements - elem.remove(); + var elem = jQuery("
  • Change location
  • ").prependTo("#firstUL"); + elem.find("a").bind("click", function() { + var close = jQuery("spanx", this); // same with jQuery(this).find("span"); + equal( close.length, 0, "Context element does not exist, length must be zero" ); + ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); + return false; + }).click(); - jQuery("#check1").click(function() { - ok( true, "click event handler for checkbox gets fired twice, see #815" ); - }).click(); + // manually clean up detached elements + elem.remove(); - var counter = 0; - jQuery("#firstp")[0].onclick = function(event) { - counter++; - }; - jQuery("#firstp").click(); - equal( counter, 1, "Check that click, triggers onclick event handler also" ); + jQuery("#check1").click(function() { + ok( true, "click event handler for checkbox gets fired twice, see #815" ); + }).click(); - var clickCounter = 0; - jQuery("#simon1")[0].onclick = function(event) { - clickCounter++; - }; - jQuery("#simon1").click(); - equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); + var counter = 0; + jQuery("#firstp")[0].onclick = function(event) { + counter++; + }; + jQuery("#firstp").click(); + equal( counter, 1, "Check that click, triggers onclick event handler also" ); - elem = jQuery("").load(function(){ - ok( true, "Trigger the load event, using the shortcut .load() (#2819)"); - }).load(); + var clickCounter = 0; + jQuery("#simon1")[0].onclick = function(event) { + clickCounter++; + }; + jQuery("#simon1").click(); + equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); - // manually clean up detached elements - elem.remove(); + elem = jQuery("").load(function(){ + ok( true, "Trigger the load event, using the shortcut .load() (#2819)"); + }).load(); - // test that special handlers do not blow up with VML elements (#7071) - jQuery("").appendTo("head"); - jQuery(" ").appendTo("#form"); - jQuery("#oval").click().keydown(); -}); + // manually clean up detached elements + elem.remove(); + + // test that special handlers do not blow up with VML elements (#7071) + jQuery("").appendTo("head"); + jQuery(" ").appendTo("#form"); + jQuery("#oval").click().keydown(); + }); + +} test("trigger() bubbling", function() { expect(18); @@ -1007,7 +1015,7 @@ test("trigger(type, [data], [fn])", function() { var form = jQuery("
    ").appendTo("body"); // Make sure it can be prevented locally - form.submit(function(){ + form.on( "submit", function(){ ok( true, "Local bind still works." ); return false; }); @@ -1017,7 +1025,7 @@ test("trigger(type, [data], [fn])", function() { form.unbind("submit"); - jQuery(document).submit(function(){ + jQuery(document).on( "submit", function(){ ok( true, "Make sure bubble works up to document." ); return false; }); @@ -1050,7 +1058,7 @@ test( "submit event bubbles on copied forms (#11649)", function() { $fixture.on( "submit", "form", delegatedSubmit ); // Trigger form submission to introduce the _submit_attached property - $testForm.on( "submit", noSubmit ).find("input[name=sub1]").click(); + $testForm.on( "submit", noSubmit ).find("input[name=sub1]").trigger("click"); // Copy the form via .clone() and .html() $formByClone = $testForm.clone( true, true ).removeAttr("id"); @@ -1058,7 +1066,7 @@ test( "submit event bubbles on copied forms (#11649)", function() { $wrapperDiv.append( $formByClone, $formByHTML ); // Check submit bubbling on the copied forms - $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").click(); + $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").trigger("click"); // Clean up $wrapperDiv.remove(); @@ -1083,7 +1091,7 @@ test( "change event bubbles on copied forms (#11796)", function(){ $fixture.on( "change", "form", delegatedChange ); // Trigger change event to introduce the _change_attached property - $form.find("select[name=select1]").val("1").change(); + $form.find("select[name=select1]").val("1").trigger("change"); // Copy the form via .clone() and .html() $formByClone = $form.clone( true, true ).removeAttr("id"); @@ -1091,7 +1099,7 @@ test( "change event bubbles on copied forms (#11796)", function(){ $wrapperDiv.append( $formByClone, $formByHTML ); // Check change bubbling on the copied forms - $wrapperDiv.find("form select[name=select1]").val("2").change(); + $wrapperDiv.find("form select[name=select1]").val("2").trigger("change"); // Clean up $wrapperDiv.remove(); @@ -1203,7 +1211,7 @@ test(".trigger() bubbling on disconnected elements (#10489)", function() { .on( "click", function() { ok( true, "click fired on p" ); }) - .click() + .trigger("click") .off( "click" ) .end() .off( "click" ) @@ -1470,7 +1478,7 @@ test("jQuery.Event.currentTarget", function(){ .on( "click", function( e ){ equal( e.currentTarget, this, "Check currentTarget on event" ); }) - .click() + .trigger("click") .off( "click" ) .end() .off( "click" ); @@ -1666,7 +1674,7 @@ test(".delegate()/.undelegate()", function() { jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(""); }); jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} }); - jQuery("#nothiddendiv span").click(); + jQuery("#nothiddendiv span").trigger("click"); equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." ); equal( livec, 1, "Verify that second handler occurred even with nuked target." ); @@ -1681,7 +1689,7 @@ test(".delegate()/.undelegate()", function() { jQuery("#body").delegate("span#liveSpan1 a", "click", function(){ lived++; return false; }); jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; }); - jQuery("span#liveSpan1 a").click(); + jQuery("span#liveSpan1 a").trigger("click"); equal( lived, 1, "Verify that only one first handler occurred." ); equal( livee, 0, "Verify that second handler doesn't." ); @@ -1691,7 +1699,7 @@ test(".delegate()/.undelegate()", function() { lived = 0; livee = 0; - jQuery("span#liveSpan2 a").click(); + jQuery("span#liveSpan2 a").trigger("click"); equal( lived, 1, "Verify that only one first handler occurred." ); equal( livee, 0, "Verify that second handler doesn't." ); @@ -1706,7 +1714,7 @@ test(".delegate()/.undelegate()", function() { equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" ); }); - jQuery("span#liveSpan1 a").click(); + jQuery("span#liveSpan1 a").trigger("click"); jQuery("#body").undelegate("span#liveSpan1", "click"); @@ -1758,7 +1766,7 @@ test("jQuery.off using dispatched jQuery.Event", function() { equal( ++count, 1, "event called once before removal" ); jQuery().off( event ); }) - .find("a").click().click().end() + .find("a").trigger("click").trigger("click").end() .remove(); }); @@ -1776,7 +1784,7 @@ test( "delegated event with delegateTarget-relative selector", function() { ok( this.id === "a0_0" , "first li under #u10 was clicked" ); }) .end() - .find("a").click().end() + .find("a").trigger("click").end() .find("#ul0").off(); // Non-positional selector (#12383) @@ -1792,7 +1800,7 @@ test( "delegated event with delegateTarget-relative selector", function() { .on( "click", "li.test a", function() { ok( true, "li.test is below the delegation point." ); }) - .find("#a0_0").click(); + .find("#a0_0").trigger("click"); markup.remove(); }); @@ -1834,7 +1842,7 @@ test("stopPropagation() stops directly-bound events on delegated target", functi e.stopPropagation(); ok( true, "delegated handler was called" ); }) - .find("a").click().end() + .find("a").trigger("click").end() .remove(); }); @@ -1970,7 +1978,7 @@ test("delegate with submit", function() { ev.preventDefault(); }); - jQuery("#testForm input[name=sub1]").submit(); + jQuery("#testForm input[name=sub1]").trigger("submit"); equal( count1, 1, "Verify form submit." ); equal( count2, 1, "Verify body submit." ); @@ -2015,24 +2023,24 @@ test("inline handler returning false stops default", function() { expect(1); var markup = jQuery(""); - markup.click(function(e) { + markup.on( "click", function(e) { ok( e.isDefaultPrevented(), "inline handler prevented default"); return false; }); - markup.find("a").click(); + markup.find("a").trigger("click"); markup.off("click"); }); test("window resize", function() { expect(2); - jQuery(window).unbind(); + jQuery(window).off(); - jQuery(window).bind("resize", function(){ + jQuery(window).on( "resize", function(){ ok( true, "Resize event fired." ); - }).resize().unbind("resize"); + }).trigger("resize").off("resize"); - ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." ); + ok( !jQuery._data(window, "events"), "Make sure all the events are gone." ); }); test("focusin bubbles", function() { @@ -2106,7 +2114,7 @@ test(".on and .off", function() { .one( "click", 7, function( e, trig ) { counter += e.data + (trig || 11); // once, 7+11=18 }) - .click() + .trigger("click") .trigger( "click", 17 ) .off( "click" ); equal( counter, 54, "direct event bindings with data" ); @@ -2121,7 +2129,7 @@ test(".on and .off", function() { counter += e.data + (trig || 11); // once, 7+11=18 }) .find("em") - .click() + .trigger("click") .trigger( "click", 17 ) .end() .off( "click", "em" ); @@ -2306,7 +2314,7 @@ test("clone() delegated events (#11076)", function() { .on( "click", "td:last-child", clicked ), clone = table.clone( true ); - clone.find("td").click(); + clone.find("td").trigger("click"); equal( counter["center"], 1, "first child" ); equal( counter["fold"], 1, "last child" ); equal( counter["centerfold"], 2, "all children" ); @@ -2337,7 +2345,7 @@ test("checkbox state (#3827)", function() { // jQuery click cb.checked = true; equal( cb.checked, true, "jQuery - checkbox is initially checked" ); - jQuery( cb ).click(); + jQuery( cb ).trigger("click"); equal( cb.checked, false, "jQuery - checkbox is no longer checked" ); // Handlers only; checkbox state remains false @@ -2348,7 +2356,7 @@ test("focus-blur order (#12868)", function() { expect( 5 ); var $text = jQuery("#text1"), - $radio = jQuery("#radio1").focus(), + $radio = jQuery("#radio1").trigger("focus"), order; // IE6-10 fire focus/blur events asynchronously; this is the resulting mess. @@ -2376,7 +2384,7 @@ test("focus-blur order (#12868)", function() { // Enabled input getting focus order = 0; equal( document.activeElement, $radio[0], "radio has focus" ); - $text.focus(); + $text.trigger("focus"); setTimeout( function() { equal( document.activeElement, $text[0], "text has focus" ); @@ -2612,7 +2620,7 @@ test( "make sure events cloned correctly", 18, function() { ok( true, "Change on original child element is fired" ); }); - fixture.clone().click().change(); // 0 events should be fired + fixture.clone().trigger("click").trigger("change"); // 0 events should be fired clone = fixture.clone( true ); @@ -2628,15 +2636,15 @@ test( "make sure events cloned correctly", 18, function() { p.off(); checkbox.off(); - p.click(); // 0 should be fired - checkbox.change(); // 0 should be fired + p.trigger("click"); // 0 should be fired + checkbox.trigger("change"); // 0 should be fired - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p:first").trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire clone.remove(); - clone.find("p:first").click(); // 0 should be fired - clone.find("#check1").change(); // 0 events should fire + clone.find("p:first").trigger("click"); // 0 should be fired + clone.find("#check1").trigger("change"); // 0 events should fire }); test( "Check order of focusin/focusout events", 2, function() { @@ -2657,10 +2665,10 @@ test( "Check order of focusin/focusout events", 2, function() { }); // gain focus - input.focus(); + input.trigger("focus"); // then lose it - jQuery("#search").focus(); + jQuery("#search").trigger("focus"); // cleanup input.off(); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 3ee260d7e..73313ea97 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -121,7 +121,7 @@ var testWrap = function( val ) { equal( result.text(), defaultText, "Check for element wrapping" ); QUnit.reset(); - jQuery("#check1").click(function() { + jQuery("#check1").on( "click", function() { var checkbox = this; ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); @@ -168,7 +168,7 @@ var testWrap = function( val ) { equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); // Wrap an element with a jQuery set and event - result = jQuery("
    ").click(function() { + result = jQuery("
    ").on( "click", function() { ok( true, "Event triggered." ); // Remove handlers on detached elements @@ -493,7 +493,7 @@ var testAppend = function( valueObj ) { $radioChecked = jQuery("input:radio[name='R1']").eq( 1 ); $radioParent = $radioChecked.parent(); $radioUnchecked = jQuery("").appendTo( $radioParent ); - $radioChecked.click(); + $radioChecked.trigger("click"); $radioUnchecked[ 0 ].checked = false; $radioParent.wrap("
    "); equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" ); @@ -641,7 +641,7 @@ test( "append the same fragment with events (Bug #6997, 5566)", function() { // native event handlers on the original object don't get disturbed when they are // modified on the clone if ( doExtra ) { - element = jQuery("div:first").click(function() { + element = jQuery("div:first").on( "click", function() { ok( true, "Event exists on original after being unbound on clone" ); jQuery( this ).unbind("click"); }); @@ -653,20 +653,20 @@ test( "append the same fragment with events (Bug #6997, 5566)", function() { clone.remove(); } - element = jQuery("").click(function() { + element = jQuery("").on( "click", function() { ok( true, "Append second element events work" ); }); jQuery("#listWithTabIndex li").append( element ) - .find("a.test6997").eq( 1 ).click(); + .find("a.test6997").eq( 1 ).trigger("click"); - element = jQuery("
  • ").click(function() { + element = jQuery("
  • ").on( "click", function() { ok( true, "Before second element events work" ); start(); }); jQuery("#listWithTabIndex li").before( element ); - jQuery("#listWithTabIndex li.test6997").eq( 1 ).click(); + jQuery("#listWithTabIndex li.test6997").eq( 1 ).trigger("click"); }); test( "append HTML5 sectioning elements (Bug #6485)", function() { @@ -808,13 +808,13 @@ test( "appendTo(String|Element|Array|jQuery)", function() { t( "Append select", "#foo select", [ "select1" ] ); QUnit.reset(); - div = jQuery("
    ").click(function() { + div = jQuery("
    ").on( "click", function() { ok( true, "Running a cloned click." ); }); div.appendTo("#qunit-fixture, #moretests"); - jQuery("#qunit-fixture div:last").click(); - jQuery("#moretests div:last").click(); + jQuery("#qunit-fixture div:last").trigger("click"); + jQuery("#moretests div:last").trigger("click"); QUnit.reset(); div = jQuery("
    ").appendTo("#qunit-fixture, #moretests"); @@ -1181,35 +1181,35 @@ var testReplaceWith = function( val ) { deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" ); - tmp = jQuery("
    ").appendTo("#qunit-fixture").click(function() { + tmp = jQuery("
    ").appendTo("#qunit-fixture").on( "click", function() { ok( true, "Newly bound click run." ); }); - y = jQuery("
    ").appendTo("#qunit-fixture").click(function() { + y = jQuery("
    ").appendTo("#qunit-fixture").on( "click", function() { ok( false, "Previously bound click run." ); }); - child = y.append("test").find("b").click(function() { + child = y.append("test").find("b").on( "click", function() { ok( true, "Child bound click run." ); return false; }); y.replaceWith( val(tmp) ); - tmp.click(); - y.click(); // Shouldn't be run - child.click(); // Shouldn't be run + tmp.trigger("click"); + y.trigger("click"); // Shouldn't be run + child.trigger("click"); // Shouldn't be run - y = jQuery("
    ").appendTo("#qunit-fixture").click(function() { + y = jQuery("
    ").appendTo("#qunit-fixture").on( "click", function() { ok( false, "Previously bound click run." ); }); - child2 = y.append("test").find("u").click(function() { + child2 = y.append("test").find("u").on( "click", function() { ok( true, "Child 2 bound click run." ); return false; }); y.replaceWith( val(child2) ); - child2.click(); + child2.trigger("click"); set = jQuery("
    ").replaceWith( val("test") ); @@ -1329,7 +1329,7 @@ test( "clone()", function() { equal( jQuery("#nonnodes").contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); // Verify that clones of clones can keep event listeners - div = jQuery("
    • test
    ").click(function() { + div = jQuery("
    • test
    ").on( "click", function() { ok( true, "Bound event still exists." ); }); clone = div.clone( true ); div.remove(); @@ -1344,7 +1344,7 @@ test( "clone()", function() { // Verify that cloned children can keep event listeners div = jQuery("
    ").append([ document.createElement("table"), document.createElement("table") ]); - div.find("table").click(function() { + div.find("table").on( "click", function() { ok( true, "Bound event still exists." ); }); @@ -1358,7 +1358,7 @@ test( "clone()", function() { clone.remove(); // Make sure that doing .clone() doesn't clone event listeners - div = jQuery("
    • test
    ").click(function() { + div = jQuery("
    • test
    ").on( "click", function() { ok( false, "Bound event still exists after .clone()." ); }); clone = div.clone(); @@ -1776,9 +1776,9 @@ test( "remove() event cleaning ", 1, function() { count = 0; first = jQuery("#ap").children(":first"); - cleanUp = first.click(function() { + cleanUp = first.on( "click", function() { count++; - }).remove().appendTo("#qunit-fixture").click(); + }).remove().appendTo("#qunit-fixture").trigger("click"); strictEqual( 0, count, "Event handler has been removed" ); @@ -1795,9 +1795,9 @@ test( "detach() event cleaning ", 1, function() { count = 0; first = jQuery("#ap").children(":first"); - cleanUp = first.click(function() { + cleanUp = first.on( "click", function() { count++; - }).detach().appendTo("#qunit-fixture").click(); + }).detach().appendTo("#qunit-fixture").trigger("click"); strictEqual( 1, count, "Event handler has not been removed" ); @@ -1880,13 +1880,13 @@ test( "jQuery.cleanData", function() { div.remove(); function getDiv() { - var div = jQuery("
    ").click(function() { + var div = jQuery("
    ").on( "click", function() { ok( true, type + " " + pos + " Click event fired." ); - }).focus(function() { + }).on( "focus", function() { ok( true, type + " " + pos + " Focus event fired." ); - }).find("div").click(function() { + }).find("div").on( "click", function() { ok( false, type + " " + pos + " Click event fired." ); - }).focus(function() { + }).on( "focus", function() { ok( false, type + " " + pos + " Focus event fired." ); }).end().appendTo("body");