Ticket #8753 Allow special properties to explicitly defined on jQuery.Event objects
This commit is contained in:
parent
2ed81b44be
commit
23a411b6bc
2 changed files with 37 additions and 9 deletions
17
src/event.js
17
src/event.js
|
@ -1,6 +1,7 @@
|
||||||
(function( jQuery ) {
|
(function( jQuery ) {
|
||||||
|
|
||||||
var rnamespaces = /\.(.*)$/,
|
var hasOwn = Object.prototype.hasOwnProperty,
|
||||||
|
rnamespaces = /\.(.*)$/,
|
||||||
rformElems = /^(?:textarea|input|select)$/i,
|
rformElems = /^(?:textarea|input|select)$/i,
|
||||||
rperiod = /\./g,
|
rperiod = /\./g,
|
||||||
rspace = / /g,
|
rspace = / /g,
|
||||||
|
@ -581,6 +582,15 @@ jQuery.Event = function( src ) {
|
||||||
this.originalEvent = src;
|
this.originalEvent = src;
|
||||||
this.type = src.type;
|
this.type = src.type;
|
||||||
|
|
||||||
|
// Push explicitly provided properties onto the event object
|
||||||
|
for ( var prop in src ) {
|
||||||
|
// Ensure we don't clobber jQuery.Event prototype
|
||||||
|
// with own properties.
|
||||||
|
if ( hasOwn.call( src, prop ) ) {
|
||||||
|
this[ prop ] = src[ prop ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Events bubbling up the document may have been marked as prevented
|
// Events bubbling up the document may have been marked as prevented
|
||||||
// by a handler lower down the tree; reflect the correct value.
|
// by a handler lower down the tree; reflect the correct value.
|
||||||
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
|
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
|
||||||
|
@ -868,10 +878,10 @@ function trigger( type, elem, args ) {
|
||||||
// Create "bubbling" focus and blur events
|
// Create "bubbling" focus and blur events
|
||||||
if ( document.addEventListener ) {
|
if ( document.addEventListener ) {
|
||||||
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
|
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
|
||||||
|
|
||||||
// Attach a single capturing handler while someone wants focusin/focusout
|
// Attach a single capturing handler while someone wants focusin/focusout
|
||||||
var attaches = 0;
|
var attaches = 0;
|
||||||
|
|
||||||
jQuery.event.special[ fix ] = {
|
jQuery.event.special[ fix ] = {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
if ( attaches++ === 0 ) {
|
if ( attaches++ === 0 ) {
|
||||||
|
@ -1184,3 +1194,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
|
||||||
});
|
});
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
||||||
|
|
|
@ -685,7 +685,6 @@ test("hover()", function() {
|
||||||
|
|
||||||
test("mouseover triggers mouseenter", function() {
|
test("mouseover triggers mouseenter", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
|
|
||||||
var count = 0,
|
var count = 0,
|
||||||
elem = jQuery("<a />");
|
elem = jQuery("<a />");
|
||||||
elem.mouseenter(function () {
|
elem.mouseenter(function () {
|
||||||
|
@ -693,7 +692,6 @@ test("mouseover triggers mouseenter", function() {
|
||||||
});
|
});
|
||||||
elem.trigger('mouseover');
|
elem.trigger('mouseover');
|
||||||
equals(count, 1, "make sure mouseover triggers a mouseenter" );
|
equals(count, 1, "make sure mouseover triggers a mouseenter" );
|
||||||
|
|
||||||
elem.remove();
|
elem.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -930,6 +928,27 @@ test("trigger(eventObject, [data], [fn])", function() {
|
||||||
$parent.unbind().remove();
|
$parent.unbind().remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("jQuery.Event({ /* props */ })", function() {
|
||||||
|
|
||||||
|
expect(4);
|
||||||
|
|
||||||
|
var event = jQuery.Event({ type: "keydown", keyCode: 64 }),
|
||||||
|
handler = function( event ) {
|
||||||
|
ok( "keyCode" in event, "Special property 'keyCode' exists" );
|
||||||
|
equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
|
||||||
|
};
|
||||||
|
|
||||||
|
// Supports jQuery.Event implementation
|
||||||
|
equal( event.type, "keydown", "Verify type" );
|
||||||
|
|
||||||
|
ok( "keyCode" in event, "Special 'keyCode' property exists" );
|
||||||
|
|
||||||
|
jQuery("body").bind( "keydown", handler ).trigger( event );
|
||||||
|
|
||||||
|
jQuery("body").unbind( "keydown" );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test("jQuery.Event.currentTarget", function(){
|
test("jQuery.Event.currentTarget", function(){
|
||||||
expect(1);
|
expect(1);
|
||||||
|
|
||||||
|
@ -1982,8 +2001,7 @@ test("window resize", function() {
|
||||||
|
|
||||||
test("focusin bubbles", function() {
|
test("focusin bubbles", function() {
|
||||||
expect(5);
|
expect(5);
|
||||||
|
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
|
||||||
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
|
|
||||||
order = 0;
|
order = 0;
|
||||||
|
|
||||||
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
|
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
|
||||||
|
@ -1996,12 +2014,10 @@ test("focusin bubbles", function() {
|
||||||
|
|
||||||
// DOM focus method
|
// DOM focus method
|
||||||
input[0].focus();
|
input[0].focus();
|
||||||
|
|
||||||
// To make the next focus test work, we need to take focus off the input.
|
// To make the next focus test work, we need to take focus off the input.
|
||||||
// This will fire another focusin event, so set order to reflect that.
|
// This will fire another focusin event, so set order to reflect that.
|
||||||
order = 1;
|
order = 1;
|
||||||
jQuery("#text1")[0].focus();
|
jQuery("#text1")[0].focus();
|
||||||
|
|
||||||
// jQuery trigger, which calls DOM focus
|
// jQuery trigger, which calls DOM focus
|
||||||
order = 0;
|
order = 0;
|
||||||
input.trigger( "focus" );
|
input.trigger( "focus" );
|
||||||
|
@ -2027,3 +2043,4 @@ test("event properties", function() {
|
||||||
}).click();
|
}).click();
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue