Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #12656. Make event shorthands excludable.
  • Loading branch information
dmethvin committed Jan 27, 2013
1 parent 3f9f2b1 commit 24e7624
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 167 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -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" ] },
Expand Down
15 changes: 15 additions & 0 deletions 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 );
};
38 changes: 11 additions & 27 deletions src/event.js
Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
}
});
2 changes: 1 addition & 1 deletion test/unit/attributes.js
Expand Up @@ -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]" );

Expand Down
9 changes: 6 additions & 3 deletions test/unit/core.js
Expand Up @@ -34,16 +34,19 @@ 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"
};

// 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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 24e7624

Please sign in to comment.