|
define( [ |
|
"./core", |
|
"./var/document", |
|
"./var/rnotwhite", |
|
"./var/slice", |
|
"./data/var/dataPriv", |
|
|
|
"./core/init", |
|
"./selector" |
|
], function( jQuery, document, rnotwhite, slice, dataPriv ) { |
|
|
|
var |
|
rkeyEvent = /^key/, |
|
rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/, |
|
rtypenamespace = /^([^.]*)(?:\.(.+)|)/; |
|
|
|
function returnTrue() { |
|
return true; |
|
} |
|
|
|
function returnFalse() { |
|
return false; |
|
} |
|
|
|
|
|
|
|
function safeActiveElement() { |
|
try { |
|
return document.activeElement; |
|
} catch ( err ) { } |
|
} |
|
|
|
function on( elem, types, selector, data, fn, one ) { |
|
var origFn, type; |
|
|
|
|
|
if ( typeof types === "object" ) { |
|
|
|
|
|
if ( typeof selector !== "string" ) { |
|
|
|
|
|
data = data || selector; |
|
selector = undefined; |
|
} |
|
for ( type in types ) { |
|
on( elem, type, selector, data, types[ type ], one ); |
|
} |
|
return elem; |
|
} |
|
|
|
if ( data == null && fn == null ) { |
|
|
|
|
|
fn = selector; |
|
data = selector = undefined; |
|
} else if ( fn == null ) { |
|
if ( typeof selector === "string" ) { |
|
|
|
|
|
fn = data; |
|
data = undefined; |
|
} else { |
|
|
|
|
|
fn = data; |
|
data = selector; |
|
selector = undefined; |
|
} |
|
} |
|
if ( fn === false ) { |
|
fn = returnFalse; |
|
} else if ( !fn ) { |
|
return elem; |
|
} |
|
|
|
if ( one === 1 ) { |
|
origFn = fn; |
|
fn = function( event ) { |
|
|
|
|
|
jQuery().off( event ); |
|
return origFn.apply( this, arguments ); |
|
}; |
|
|
|
|
|
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); |
|
} |
|
return elem.each( function() { |
|
jQuery.event.add( this, types, fn, data, selector ); |
|
} ); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
jQuery.event = { |
|
|
|
global: {}, |
|
|
|
add: function( elem, types, handler, data, selector ) { |
|
|
|
var handleObjIn, eventHandle, tmp, |
|
events, t, handleObj, |
|
special, handlers, type, namespaces, origType, |
|
elemData = dataPriv.get( elem ); |
|
|
|
|
|
if ( !elemData ) { |
|
return; |
|
} |
|
|
|
|
|
if ( handler.handler ) { |
|
handleObjIn = handler; |
|
handler = handleObjIn.handler; |
|
selector = handleObjIn.selector; |
|
} |
|
|
|
|
|
if ( !handler.guid ) { |
|
handler.guid = jQuery.guid++; |
|
} |
|
|
|
|
|
if ( !( events = elemData.events ) ) { |
|
events = elemData.events = {}; |
|
} |
|
if ( !( eventHandle = elemData.handle ) ) { |
|
eventHandle = elemData.handle = function( e ) { |
|
|
|
|
|
|
|
return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? |
|
jQuery.event.dispatch.apply( elem, arguments ) : undefined; |
|
}; |
|
} |
|
|
|
|
|
types = ( types || "" ).match( rnotwhite ) || [ "" ]; |
|
t = types.length; |
|
while ( t-- ) { |
|
tmp = rtypenamespace.exec( types[ t ] ) || []; |
|
type = origType = tmp[ 1 ]; |
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); |
|
|
|
|
|
if ( !type ) { |
|
continue; |
|
} |
|
|
|
|
|
special = jQuery.event.special[ type ] || {}; |
|
|
|
|
|
type = ( selector ? special.delegateType : special.bindType ) || type; |
|
|
|
|
|
special = jQuery.event.special[ type ] || {}; |
|
|
|
|
|
handleObj = jQuery.extend( { |
|
type: type, |
|
origType: origType, |
|
data: data, |
|
handler: handler, |
|
guid: handler.guid, |
|
selector: selector, |
|
needsContext: selector && jQuery.expr.match.needsContext.test( selector ), |
|
namespace: namespaces.join( "." ) |
|
}, handleObjIn ); |
|
|
|
|
|
if ( !( handlers = events[ type ] ) ) { |
|
handlers = events[ type ] = []; |
|
handlers.delegateCount = 0; |
|
|
|
|
|
if ( !special.setup || |
|
special.setup.call( elem, data, namespaces, eventHandle ) === false ) { |
|
|
|
if ( elem.addEventListener ) { |
|
elem.addEventListener( type, eventHandle ); |
|
} |
|
} |
|
} |
|
|
|
if ( special.add ) { |
|
special.add.call( elem, handleObj ); |
|
|
|
if ( !handleObj.handler.guid ) { |
|
handleObj.handler.guid = handler.guid; |
|
} |
|
} |
|
|
|
|
|
if ( selector ) { |
|
handlers.splice( handlers.delegateCount++, 0, handleObj ); |
|
} else { |
|
handlers.push( handleObj ); |
|
} |
|
|
|
|
|
jQuery.event.global[ type ] = true; |
|
} |
|
|
|
}, |
|
|
|
|
|
remove: function( elem, types, handler, selector, mappedTypes ) { |
|
|
|
var j, origCount, tmp, |
|
events, t, handleObj, |
|
special, handlers, type, namespaces, origType, |
|
elemData = dataPriv.hasData( elem ) && dataPriv.get( elem ); |
|
|
|
if ( !elemData || !( events = elemData.events ) ) { |
|
return; |
|
} |
|
|
|
|
|
types = ( types || "" ).match( rnotwhite ) || [ "" ]; |
|
t = types.length; |
|
while ( t-- ) { |
|
tmp = rtypenamespace.exec( types[ t ] ) || []; |
|
type = origType = tmp[ 1 ]; |
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); |
|
|
|
|
|
if ( !type ) { |
|
for ( type in events ) { |
|
jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); |
|
} |
|
continue; |
|
} |
|
|
|
special = jQuery.event.special[ type ] || {}; |
|
type = ( selector ? special.delegateType : special.bindType ) || type; |
|
handlers = events[ type ] || []; |
|
tmp = tmp[ 2 ] && |
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ); |
|
|
|
|
|
origCount = j = handlers.length; |
|
while ( j-- ) { |
|
handleObj = handlers[ j ]; |
|
|
|
if ( ( mappedTypes || origType === handleObj.origType ) && |
|
( !handler || handler.guid === handleObj.guid ) && |
|
( !tmp || tmp.test( handleObj.namespace ) ) && |
|
( !selector || selector === handleObj.selector || |
|
selector === "**" && handleObj.selector ) ) { |
|
handlers.splice( j, 1 ); |
|
|
|
if ( handleObj.selector ) { |
|
handlers.delegateCount--; |
|
} |
|
if ( special.remove ) { |
|
special.remove.call( elem, handleObj ); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
if ( origCount && !handlers.length ) { |
|
if ( !special.teardown || |
|
special.teardown.call( elem, namespaces, elemData.handle ) === false ) { |
|
|
|
jQuery.removeEvent( elem, type, elemData.handle ); |
|
} |
|
|
|
delete events[ type ]; |
|
} |
|
} |
|
|
|
|
|
if ( jQuery.isEmptyObject( events ) ) { |
|
dataPriv.remove( elem, "handle events" ); |
|
} |
|
}, |
|
|
|
dispatch: function( event ) { |
|
|
|
|
|
event = jQuery.event.fix( event ); |
|
|
|
var i, j, ret, matched, handleObj, |
|
handlerQueue = [], |
|
args = slice.call( arguments ), |
|
handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [], |
|
special = jQuery.event.special[ event.type ] || {}; |
|
|
|
|
|
args[ 0 ] = event; |
|
event.delegateTarget = this; |
|
|
|
|
|
if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { |
|
return; |
|
} |
|
|
|
|
|
handlerQueue = jQuery.event.handlers.call( this, event, handlers ); |
|
|
|
|
|
i = 0; |
|
while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) { |
|
event.currentTarget = matched.elem; |
|
|
|
j = 0; |
|
while ( ( handleObj = matched.handlers[ j++ ] ) && |
|
!event.isImmediatePropagationStopped() ) { |
|
|
|
|
|
|
|
if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) { |
|
|
|
event.handleObj = handleObj; |
|
event.data = handleObj.data; |
|
|
|
ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle || |
|
handleObj.handler ).apply( matched.elem, args ); |
|
|
|
if ( ret !== undefined ) { |
|
if ( ( event.result = ret ) === false ) { |
|
event.preventDefault(); |
|
event.stopPropagation(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
if ( special.postDispatch ) { |
|
special.postDispatch.call( this, event ); |
|
} |
|
|
|
return event.result; |
|
}, |
|
|
|
handlers: function( event, handlers ) { |
|
var i, matches, sel, handleObj, |
|
handlerQueue = [], |
|
delegateCount = handlers.delegateCount, |
|
cur = event.target; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( delegateCount && cur.nodeType && |
|
( event.type !== "click" || isNaN( event.button ) || event.button < 1 ) ) { |
|
|
|
for ( ; cur !== this; cur = cur.parentNode || this ) { |
|
|
|
|
|
|
|
if ( cur.nodeType === 1 && ( cur.disabled !== true || event.type !== "click" ) ) { |
|
matches = []; |
|
for ( i = 0; i < delegateCount; i++ ) { |
|
handleObj = handlers[ i ]; |
|
|
|
|
|
sel = handleObj.selector + " "; |
|
|
|
if ( matches[ sel ] === undefined ) { |
|
matches[ sel ] = handleObj.needsContext ? |
|
jQuery( sel, this ).index( cur ) > -1 : |
|
jQuery.find( sel, this, null, [ cur ] ).length; |
|
} |
|
if ( matches[ sel ] ) { |
|
matches.push( handleObj ); |
|
} |
|
} |
|
if ( matches.length ) { |
|
handlerQueue.push( { elem: cur, handlers: matches } ); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
if ( delegateCount < handlers.length ) { |
|
handlerQueue.push( { elem: this, handlers: handlers.slice( delegateCount ) } ); |
|
} |
|
|
|
return handlerQueue; |
|
}, |
|
|
|
|
|
props: ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " + |
|
"metaKey relatedTarget shiftKey target timeStamp view which" ).split( " " ), |
|
|
|
fixHooks: {}, |
|
|
|
keyHooks: { |
|
props: "char charCode key keyCode".split( " " ), |
|
filter: function( event, original ) { |
|
|
|
|
|
if ( event.which == null ) { |
|
event.which = original.charCode != null ? original.charCode : original.keyCode; |
|
} |
|
|
|
return event; |
|
} |
|
}, |
|
|
|
mouseHooks: { |
|
props: ( "button buttons clientX clientY offsetX offsetY pageX pageY " + |
|
"screenX screenY toElement" ).split( " " ), |
|
filter: function( event, original ) { |
|
var eventDoc, doc, body, |
|
button = original.button; |
|
|
|
|
|
if ( event.pageX == null && original.clientX != null ) { |
|
eventDoc = event.target.ownerDocument || document; |
|
doc = eventDoc.documentElement; |
|
body = eventDoc.body; |
|
|
|
event.pageX = original.clientX + |
|
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - |
|
( doc && doc.clientLeft || body && body.clientLeft || 0 ); |
|
event.pageY = original.clientY + |
|
( doc && doc.scrollTop || body && body.scrollTop || 0 ) - |
|
( doc && doc.clientTop || body && body.clientTop || 0 ); |
|
} |
|
|
|
|
|
|
|
if ( !event.which && button !== undefined ) { |
|
event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); |
|
} |
|
|
|
return event; |
|
} |
|
}, |
|
|
|
fix: function( event ) { |
|
if ( event[ jQuery.expando ] ) { |
|
return event; |
|
} |
|
|
|
|
|
var i, prop, copy, |
|
type = event.type, |
|
originalEvent = event, |
|
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 ); |
|
|
|
i = copy.length; |
|
while ( i-- ) { |
|
prop = copy[ i ]; |
|
event[ prop ] = originalEvent[ prop ]; |
|
} |
|
|
|
|
|
|
|
if ( !event.target ) { |
|
event.target = document; |
|
} |
|
|
|
|
|
|
|
if ( event.target.nodeType === 3 ) { |
|
event.target = event.target.parentNode; |
|
} |
|
|
|
return fixHook.filter ? fixHook.filter( event, originalEvent ) : event; |
|
}, |
|
|
|
special: { |
|
load: { |
|
|
|
|
|
noBubble: true |
|
}, |
|
focus: { |
|
|
|
|
|
trigger: function() { |
|
if ( this !== safeActiveElement() && this.focus ) { |
|
this.focus(); |
|
return false; |
|
} |
|
}, |
|
delegateType: "focusin" |
|
}, |
|
blur: { |
|
trigger: function() { |
|
if ( this === safeActiveElement() && this.blur ) { |
|
this.blur(); |
|
return false; |
|
} |
|
}, |
|
delegateType: "focusout" |
|
}, |
|
click: { |
|
|
|
|
|
trigger: function() { |
|
if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) { |
|
this.click(); |
|
return false; |
|
} |
|
}, |
|
|
|
|
|
_default: function( event ) { |
|
return jQuery.nodeName( event.target, "a" ); |
|
} |
|
}, |
|
|
|
beforeunload: { |
|
postDispatch: function( event ) { |
|
|
|
|
|
|
|
if ( event.result !== undefined && event.originalEvent ) { |
|
event.originalEvent.returnValue = event.result; |
|
} |
|
} |
|
} |
|
} |
|
}; |
|
|
|
jQuery.removeEvent = function( elem, type, handle ) { |
|
|
|
|
|
if ( elem.removeEventListener ) { |
|
elem.removeEventListener( type, handle ); |
|
} |
|
}; |
|
|
|
jQuery.Event = function( src, props ) { |
|
|
|
|
|
if ( !( this instanceof jQuery.Event ) ) { |
|
return new jQuery.Event( src, props ); |
|
} |
|
|
|
|
|
if ( src && src.type ) { |
|
this.originalEvent = src; |
|
this.type = src.type; |
|
|
|
|
|
|
|
this.isDefaultPrevented = src.defaultPrevented || |
|
src.defaultPrevented === undefined && |
|
|
|
|
|
src.returnValue === false ? |
|
returnTrue : |
|
returnFalse; |
|
|
|
|
|
} else { |
|
this.type = src; |
|
} |
|
|
|
|
|
if ( props ) { |
|
jQuery.extend( this, props ); |
|
} |
|
|
|
|
|
this.timeStamp = src && src.timeStamp || jQuery.now(); |
|
|
|
|
|
this[ jQuery.expando ] = true; |
|
}; |
|
|
|
|
|
|
|
jQuery.Event.prototype = { |
|
constructor: jQuery.Event, |
|
isDefaultPrevented: returnFalse, |
|
isPropagationStopped: returnFalse, |
|
isImmediatePropagationStopped: returnFalse, |
|
|
|
preventDefault: function() { |
|
var e = this.originalEvent; |
|
|
|
this.isDefaultPrevented = returnTrue; |
|
|
|
if ( e ) { |
|
e.preventDefault(); |
|
} |
|
}, |
|
stopPropagation: function() { |
|
var e = this.originalEvent; |
|
|
|
this.isPropagationStopped = returnTrue; |
|
|
|
if ( e ) { |
|
e.stopPropagation(); |
|
} |
|
}, |
|
stopImmediatePropagation: function() { |
|
var e = this.originalEvent; |
|
|
|
this.isImmediatePropagationStopped = returnTrue; |
|
|
|
if ( e ) { |
|
e.stopImmediatePropagation(); |
|
} |
|
|
|
this.stopPropagation(); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jQuery.each( { |
|
mouseenter: "mouseover", |
|
mouseleave: "mouseout", |
|
pointerenter: "pointerover", |
|
pointerleave: "pointerout" |
|
}, function( orig, fix ) { |
|
jQuery.event.special[ orig ] = { |
|
delegateType: fix, |
|
bindType: fix, |
|
|
|
handle: function( event ) { |
|
var ret, |
|
target = this, |
|
related = event.relatedTarget, |
|
handleObj = event.handleObj; |
|
|
|
|
|
|
|
if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) { |
|
event.type = handleObj.origType; |
|
ret = handleObj.handler.apply( this, arguments ); |
|
event.type = fix; |
|
} |
|
return ret; |
|
} |
|
}; |
|
} ); |
|
|
|
jQuery.fn.extend( { |
|
on: function( types, selector, data, fn ) { |
|
return on( this, types, selector, data, fn ); |
|
}, |
|
one: function( types, selector, data, fn ) { |
|
return on( this, types, selector, data, fn, 1 ); |
|
}, |
|
off: function( types, selector, fn ) { |
|
var handleObj, type; |
|
if ( types && types.preventDefault && types.handleObj ) { |
|
|
|
|
|
handleObj = types.handleObj; |
|
jQuery( types.delegateTarget ).off( |
|
handleObj.namespace ? |
|
handleObj.origType + "." + handleObj.namespace : |
|
handleObj.origType, |
|
handleObj.selector, |
|
handleObj.handler |
|
); |
|
return this; |
|
} |
|
if ( typeof types === "object" ) { |
|
|
|
|
|
for ( type in types ) { |
|
this.off( type, selector, types[ type ] ); |
|
} |
|
return this; |
|
} |
|
if ( selector === false || typeof selector === "function" ) { |
|
|
|
|
|
fn = selector; |
|
selector = undefined; |
|
} |
|
if ( fn === false ) { |
|
fn = returnFalse; |
|
} |
|
return this.each( function() { |
|
jQuery.event.remove( this, types, fn, selector ); |
|
} ); |
|
} |
|
} ); |
|
|
|
return jQuery; |
|
} ); |
|
|