Permalink
Browse files

Fix #12656. Make event shorthands excludable.

  • Loading branch information...
dmethvin committed Jan 27, 2013
1 parent a6c358d commit 6f7b6915bf457c413476faefb2159df717c2c210
Showing with 173 additions and 162 deletions.
  1. +1 −0 Gruntfile.js
  2. +15 −0 src/event-alias.js
  3. +11 −27 src/event.js
  4. +1 −1 test/unit/attributes.js
  5. +6 −3 test/unit/core.js
  6. +113 −105 test/unit/event.js
  7. +26 −26 test/unit/manipulation.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" ] },
@@ -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 );
};
@@ -481,10 +481,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 :

This comment has been minimized.

@staabm

staabm Jan 27, 2013

Contributor

won't this init only one of the event types (either mouse or key), but never both?

This comment has been minimized.

@dmethvin

dmethvin Jan 27, 2013

Member

Yes, but any particular event can only be either a mouse event or a key event.

rkeyEvent.test( type ) ? this.keyHooks :
{};
}
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;

event = new jQuery.Event( originalEvent );

@@ -810,29 +818,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;
}
});
@@ -312,7 +312,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,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;
@@ -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();
Oops, something went wrong.

0 comments on commit 6f7b691

Please sign in to comment.