|
define( [ |
|
"../core", |
|
"../var/document", |
|
"../data/var/dataPriv", |
|
"../data/var/acceptData", |
|
"../var/hasOwn", |
|
|
|
"../event" |
|
], function( jQuery, document, dataPriv, acceptData, hasOwn ) { |
|
|
|
var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/; |
|
|
|
jQuery.extend( jQuery.event, { |
|
|
|
trigger: function( event, data, elem, onlyHandlers ) { |
|
|
|
var i, cur, tmp, bubbleType, ontype, handle, special, |
|
eventPath = [ elem || document ], |
|
type = hasOwn.call( event, "type" ) ? event.type : event, |
|
namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : []; |
|
|
|
cur = tmp = elem = elem || document; |
|
|
|
|
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) { |
|
return; |
|
} |
|
|
|
|
|
if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { |
|
return; |
|
} |
|
|
|
if ( type.indexOf( "." ) > -1 ) { |
|
|
|
|
|
namespaces = type.split( "." ); |
|
type = namespaces.shift(); |
|
namespaces.sort(); |
|
} |
|
ontype = type.indexOf( ":" ) < 0 && "on" + type; |
|
|
|
|
|
event = event[ jQuery.expando ] ? |
|
event : |
|
new jQuery.Event( type, typeof event === "object" && event ); |
|
|
|
|
|
event.isTrigger = onlyHandlers ? 2 : 3; |
|
event.namespace = namespaces.join( "." ); |
|
event.rnamespace = event.namespace ? |
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) : |
|
null; |
|
|
|
|
|
event.result = undefined; |
|
if ( !event.target ) { |
|
event.target = elem; |
|
} |
|
|
|
|
|
data = data == null ? |
|
[ event ] : |
|
jQuery.makeArray( data, [ event ] ); |
|
|
|
|
|
special = jQuery.event.special[ type ] || {}; |
|
if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) { |
|
return; |
|
} |
|
|
|
|
|
|
|
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) { |
|
|
|
bubbleType = special.delegateType || type; |
|
if ( !rfocusMorph.test( bubbleType + type ) ) { |
|
cur = cur.parentNode; |
|
} |
|
for ( ; cur; cur = cur.parentNode ) { |
|
eventPath.push( cur ); |
|
tmp = cur; |
|
} |
|
|
|
|
|
if ( tmp === ( elem.ownerDocument || document ) ) { |
|
eventPath.push( tmp.defaultView || tmp.parentWindow || window ); |
|
} |
|
} |
|
|
|
|
|
i = 0; |
|
while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) { |
|
|
|
event.type = i > 1 ? |
|
bubbleType : |
|
special.bindType || type; |
|
|
|
|
|
handle = ( dataPriv.get( cur, "events" ) || {} )[ event.type ] && |
|
dataPriv.get( cur, "handle" ); |
|
if ( handle ) { |
|
handle.apply( cur, data ); |
|
} |
|
|
|
|
|
handle = ontype && cur[ ontype ]; |
|
if ( handle && handle.apply && acceptData( cur ) ) { |
|
event.result = handle.apply( cur, data ); |
|
if ( event.result === false ) { |
|
event.preventDefault(); |
|
} |
|
} |
|
} |
|
event.type = type; |
|
|
|
|
|
if ( !onlyHandlers && !event.isDefaultPrevented() ) { |
|
|
|
if ( ( !special._default || |
|
special._default.apply( eventPath.pop(), data ) === false ) && |
|
acceptData( elem ) ) { |
|
|
|
|
|
|
|
if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) { |
|
|
|
|
|
tmp = elem[ ontype ]; |
|
|
|
if ( tmp ) { |
|
elem[ ontype ] = null; |
|
} |
|
|
|
|
|
jQuery.event.triggered = type; |
|
elem[ type ](); |
|
jQuery.event.triggered = undefined; |
|
|
|
if ( tmp ) { |
|
elem[ ontype ] = tmp; |
|
} |
|
} |
|
} |
|
} |
|
|
|
return event.result; |
|
}, |
|
|
|
|
|
simulate: function( type, elem, event ) { |
|
var e = jQuery.extend( |
|
new jQuery.Event(), |
|
event, |
|
{ |
|
type: type, |
|
isSimulated: true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
); |
|
|
|
jQuery.event.trigger( e, null, elem ); |
|
|
|
if ( e.isDefaultPrevented() ) { |
|
event.preventDefault(); |
|
} |
|
} |
|
|
|
} ); |
|
|
|
jQuery.fn.extend( { |
|
|
|
trigger: function( type, data ) { |
|
return this.each( function() { |
|
jQuery.event.trigger( type, data, this ); |
|
} ); |
|
}, |
|
triggerHandler: function( type, data ) { |
|
var elem = this[ 0 ]; |
|
if ( elem ) { |
|
return jQuery.event.trigger( type, data, elem, true ); |
|
} |
|
} |
|
} ); |
|
|
|
return jQuery; |
|
} ); |
|
|