Commit 6f7b6915 authored by Dave Methvin's avatar Dave Methvin

Fix #12656. Make event shorthands excludable.

parent a6c358d0
...@@ -45,6 +45,7 @@ module.exports = function( grunt ) { ...@@ -45,6 +45,7 @@ module.exports = function( grunt ) {
{ flag: "css", src: "src/css.js" }, { flag: "css", src: "src/css.js" },
"src/serialize.js", "src/serialize.js",
{ flag: "event-alias", src: "src/event-alias.js" },
{ flag: "ajax", src: "src/ajax.js" }, { flag: "ajax", src: "src/ajax.js" },
{ flag: "ajax/script", src: "src/ajax/script.js", needs: ["ajax"] }, { flag: "ajax/script", src: "src/ajax/script.js", needs: ["ajax"] },
{ flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] }, { flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] },
......
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 );
};
...@@ -481,10 +481,18 @@ jQuery.event = { ...@@ -481,10 +481,18 @@ jQuery.event = {
} }
// Create a writable copy of the event object and normalize some properties // Create a writable copy of the event object and normalize some properties
var i, prop, var i, prop, copy,
type = event.type,
originalEvent = event, originalEvent = event,
fixHook = jQuery.event.fixHooks[ event.type ] || {}, fixHook = this.fixHooks[ type ];
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
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 ); event = new jQuery.Event( originalEvent );
...@@ -810,29 +818,5 @@ jQuery.fn.extend({ ...@@ -810,29 +818,5 @@ jQuery.fn.extend({
if ( elem ) { if ( elem ) {
return jQuery.event.trigger( type, data, elem, true ); 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;
} }
}); });
...@@ -312,7 +312,7 @@ test( "attr(String, Object)", function() { ...@@ -312,7 +312,7 @@ test( "attr(String, Object)", function() {
equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" ); equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" );
var $radios = jQuery("#checkedtest").find("input[type='radio']"); 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( 1 ).prop("checked"), true, "Second radio was checked when clicked" );
equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" ); equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" );
......
...@@ -34,9 +34,8 @@ test("jQuery()", function() { ...@@ -34,9 +34,8 @@ test("jQuery()", function() {
div = jQuery("<div/><hr/><code/><b/>"), div = jQuery("<div/><hr/><code/><b/>"),
exec = false, exec = false,
lng = "", lng = "",
expected = 22, expected = 21,
attrObj = { attrObj = {
"click": function() { ok( exec, "Click executed." ); },
"text": "test", "text": "test",
"class": "test2", "class": "test2",
"id": "test3" "id": "test3"
...@@ -44,6 +43,10 @@ test("jQuery()", function() { ...@@ -44,6 +43,10 @@ test("jQuery()", function() {
// The $(html, props) signature can stealth-call any $.fn method, check for a // 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. // 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 ) { if ( jQuery.fn.width ) {
expected++; expected++;
attrObj["width"] = 10; attrObj["width"] = 10;
...@@ -133,7 +136,7 @@ test("jQuery()", function() { ...@@ -133,7 +136,7 @@ test("jQuery()", function() {
equal( elem[0].id, "test3", "jQuery() quick setter id"); equal( elem[0].id, "test3", "jQuery() quick setter id");
exec = true; exec = true;
elem.click(); elem.trigger("click");
// manually clean up detached elements // manually clean up detached elements
elem.remove(); elem.remove();
......
This diff is collapsed.
...@@ -121,7 +121,7 @@ var testWrap = function( val ) { ...@@ -121,7 +121,7 @@ var testWrap = function( val ) {
equal( result.text(), defaultText, "Check for element wrapping" ); equal( result.text(), defaultText, "Check for element wrapping" );
QUnit.reset(); QUnit.reset();
jQuery("#check1").click(function() { jQuery("#check1").on( "click", function() {
var checkbox = this; var checkbox = this;
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
...@@ -168,7 +168,7 @@ var testWrap = function( val ) { ...@@ -168,7 +168,7 @@ var testWrap = function( val ) {
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
// Wrap an element with a jQuery set and event // Wrap an element with a jQuery set and event
result = jQuery("<div></div>").click(function() { result = jQuery("<div></div>").on( "click", function() {
ok( true, "Event triggered." ); ok( true, "Event triggered." );
// Remove handlers on detached elements // Remove handlers on detached elements
...@@ -493,7 +493,7 @@ var testAppend = function( valueObj ) { ...@@ -493,7 +493,7 @@ var testAppend = function( valueObj ) {
$radioChecked = jQuery("input:radio[name='R1']").eq( 1 ); $radioChecked = jQuery("input:radio[name='R1']").eq( 1 );
$radioParent = $radioChecked.parent(); $radioParent = $radioChecked.parent();
$radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent ); $radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
$radioChecked.click(); $radioChecked.trigger("click");
$radioUnchecked[ 0 ].checked = false; $radioUnchecked[ 0 ].checked = false;
$radioParent.wrap("<div></div>"); $radioParent.wrap("<div></div>");
equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" ); equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" );
...@@ -766,13 +766,13 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() { ...@@ -766,13 +766,13 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
t( "Append select", "#foo select", [ "select1" ] ); t( "Append select", "#foo select", [ "select1" ] );
QUnit.reset(); QUnit.reset();
div = jQuery("<div/>").click(function() { div = jQuery("<div/>").on( "click", function() {
ok( true, "Running a cloned click." ); ok( true, "Running a cloned click." );
}); });
div.appendTo("#qunit-fixture, #moretests"); div.appendTo("#qunit-fixture, #moretests");
jQuery("#qunit-fixture div:last").click(); jQuery("#qunit-fixture div:last").trigger("click");
jQuery("#moretests div:last").click(); jQuery("#moretests div:last").trigger("click");
QUnit.reset(); QUnit.reset();
div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests"); div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
...@@ -1139,35 +1139,35 @@ var testReplaceWith = function( val ) { ...@@ -1139,35 +1139,35 @@ var testReplaceWith = function( val ) {
deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" ); deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" );
tmp = jQuery("<div/>").appendTo("#qunit-fixture").click(function() { tmp = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
ok( true, "Newly bound click run." ); ok( true, "Newly bound click run." );
}); });
y = jQuery("<div/>").appendTo("#qunit-fixture").click(function() { y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
ok( false, "Previously bound click run." ); ok( false, "Previously bound click run." );
}); });
child = y.append("<b>test</b>").find("b").click(function() { child = y.append("<b>test</b>").find("b").on( "click", function() {
ok( true, "Child bound click run." ); ok( true, "Child bound click run." );
return false; return false;
}); });
y.replaceWith( val(tmp) ); y.replaceWith( val(tmp) );
tmp.click(); tmp.trigger("click");
y.click(); // Shouldn't be run y.trigger("click"); // Shouldn't be run
child.click(); // Shouldn't be run child.trigger("click"); // Shouldn't be run
y = jQuery("<div/>").appendTo("#qunit-fixture").click(function() { y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
ok( false, "Previously bound click run." ); ok( false, "Previously bound click run." );
}); });
child2 = y.append("<u>test</u>").find("u").click(function() { child2 = y.append("<u>test</u>").find("u").on( "click", function() {
ok( true, "Child 2 bound click run." ); ok( true, "Child 2 bound click run." );
return false; return false;
}); });
y.replaceWith( val(child2) ); y.replaceWith( val(child2) );
child2.click(); child2.trigger("click");
set = jQuery("<div/>").replaceWith( val("<span>test</span>") ); set = jQuery("<div/>").replaceWith( val("<span>test</span>") );
...@@ -1287,7 +1287,7 @@ test( "clone()", function() { ...@@ -1287,7 +1287,7 @@ test( "clone()", function() {
equal( jQuery("#nonnodes").contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); 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 // Verify that clones of clones can keep event listeners
div = jQuery("<div><ul><li>test</li></ul></div>").click(function() { div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
ok( true, "Bound event still exists." ); ok( true, "Bound event still exists." );
}); });
clone = div.clone( true ); div.remove(); clone = div.clone( true ); div.remove();
...@@ -1302,7 +1302,7 @@ test( "clone()", function() { ...@@ -1302,7 +1302,7 @@ test( "clone()", function() {
// Verify that cloned children can keep event listeners // Verify that cloned children can keep event listeners
div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]); div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
div.find("table").click(function() { div.find("table").on( "click", function() {
ok( true, "Bound event still exists." ); ok( true, "Bound event still exists." );
}); });
...@@ -1316,7 +1316,7 @@ test( "clone()", function() { ...@@ -1316,7 +1316,7 @@ test( "clone()", function() {
clone.remove(); clone.remove();
// Make sure that doing .clone() doesn't clone event listeners // Make sure that doing .clone() doesn't clone event listeners
div = jQuery("<div><ul><li>test</li></ul></div>").click(function() { div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
ok( false, "Bound event still exists after .clone()." ); ok( false, "Bound event still exists after .clone()." );
}); });
clone = div.clone(); clone = div.clone();
...@@ -1734,9 +1734,9 @@ test( "remove() event cleaning ", 1, function() { ...@@ -1734,9 +1734,9 @@ test( "remove() event cleaning ", 1, function() {
count = 0; count = 0;
first = jQuery("#ap").children(":first"); first = jQuery("#ap").children(":first");
cleanUp = first.click(function() { cleanUp = first.on( "click", function() {
count++; count++;
}).remove().appendTo("#qunit-fixture").click(); }).remove().appendTo("#qunit-fixture").trigger("click");
strictEqual( 0, count, "Event handler has been removed" ); strictEqual( 0, count, "Event handler has been removed" );
...@@ -1753,9 +1753,9 @@ test( "detach() event cleaning ", 1, function() { ...@@ -1753,9 +1753,9 @@ test( "detach() event cleaning ", 1, function() {
count = 0; count = 0;
first = jQuery("#ap").children(":first"); first = jQuery("#ap").children(":first");
cleanUp = first.click(function() { cleanUp = first.on( "click", function() {
count++; count++;
}).detach().appendTo("#qunit-fixture").click(); }).detach().appendTo("#qunit-fixture").trigger("click");
strictEqual( 1, count, "Event handler has not been removed" ); strictEqual( 1, count, "Event handler has not been removed" );
...@@ -1832,13 +1832,13 @@ test( "jQuery.cleanData", function() { ...@@ -1832,13 +1832,13 @@ test( "jQuery.cleanData", function() {
div.remove(); div.remove();
function getDiv() { function getDiv() {
var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function() { var div = jQuery("<div class='outer'><div class='inner'></div></div>").on( "click", function() {
ok( true, type + " " + pos + " Click event fired." ); ok( true, type + " " + pos + " Click event fired." );
}).focus(function() { }).on( "focus", function() {
ok( true, type + " " + pos + " Focus event fired." ); ok( true, type + " " + pos + " Focus event fired." );
}).find("div").click(function() { }).find("div").on( "click", function() {
ok( false, type + " " + pos + " Click event fired." ); ok( false, type + " " + pos + " Click event fired." );
}).focus(function() { }).on( "focus", function() {
ok( false, type + " " + pos + " Focus event fired." ); ok( false, type + " " + pos + " Focus event fired." );
}).end().appendTo("body"); }).end().appendTo("body");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment