mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
No ticket: compress event.js
This commit is contained in:
parent
7be47fba08
commit
9cf812d7a2
4
src/effects.js
vendored
4
src/effects.js
vendored
@ -161,9 +161,9 @@ function Animation( elem, properties, options ) {
|
|||||||
|
|
||||||
jQuery.fx.timer(
|
jQuery.fx.timer(
|
||||||
jQuery.extend( tick, {
|
jQuery.extend( tick, {
|
||||||
|
elem: elem,
|
||||||
anim: animation,
|
anim: animation,
|
||||||
queue: animation.opts.queue,
|
queue: animation.opts.queue
|
||||||
elem: elem
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
313
src/event.js
313
src/event.js
@ -4,20 +4,31 @@ var rformElems = /^(?:input|select|textarea)$/i,
|
|||||||
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
||||||
rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
|
rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
|
||||||
|
|
||||||
|
function returnTrue() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function returnFalse() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper functions for managing events -- not part of the public interface.
|
* Helper functions for managing events -- not part of the public interface.
|
||||||
* Props to Dean Edwards' addEvent library for many of the ideas.
|
* Props to Dean Edwards' addEvent library for many of the ideas.
|
||||||
*/
|
*/
|
||||||
jQuery.event = {
|
jQuery.event = {
|
||||||
|
|
||||||
add: function( elem, types, handler, data, selector ) {
|
global: {},
|
||||||
var elemData, eventHandle, events,
|
|
||||||
tns, type, namespaces, handleObj,
|
|
||||||
handleObjIn, handlers, special,
|
|
||||||
t = 0;
|
|
||||||
|
|
||||||
// Don't attach events to noData or text/comment nodes (allow plain objects tho)
|
add: function( elem, types, handler, data, selector ) {
|
||||||
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
|
|
||||||
|
var handleObjIn, eventHandle, tmp,
|
||||||
|
events, t, handleObj,
|
||||||
|
special, handlers, type, namespaces, origType,
|
||||||
|
// Don't attach events to noData or text/comment nodes (but allow plain objects)
|
||||||
|
elemData = elem.nodeType !== 3 && elem.nodeType !== 8 && jQuery._data( elem );
|
||||||
|
|
||||||
|
if ( !elemData ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,13 +45,11 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init the element's event structure and main handler, if this is the first
|
// Init the element's event structure and main handler, if this is the first
|
||||||
events = elemData.events;
|
if ( !(events = elemData.events) ) {
|
||||||
if ( !events ) {
|
events = elemData.events = {};
|
||||||
elemData.events = events = {};
|
|
||||||
}
|
}
|
||||||
eventHandle = elemData.handle;
|
if ( !(eventHandle = elemData.handle) ) {
|
||||||
if ( !eventHandle ) {
|
eventHandle = elemData.handle = function( e ) {
|
||||||
elemData.handle = eventHandle = function( e ) {
|
|
||||||
// Discard the second event of a jQuery.event.trigger() and
|
// Discard the second event of a jQuery.event.trigger() and
|
||||||
// when an event is called after a page has unloaded
|
// when an event is called after a page has unloaded
|
||||||
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
|
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
|
||||||
@ -54,11 +63,11 @@ jQuery.event = {
|
|||||||
// Handle multiple events separated by a space
|
// Handle multiple events separated by a space
|
||||||
// jQuery(...).bind("mouseover mouseout", fn);
|
// jQuery(...).bind("mouseover mouseout", fn);
|
||||||
types = ( types || "" ).match( core_rnotwhite ) || [""];
|
types = ( types || "" ).match( core_rnotwhite ) || [""];
|
||||||
for ( ; t < types.length; t++ ) {
|
t = types.length;
|
||||||
|
while ( t-- ) {
|
||||||
tns = rtypenamespace.exec( types[t] ) || [];
|
tmp = rtypenamespace.exec( types[t] ) || [];
|
||||||
type = tns[1];
|
type = origType = tmp[1];
|
||||||
namespaces = ( tns[2] || "" ).split( "." ).sort();
|
namespaces = ( tmp[2] || "" ).split( "." ).sort();
|
||||||
|
|
||||||
// If event changes its type, use the special event handlers for the changed type
|
// If event changes its type, use the special event handlers for the changed type
|
||||||
special = jQuery.event.special[ type ] || {};
|
special = jQuery.event.special[ type ] || {};
|
||||||
@ -72,7 +81,7 @@ jQuery.event = {
|
|||||||
// handleObj is passed to all event handlers
|
// handleObj is passed to all event handlers
|
||||||
handleObj = jQuery.extend({
|
handleObj = jQuery.extend({
|
||||||
type: type,
|
type: type,
|
||||||
origType: tns[1],
|
origType: origType,
|
||||||
data: data,
|
data: data,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
guid: handler.guid,
|
guid: handler.guid,
|
||||||
@ -82,8 +91,7 @@ jQuery.event = {
|
|||||||
}, handleObjIn );
|
}, handleObjIn );
|
||||||
|
|
||||||
// Init the event handler queue if we're the first
|
// Init the event handler queue if we're the first
|
||||||
handlers = events[ type ];
|
if ( !(handlers = events[ type ]) ) {
|
||||||
if ( !handlers ) {
|
|
||||||
handlers = events[ type ] = [];
|
handlers = events[ type ] = [];
|
||||||
handlers.delegateCount = 0;
|
handlers.delegateCount = 0;
|
||||||
|
|
||||||
@ -122,14 +130,12 @@ jQuery.event = {
|
|||||||
elem = null;
|
elem = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
global: {},
|
|
||||||
|
|
||||||
// Detach an event or set of events from an element
|
// Detach an event or set of events from an element
|
||||||
remove: function( elem, types, handler, selector, mappedTypes ) {
|
remove: function( elem, types, handler, selector, mappedTypes ) {
|
||||||
|
|
||||||
var tns, type, origType, namespaces, origCount,
|
var j, origCount, tmp,
|
||||||
j, events, special, eventType, handleObj,
|
events, t, handleObj,
|
||||||
t = 0,
|
special, handlers, type, namespaces, origType,
|
||||||
elemData = jQuery.hasData( elem ) && jQuery._data( elem );
|
elemData = jQuery.hasData( elem ) && jQuery._data( elem );
|
||||||
|
|
||||||
if ( !elemData || !(events = elemData.events) ) {
|
if ( !elemData || !(events = elemData.events) ) {
|
||||||
@ -138,10 +144,11 @@ jQuery.event = {
|
|||||||
|
|
||||||
// Once for each type.namespace in types; type may be omitted
|
// Once for each type.namespace in types; type may be omitted
|
||||||
types = ( types || "" ).match( core_rnotwhite ) || [""];
|
types = ( types || "" ).match( core_rnotwhite ) || [""];
|
||||||
for ( ; t < types.length; t++ ) {
|
t = types.length;
|
||||||
tns = rtypenamespace.exec( types[t] ) || [];
|
while ( t-- ) {
|
||||||
type = origType = tns[1];
|
tmp = rtypenamespace.exec( types[t] ) || [];
|
||||||
namespaces = tns[2];
|
type = origType = tmp[1];
|
||||||
|
namespaces = ( tmp[2] || "" ).split( "." ).sort();
|
||||||
|
|
||||||
// Unbind all events (on this namespace, if provided) for the element
|
// Unbind all events (on this namespace, if provided) for the element
|
||||||
if ( !type ) {
|
if ( !type ) {
|
||||||
@ -153,22 +160,22 @@ jQuery.event = {
|
|||||||
|
|
||||||
special = jQuery.event.special[ type ] || {};
|
special = jQuery.event.special[ type ] || {};
|
||||||
type = ( selector ? special.delegateType : special.bindType ) || type;
|
type = ( selector ? special.delegateType : special.bindType ) || type;
|
||||||
eventType = events[ type ] || [];
|
handlers = events[ type ] || [];
|
||||||
origCount = eventType.length;
|
tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
|
||||||
namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
|
|
||||||
|
|
||||||
// Remove matching events
|
// Remove matching events
|
||||||
for ( j = 0; j < eventType.length; j++ ) {
|
origCount = j = handlers.length;
|
||||||
handleObj = eventType[ j ];
|
while ( j-- ) {
|
||||||
|
handleObj = handlers[ j ];
|
||||||
|
|
||||||
if ( ( mappedTypes || origType === handleObj.origType ) &&
|
if ( ( mappedTypes || origType === handleObj.origType ) &&
|
||||||
( !handler || handler.guid === handleObj.guid ) &&
|
( !handler || handler.guid === handleObj.guid ) &&
|
||||||
( !namespaces || namespaces.test( handleObj.namespace ) ) &&
|
( !tmp || tmp.test( handleObj.namespace ) ) &&
|
||||||
( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
|
( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
|
||||||
eventType.splice( j--, 1 );
|
handlers.splice( j, 1 );
|
||||||
|
|
||||||
if ( handleObj.selector ) {
|
if ( handleObj.selector ) {
|
||||||
eventType.delegateCount--;
|
handlers.delegateCount--;
|
||||||
}
|
}
|
||||||
if ( special.remove ) {
|
if ( special.remove ) {
|
||||||
special.remove.call( elem, handleObj );
|
special.remove.call( elem, handleObj );
|
||||||
@ -178,7 +185,7 @@ jQuery.event = {
|
|||||||
|
|
||||||
// Remove generic event handler if we removed something and no more handlers exist
|
// Remove generic event handler if we removed something and no more handlers exist
|
||||||
// (avoids potential for endless recursion during removal of special event handlers)
|
// (avoids potential for endless recursion during removal of special event handlers)
|
||||||
if ( eventType.length === 0 && origCount !== eventType.length ) {
|
if ( origCount && !handlers.length ) {
|
||||||
if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
|
if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
|
||||||
jQuery.removeEvent( elem, type, elemData.handle );
|
jQuery.removeEvent( elem, type, elemData.handle );
|
||||||
}
|
}
|
||||||
@ -199,11 +206,12 @@ jQuery.event = {
|
|||||||
|
|
||||||
trigger: function( event, data, elem, onlyHandlers ) {
|
trigger: function( event, data, elem, onlyHandlers ) {
|
||||||
|
|
||||||
var i, cur, old, ontype, special, handle, eventPath, bubbleType,
|
var i, cur, tmp, bubbleType, ontype, handle, special,
|
||||||
|
eventPath = [ elem || document ],
|
||||||
type = event.type || event,
|
type = event.type || event,
|
||||||
namespaces = event.namespace ? event.namespace.split(".") : [];
|
namespaces = event.namespace ? event.namespace.split(".") : [];
|
||||||
|
|
||||||
elem = elem || document;
|
cur = tmp = elem = elem || document;
|
||||||
|
|
||||||
// Don't do events on text and comment nodes
|
// Don't do events on text and comment nodes
|
||||||
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
||||||
@ -221,21 +229,19 @@ jQuery.event = {
|
|||||||
type = namespaces.shift();
|
type = namespaces.shift();
|
||||||
namespaces.sort();
|
namespaces.sort();
|
||||||
}
|
}
|
||||||
|
ontype = type.indexOf(":") < 0 && "on" + type;
|
||||||
|
|
||||||
// Caller can pass in an Event, Object, or just an event type string
|
// Caller can pass in a jQuery.Event object, Object, or just an event type string
|
||||||
event = typeof event === "object" ?
|
event = event[ jQuery.expando ] ?
|
||||||
// jQuery.Event object
|
event :
|
||||||
event[ jQuery.expando ] ? event :
|
new jQuery.Event( type, typeof event === "object" && event );
|
||||||
// Object literal
|
|
||||||
new jQuery.Event( type, event ) :
|
|
||||||
// Just the event type (string)
|
|
||||||
new jQuery.Event( type );
|
|
||||||
|
|
||||||
event.type = type;
|
|
||||||
event.isTrigger = true;
|
event.isTrigger = true;
|
||||||
|
event.type = type;
|
||||||
event.namespace = namespaces.join(".");
|
event.namespace = namespaces.join(".");
|
||||||
event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
|
event.namespace_re = event.namespace ?
|
||||||
ontype = type.indexOf(":") < 0 ? "on" + type : "";
|
new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
|
||||||
|
null;
|
||||||
|
|
||||||
// Clean up the event in case it is being reused
|
// Clean up the event in case it is being reused
|
||||||
event.result = undefined;
|
event.result = undefined;
|
||||||
@ -244,8 +250,9 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clone any incoming data and prepend the event, creating the handler arg list
|
// Clone any incoming data and prepend the event, creating the handler arg list
|
||||||
data = data != null ? jQuery.makeArray( data ) : [];
|
data = data == null ?
|
||||||
data.unshift( event );
|
[ event ] :
|
||||||
|
jQuery.makeArray( data, [ event ] );
|
||||||
|
|
||||||
// Allow special events to draw outside the lines
|
// Allow special events to draw outside the lines
|
||||||
special = jQuery.event.special[ type ] || {};
|
special = jQuery.event.special[ type ] || {};
|
||||||
@ -255,33 +262,38 @@ jQuery.event = {
|
|||||||
|
|
||||||
// Determine event propagation path in advance, per W3C events spec (#9951)
|
// Determine event propagation path in advance, per W3C events spec (#9951)
|
||||||
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
||||||
eventPath = [[ elem, special.bindType || type ]];
|
|
||||||
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
|
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
|
||||||
|
|
||||||
bubbleType = special.delegateType || type;
|
bubbleType = special.delegateType || type;
|
||||||
cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
|
if ( !rfocusMorph.test( bubbleType + type ) ) {
|
||||||
for ( old = elem; cur; cur = cur.parentNode ) {
|
cur = cur.parentNode;
|
||||||
eventPath.push([ cur, bubbleType ]);
|
}
|
||||||
old = cur;
|
for ( ; cur; cur = cur.parentNode ) {
|
||||||
|
eventPath.push( cur );
|
||||||
|
tmp = cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add window if we got to document (e.g., not plain obj or detached DOM)
|
// Only add window if we got to document (e.g., not plain obj or detached DOM)
|
||||||
if ( old === (elem.ownerDocument || document) ) {
|
if ( tmp === (elem.ownerDocument || document) ) {
|
||||||
eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
|
eventPath.push( tmp.defaultView || tmp.parentWindow || window );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire handlers on the event path
|
// Fire handlers on the event path
|
||||||
for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) {
|
i = 0;
|
||||||
|
while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
|
||||||
|
|
||||||
cur = eventPath[i][0];
|
event.type = i > 1 ?
|
||||||
event.type = eventPath[i][1];
|
bubbleType :
|
||||||
|
special.bindType || type;
|
||||||
|
|
||||||
|
// jQuery handler
|
||||||
handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
|
handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
|
||||||
if ( handle ) {
|
if ( handle ) {
|
||||||
handle.apply( cur, data );
|
handle.apply( cur, data );
|
||||||
}
|
}
|
||||||
// Note that this is a bare JS function and not a jQuery handler
|
|
||||||
|
// Native handler
|
||||||
handle = ontype && cur[ ontype ];
|
handle = ontype && cur[ ontype ];
|
||||||
if ( handle && jQuery.acceptData( cur ) && handle.apply && handle.apply( cur, data ) === false ) {
|
if ( handle && jQuery.acceptData( cur ) && handle.apply && handle.apply( cur, data ) === false ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -301,9 +313,9 @@ jQuery.event = {
|
|||||||
if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) {
|
if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) {
|
||||||
|
|
||||||
// Don't re-trigger an onFOO event when we call its FOO() method
|
// Don't re-trigger an onFOO event when we call its FOO() method
|
||||||
old = elem[ ontype ];
|
tmp = elem[ ontype ];
|
||||||
|
|
||||||
if ( old ) {
|
if ( tmp ) {
|
||||||
elem[ ontype ] = null;
|
elem[ ontype ] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,8 +329,8 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
jQuery.event.triggered = undefined;
|
jQuery.event.triggered = undefined;
|
||||||
|
|
||||||
if ( old ) {
|
if ( tmp ) {
|
||||||
elem[ ontype ] = old;
|
elem[ ontype ] = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,11 +345,11 @@ jQuery.event = {
|
|||||||
event = jQuery.event.fix( event );
|
event = jQuery.event.fix( event );
|
||||||
|
|
||||||
var i, j, cur, ret, selMatch, matched, matches, handleObj, sel,
|
var i, j, cur, ret, selMatch, matched, matches, handleObj, sel,
|
||||||
handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []),
|
handlerQueue = [],
|
||||||
delegateCount = handlers.delegateCount,
|
|
||||||
args = core_slice.call( arguments ),
|
args = core_slice.call( arguments ),
|
||||||
special = jQuery.event.special[ event.type ] || {},
|
handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [],
|
||||||
handlerQueue = [];
|
delegateCount = handlers.delegateCount,
|
||||||
|
special = jQuery.event.special[ event.type ] || {};
|
||||||
|
|
||||||
// Use the fix-ed jQuery.Event rather than the (read-only) native event
|
// Use the fix-ed jQuery.Event rather than the (read-only) native event
|
||||||
args[0] = event;
|
args[0] = event;
|
||||||
@ -358,7 +370,8 @@ jQuery.event = {
|
|||||||
if ( cur.disabled !== true || event.type !== "click" ) {
|
if ( cur.disabled !== true || event.type !== "click" ) {
|
||||||
selMatch = {};
|
selMatch = {};
|
||||||
matches = [];
|
matches = [];
|
||||||
for ( i = 0; i < delegateCount; i++ ) {
|
i = 0;
|
||||||
|
for ( ; i < delegateCount; i++ ) {
|
||||||
handleObj = handlers[ i ];
|
handleObj = handlers[ i ];
|
||||||
sel = handleObj.selector;
|
sel = handleObj.selector;
|
||||||
|
|
||||||
@ -372,7 +385,7 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( matches.length ) {
|
if ( matches.length ) {
|
||||||
handlerQueue.push({ elem: cur, matches: matches });
|
handlerQueue.push({ elem: cur, handlers: matches });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,30 +393,29 @@ jQuery.event = {
|
|||||||
|
|
||||||
// Add the remaining (directly-bound) handlers
|
// Add the remaining (directly-bound) handlers
|
||||||
if ( handlers.length > delegateCount ) {
|
if ( handlers.length > delegateCount ) {
|
||||||
handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) });
|
handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run delegates first; they may want to stop propagation beneath us
|
// Run delegates first; they may want to stop propagation beneath us
|
||||||
for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) {
|
i = 0;
|
||||||
matched = handlerQueue[ i ];
|
while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
|
||||||
event.currentTarget = matched.elem;
|
event.currentTarget = matched.elem;
|
||||||
|
|
||||||
for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) {
|
j = 0;
|
||||||
handleObj = matched.matches[ j ];
|
while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
|
||||||
|
|
||||||
// Triggered event must either 1) have no namespace, or
|
// Triggered event must either 1) have no namespace, or
|
||||||
// 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
|
// 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
|
||||||
if ( !event.namespace || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) {
|
if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
|
||||||
|
|
||||||
event.data = handleObj.data;
|
|
||||||
event.handleObj = handleObj;
|
event.handleObj = handleObj;
|
||||||
|
event.data = handleObj.data;
|
||||||
|
|
||||||
ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
|
ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
|
||||||
.apply( matched.elem, args );
|
.apply( matched.elem, args );
|
||||||
|
|
||||||
if ( ret !== undefined ) {
|
if ( ret !== undefined ) {
|
||||||
event.result = ret;
|
if ( (event.result = ret) === false ) {
|
||||||
if ( ret === false ) {
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
@ -420,6 +432,44 @@ jQuery.event = {
|
|||||||
return event.result;
|
return event.result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fix: function( event ) {
|
||||||
|
if ( event[ jQuery.expando ] ) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a writable copy of the event object and normalize some properties
|
||||||
|
var i, prop,
|
||||||
|
originalEvent = event,
|
||||||
|
fixHook = jQuery.event.fixHooks[ event.type ] || {},
|
||||||
|
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
|
||||||
|
|
||||||
|
event = new jQuery.Event( originalEvent );
|
||||||
|
|
||||||
|
i = copy.length;
|
||||||
|
while ( i-- ) {
|
||||||
|
prop = copy[ i ];
|
||||||
|
event[ prop ] = originalEvent[ prop ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support: IE<9
|
||||||
|
// Fix target property (#1925)
|
||||||
|
if ( !event.target ) {
|
||||||
|
event.target = originalEvent.srcElement || document;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support: Safari
|
||||||
|
// Target should not be a text node (#504)
|
||||||
|
if ( event.target.nodeType === 3 ) {
|
||||||
|
event.target = event.target.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support: IE<9
|
||||||
|
// For mouse/key events, metaKey==false if it's undefined (#3368, #11328)
|
||||||
|
event.metaKey = !!event.metaKey;
|
||||||
|
|
||||||
|
return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
|
||||||
|
},
|
||||||
|
|
||||||
// Includes some event props shared by KeyEvent and MouseEvent
|
// Includes some event props shared by KeyEvent and MouseEvent
|
||||||
props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
|
props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
|
||||||
|
|
||||||
@ -470,40 +520,6 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fix: function( event ) {
|
|
||||||
if ( event[ jQuery.expando ] ) {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a writable copy of the event object and normalize some properties
|
|
||||||
var i, prop,
|
|
||||||
originalEvent = event,
|
|
||||||
fixHook = jQuery.event.fixHooks[ event.type ] || {},
|
|
||||||
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
|
|
||||||
|
|
||||||
event = jQuery.Event( originalEvent );
|
|
||||||
|
|
||||||
for ( i = copy.length; i; ) {
|
|
||||||
prop = copy[ --i ];
|
|
||||||
event[ prop ] = originalEvent[ prop ];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix target property, if necessary (#1925, IE 6/7/8 & Safari2)
|
|
||||||
if ( !event.target ) {
|
|
||||||
event.target = originalEvent.srcElement || document;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Target should not be a text node (#504, Safari)
|
|
||||||
if ( event.target.nodeType === 3 ) {
|
|
||||||
event.target = event.target.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For mouse/key events, metaKey==false if it's undefined (#3368, #11328; IE6/7/8)
|
|
||||||
event.metaKey = !!event.metaKey;
|
|
||||||
|
|
||||||
return fixHook.filter? fixHook.filter( event, originalEvent ) : event;
|
|
||||||
},
|
|
||||||
|
|
||||||
special: {
|
special: {
|
||||||
load: {
|
load: {
|
||||||
// Prevent triggered image.load events from bubbling to window.load
|
// Prevent triggered image.load events from bubbling to window.load
|
||||||
@ -512,7 +528,7 @@ jQuery.event = {
|
|||||||
click: {
|
click: {
|
||||||
// For checkbox, fire native event so checked state will be right
|
// For checkbox, fire native event so checked state will be right
|
||||||
trigger: function() {
|
trigger: function() {
|
||||||
if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) {
|
if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
|
||||||
this.click();
|
this.click();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -526,8 +542,9 @@ jQuery.event = {
|
|||||||
this.focus();
|
this.focus();
|
||||||
return false;
|
return false;
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
// IE<9 dies on focus to hidden element (#1486,#12518)
|
// Support: IE<9
|
||||||
// If this happens, let .trigger() run the handlers
|
// If we error on focus to hidden element (#1486, #12518),
|
||||||
|
// let .trigger() run the handlers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -577,10 +594,6 @@ jQuery.event = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Some plugins are using, but it's undocumented/deprecated and will be removed.
|
|
||||||
// The 1.7 special event interface should provide all the hooks needed now.
|
|
||||||
jQuery.event.handle = jQuery.event.dispatch;
|
|
||||||
|
|
||||||
jQuery.removeEvent = document.removeEventListener ?
|
jQuery.removeEvent = document.removeEventListener ?
|
||||||
function( elem, type, handle ) {
|
function( elem, type, handle ) {
|
||||||
if ( elem.removeEventListener ) {
|
if ( elem.removeEventListener ) {
|
||||||
@ -635,54 +648,51 @@ jQuery.Event = function( src, props ) {
|
|||||||
this[ jQuery.expando ] = true;
|
this[ jQuery.expando ] = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function returnFalse() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
function returnTrue() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
|
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
|
||||||
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
|
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
|
||||||
jQuery.Event.prototype = {
|
jQuery.Event.prototype = {
|
||||||
preventDefault: function() {
|
isDefaultPrevented: returnFalse,
|
||||||
this.isDefaultPrevented = returnTrue;
|
isPropagationStopped: returnFalse,
|
||||||
|
isImmediatePropagationStopped: returnFalse,
|
||||||
|
|
||||||
|
preventDefault: function() {
|
||||||
var e = this.originalEvent;
|
var e = this.originalEvent;
|
||||||
|
|
||||||
|
this.isDefaultPrevented = returnTrue;
|
||||||
if ( !e ) {
|
if ( !e ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if preventDefault exists run it on the original event
|
// If preventDefault exists, run it on the original event
|
||||||
if ( e.preventDefault ) {
|
if ( e.preventDefault ) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// otherwise set the returnValue property of the original event to false (IE)
|
// Support: IE
|
||||||
|
// Otherwise set the returnValue property of the original event to false
|
||||||
} else {
|
} else {
|
||||||
e.returnValue = false;
|
e.returnValue = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stopPropagation: function() {
|
stopPropagation: function() {
|
||||||
this.isPropagationStopped = returnTrue;
|
|
||||||
|
|
||||||
var e = this.originalEvent;
|
var e = this.originalEvent;
|
||||||
|
|
||||||
|
this.isPropagationStopped = returnTrue;
|
||||||
if ( !e ) {
|
if ( !e ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if stopPropagation exists run it on the original event
|
// If stopPropagation exists, run it on the original event
|
||||||
if ( e.stopPropagation ) {
|
if ( e.stopPropagation ) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
// otherwise set the cancelBubble property of the original event to true (IE)
|
|
||||||
|
// Support: IE
|
||||||
|
// Set the cancelBubble property of the original event to true
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
},
|
},
|
||||||
stopImmediatePropagation: function() {
|
stopImmediatePropagation: function() {
|
||||||
this.isImmediatePropagationStopped = returnTrue;
|
this.isImmediatePropagationStopped = returnTrue;
|
||||||
this.stopPropagation();
|
this.stopPropagation();
|
||||||
},
|
}
|
||||||
isDefaultPrevented: returnFalse,
|
|
||||||
isPropagationStopped: returnFalse,
|
|
||||||
isImmediatePropagationStopped: returnFalse
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create mouseenter/leave events using mouseover/out and event-time checks
|
// Create mouseenter/leave events using mouseover/out and event-time checks
|
||||||
@ -727,11 +737,11 @@ if ( !jQuery.support.submitBubbles ) {
|
|||||||
// Node name check avoids a VML-related crash in IE (#9807)
|
// Node name check avoids a VML-related crash in IE (#9807)
|
||||||
var elem = e.target,
|
var elem = e.target,
|
||||||
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
|
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
|
||||||
if ( form && !jQuery._data( form, "_submit_attached" ) ) {
|
if ( form && !jQuery._data( form, "submitBubbles" ) ) {
|
||||||
jQuery.event.add( form, "submit._submit", function( event ) {
|
jQuery.event.add( form, "submit._submit", function( event ) {
|
||||||
event._submit_bubble = true;
|
event._submit_bubble = true;
|
||||||
});
|
});
|
||||||
jQuery._data( form, "_submit_attached", true );
|
jQuery._data( form, "submitBubbles", true );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// return undefined since we don't need an event listener
|
// return undefined since we don't need an event listener
|
||||||
@ -790,13 +800,13 @@ if ( !jQuery.support.changeBubbles ) {
|
|||||||
jQuery.event.add( this, "beforeactivate._change", function( e ) {
|
jQuery.event.add( this, "beforeactivate._change", function( e ) {
|
||||||
var elem = e.target;
|
var elem = e.target;
|
||||||
|
|
||||||
if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "_change_attached" ) ) {
|
if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "changeBubbles" ) ) {
|
||||||
jQuery.event.add( elem, "change._change", function( event ) {
|
jQuery.event.add( elem, "change._change", function( event ) {
|
||||||
if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
|
if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
|
||||||
jQuery.event.simulate( "change", this.parentNode, event, true );
|
jQuery.event.simulate( "change", this.parentNode, event, true );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
jQuery._data( elem, "_change_attached", true );
|
jQuery._data( elem, "changeBubbles", true );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -851,7 +861,7 @@ jQuery.fn.extend({
|
|||||||
// Types can be a map of types/handlers
|
// Types can be a map of types/handlers
|
||||||
if ( typeof types === "object" ) {
|
if ( typeof types === "object" ) {
|
||||||
// ( types-Object, selector, data )
|
// ( types-Object, selector, data )
|
||||||
if ( typeof selector !== "string" ) { // && selector != null
|
if ( typeof selector !== "string" ) {
|
||||||
// ( types-Object, data )
|
// ( types-Object, data )
|
||||||
data = data || selector;
|
data = data || selector;
|
||||||
selector = undefined;
|
selector = undefined;
|
||||||
@ -954,8 +964,9 @@ jQuery.fn.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
triggerHandler: function( type, data ) {
|
triggerHandler: function( type, data ) {
|
||||||
if ( this[0] ) {
|
var elem = this[0];
|
||||||
return jQuery.event.trigger( type, data, this[0], true );
|
if ( elem ) {
|
||||||
|
return jQuery.event.trigger( type, data, elem, true );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user