Commit 24e76245 authored by Dave Methvin's avatar Dave Methvin

Fix #12656. Make event shorthands excludable.

parent 3f9f2b1d
......@@ -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" ] },
......
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 );
};
......@@ -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;
}
});
......@@ -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]" );
......
......@@ -34,9 +34,8 @@ test("jQuery()", function() {
div = jQuery("<div/><hr/><code/><b/>"),
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();
......
This diff is collapsed.
......@@ -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("<div></div>").click(function() {
result = jQuery("<div></div>").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("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
$radioChecked.click();
$radioChecked.trigger("click");
$radioUnchecked[ 0 ].checked = false;
$radioParent.wrap("<div></div>");
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("<a class='test6997'></a>").click(function() {
element = jQuery("<a class='test6997'></a>").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("<li class='test6997'></li>").click(function() {
element = jQuery("<li class='test6997'></li>").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<Element>|jQuery)", function() {
t( "Append select", "#foo select", [ "select1" ] );
QUnit.reset();
div = jQuery("<div/>").click(function() {
div = jQuery("<div/>").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("<div/>").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("<div/>").appendTo("#qunit-fixture").click(function() {
tmp = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
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." );
});
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." );
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("<div/>").appendTo("#qunit-fixture").click(function() {
y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
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." );
return false;
});
y.replaceWith( val(child2) );
child2.click();
child2.trigger("click");
set = jQuery("<div/>").replaceWith( val("<span>test</span>") );
......@@ -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("<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." );
});
clone = div.clone( true ); div.remove();
......@@ -1344,7 +1344,7 @@ test( "clone()", function() {
// Verify that cloned children can keep event listeners
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." );
});
......@@ -1358,7 +1358,7 @@ test( "clone()", function() {
clone.remove();
// 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()." );
});
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("<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." );
}).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");
......
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