Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

event.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. define( [
  2. "./core",
  3. "./var/document",
  4. "./var/documentElement",
  5. "./var/isFunction",
  6. "./var/rnothtmlwhite",
  7. "./var/rcheckableType",
  8. "./var/slice",
  9. "./data/var/dataPriv",
  10. "./core/nodeName",
  11. "./core/init",
  12. "./selector"
  13. ], function( jQuery, document, documentElement, isFunction, rnothtmlwhite,
  14. rcheckableType, slice, dataPriv, nodeName ) {
  15. "use strict";
  16. var
  17. rkeyEvent = /^key/,
  18. rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,
  19. rtypenamespace = /^([^.]*)(?:\.(.+)|)/;
  20. function returnTrue() {
  21. return true;
  22. }
  23. function returnFalse() {
  24. return false;
  25. }
  26. // Support: IE <=9 - 11+
  27. // focus() and blur() are asynchronous, except when they are no-op.
  28. // So expect focus to be synchronous when the element is already active,
  29. // and blur to be synchronous when the element is not already active.
  30. // (focus and blur are always synchronous in other supported browsers,
  31. // this just defines when we can count on it).
  32. function expectSync( elem, type ) {
  33. return ( elem === safeActiveElement() ) === ( type === "focus" );
  34. }
  35. // Support: IE <=9 only
  36. // Accessing document.activeElement can throw unexpectedly
  37. // https://bugs.jquery.com/ticket/13393
  38. function safeActiveElement() {
  39. try {
  40. return document.activeElement;
  41. } catch ( err ) { }
  42. }
  43. function on( elem, types, selector, data, fn, one ) {
  44. var origFn, type;
  45. // Types can be a map of types/handlers
  46. if ( typeof types === "object" ) {
  47. // ( types-Object, selector, data )
  48. if ( typeof selector !== "string" ) {
  49. // ( types-Object, data )
  50. data = data || selector;
  51. selector = undefined;
  52. }
  53. for ( type in types ) {
  54. on( elem, type, selector, data, types[ type ], one );
  55. }
  56. return elem;
  57. }
  58. if ( data == null && fn == null ) {
  59. // ( types, fn )
  60. fn = selector;
  61. data = selector = undefined;
  62. } else if ( fn == null ) {
  63. if ( typeof selector === "string" ) {
  64. // ( types, selector, fn )
  65. fn = data;
  66. data = undefined;
  67. } else {
  68. // ( types, data, fn )
  69. fn = data;
  70. data = selector;
  71. selector = undefined;
  72. }
  73. }
  74. if ( fn === false ) {
  75. fn = returnFalse;
  76. } else if ( !fn ) {
  77. return elem;
  78. }
  79. if ( one === 1 ) {
  80. origFn = fn;
  81. fn = function( event ) {
  82. // Can use an empty set, since event contains the info
  83. jQuery().off( event );
  84. return origFn.apply( this, arguments );
  85. };
  86. // Use same guid so caller can remove using origFn
  87. fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
  88. }
  89. return elem.each( function() {
  90. jQuery.event.add( this, types, fn, data, selector );
  91. } );
  92. }
  93. /*
  94. * Helper functions for managing events -- not part of the public interface.
  95. * Props to Dean Edwards' addEvent library for many of the ideas.
  96. */
  97. jQuery.event = {
  98. global: {},
  99. add: function( elem, types, handler, data, selector ) {
  100. var handleObjIn, eventHandle, tmp,
  101. events, t, handleObj,
  102. special, handlers, type, namespaces, origType,
  103. elemData = dataPriv.get( elem );
  104. // Don't attach events to noData or text/comment nodes (but allow plain objects)
  105. if ( !elemData ) {
  106. return;
  107. }
  108. // Caller can pass in an object of custom data in lieu of the handler
  109. if ( handler.handler ) {
  110. handleObjIn = handler;
  111. handler = handleObjIn.handler;
  112. selector = handleObjIn.selector;
  113. }
  114. // Ensure that invalid selectors throw exceptions at attach time
  115. // Evaluate against documentElement in case elem is a non-element node (e.g., document)
  116. if ( selector ) {
  117. jQuery.find.matchesSelector( documentElement, selector );
  118. }
  119. // Make sure that the handler has a unique ID, used to find/remove it later
  120. if ( !handler.guid ) {
  121. handler.guid = jQuery.guid++;
  122. }
  123. // Init the element's event structure and main handler, if this is the first
  124. if ( !( events = elemData.events ) ) {
  125. events = elemData.events = {};
  126. }
  127. if ( !( eventHandle = elemData.handle ) ) {
  128. eventHandle = elemData.handle = function( e ) {
  129. // Discard the second event of a jQuery.event.trigger() and
  130. // when an event is called after a page has unloaded
  131. return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
  132. jQuery.event.dispatch.apply( elem, arguments ) : undefined;
  133. };
  134. }
  135. // Handle multiple events separated by a space
  136. types = ( types || "" ).match( rnothtmlwhite ) || [ "" ];
  137. t = types.length;
  138. while ( t-- ) {
  139. tmp = rtypenamespace.exec( types[ t ] ) || [];
  140. type = origType = tmp[ 1 ];
  141. namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
  142. // There *must* be a type, no attaching namespace-only handlers
  143. if ( !type ) {
  144. continue;
  145. }
  146. // If event changes its type, use the special event handlers for the changed type
  147. special = jQuery.event.special[ type ] || {};
  148. // If selector defined, determine special event api type, otherwise given type
  149. type = ( selector ? special.delegateType : special.bindType ) || type;
  150. // Update special based on newly reset type
  151. special = jQuery.event.special[ type ] || {};
  152. // handleObj is passed to all event handlers
  153. handleObj = jQuery.extend( {
  154. type: type,
  155. origType: origType,
  156. data: data,
  157. handler: handler,
  158. guid: handler.guid,
  159. selector: selector,
  160. needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
  161. namespace: namespaces.join( "." )
  162. }, handleObjIn );
  163. // Init the event handler queue if we're the first
  164. if ( !( handlers = events[ type ] ) ) {
  165. handlers = events[ type ] = [];
  166. handlers.delegateCount = 0;
  167. // Only use addEventListener if the special events handler returns false
  168. if ( !special.setup ||
  169. special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
  170. if ( elem.addEventListener ) {
  171. elem.addEventListener( type, eventHandle );
  172. }
  173. }
  174. }
  175. if ( special.add ) {
  176. special.add.call( elem, handleObj );
  177. if ( !handleObj.handler.guid ) {
  178. handleObj.handler.guid = handler.guid;
  179. }
  180. }
  181. // Add to the element's handler list, delegates in front
  182. if ( selector ) {
  183. handlers.splice( handlers.delegateCount++, 0, handleObj );
  184. } else {
  185. handlers.push( handleObj );
  186. }
  187. // Keep track of which events have ever been used, for event optimization
  188. jQuery.event.global[ type ] = true;
  189. }
  190. },
  191. // Detach an event or set of events from an element
  192. remove: function( elem, types, handler, selector, mappedTypes ) {
  193. var j, origCount, tmp,
  194. events, t, handleObj,
  195. special, handlers, type, namespaces, origType,
  196. elemData = dataPriv.hasData( elem ) && dataPriv.get( elem );
  197. if ( !elemData || !( events = elemData.events ) ) {
  198. return;
  199. }
  200. // Once for each type.namespace in types; type may be omitted
  201. types = ( types || "" ).match( rnothtmlwhite ) || [ "" ];
  202. t = types.length;
  203. while ( t-- ) {
  204. tmp = rtypenamespace.exec( types[ t ] ) || [];
  205. type = origType = tmp[ 1 ];
  206. namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
  207. // Unbind all events (on this namespace, if provided) for the element
  208. if ( !type ) {
  209. for ( type in events ) {
  210. jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
  211. }
  212. continue;
  213. }
  214. special = jQuery.event.special[ type ] || {};
  215. type = ( selector ? special.delegateType : special.bindType ) || type;
  216. handlers = events[ type ] || [];
  217. tmp = tmp[ 2 ] &&
  218. new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" );
  219. // Remove matching events
  220. origCount = j = handlers.length;
  221. while ( j-- ) {
  222. handleObj = handlers[ j ];
  223. if ( ( mappedTypes || origType === handleObj.origType ) &&
  224. ( !handler || handler.guid === handleObj.guid ) &&
  225. ( !tmp || tmp.test( handleObj.namespace ) ) &&
  226. ( !selector || selector === handleObj.selector ||
  227. selector === "**" && handleObj.selector ) ) {
  228. handlers.splice( j, 1 );
  229. if ( handleObj.selector ) {
  230. handlers.delegateCount--;
  231. }
  232. if ( special.remove ) {
  233. special.remove.call( elem, handleObj );
  234. }
  235. }
  236. }
  237. // Remove generic event handler if we removed something and no more handlers exist
  238. // (avoids potential for endless recursion during removal of special event handlers)
  239. if ( origCount && !handlers.length ) {
  240. if ( !special.teardown ||
  241. special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
  242. jQuery.removeEvent( elem, type, elemData.handle );
  243. }
  244. delete events[ type ];
  245. }
  246. }
  247. // Remove data and the expando if it's no longer used
  248. if ( jQuery.isEmptyObject( events ) ) {
  249. dataPriv.remove( elem, "handle events" );
  250. }
  251. },
  252. dispatch: function( nativeEvent ) {
  253. // Make a writable jQuery.Event from the native event object
  254. var event = jQuery.event.fix( nativeEvent );
  255. var i, j, ret, matched, handleObj, handlerQueue,
  256. args = new Array( arguments.length ),
  257. handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [],
  258. special = jQuery.event.special[ event.type ] || {};
  259. // Use the fix-ed jQuery.Event rather than the (read-only) native event
  260. args[ 0 ] = event;
  261. for ( i = 1; i < arguments.length; i++ ) {
  262. args[ i ] = arguments[ i ];
  263. }
  264. event.delegateTarget = this;
  265. // Call the preDispatch hook for the mapped type, and let it bail if desired
  266. if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
  267. return;
  268. }
  269. // Determine handlers
  270. handlerQueue = jQuery.event.handlers.call( this, event, handlers );
  271. // Run delegates first; they may want to stop propagation beneath us
  272. i = 0;
  273. while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) {
  274. event.currentTarget = matched.elem;
  275. j = 0;
  276. while ( ( handleObj = matched.handlers[ j++ ] ) &&
  277. !event.isImmediatePropagationStopped() ) {
  278. // If the event is namespaced, then each handler is only invoked if it is
  279. // specially universal or its namespaces are a superset of the event's.
  280. if ( !event.rnamespace || handleObj.namespace === false ||
  281. event.rnamespace.test( handleObj.namespace ) ) {
  282. event.handleObj = handleObj;
  283. event.data = handleObj.data;
  284. ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
  285. handleObj.handler ).apply( matched.elem, args );
  286. if ( ret !== undefined ) {
  287. if ( ( event.result = ret ) === false ) {
  288. event.preventDefault();
  289. event.stopPropagation();
  290. }
  291. }
  292. }
  293. }
  294. }
  295. // Call the postDispatch hook for the mapped type
  296. if ( special.postDispatch ) {
  297. special.postDispatch.call( this, event );
  298. }
  299. return event.result;
  300. },
  301. handlers: function( event, handlers ) {
  302. var i, handleObj, sel, matchedHandlers, matchedSelectors,
  303. handlerQueue = [],
  304. delegateCount = handlers.delegateCount,
  305. cur = event.target;
  306. // Find delegate handlers
  307. if ( delegateCount &&
  308. // Support: IE <=9
  309. // Black-hole SVG <use> instance trees (trac-13180)
  310. cur.nodeType &&
  311. // Support: Firefox <=42
  312. // Suppress spec-violating clicks indicating a non-primary pointer button (trac-3861)
  313. // https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click
  314. // Support: IE 11 only
  315. // ...but not arrow key "clicks" of radio inputs, which can have `button` -1 (gh-2343)
  316. !( event.type === "click" && event.button >= 1 ) ) {
  317. for ( ; cur !== this; cur = cur.parentNode || this ) {
  318. // Don't check non-elements (#13208)
  319. // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
  320. if ( cur.nodeType === 1 && !( event.type === "click" && cur.disabled === true ) ) {
  321. matchedHandlers = [];
  322. matchedSelectors = {};
  323. for ( i = 0; i < delegateCount; i++ ) {
  324. handleObj = handlers[ i ];
  325. // Don't conflict with Object.prototype properties (#13203)
  326. sel = handleObj.selector + " ";
  327. if ( matchedSelectors[ sel ] === undefined ) {
  328. matchedSelectors[ sel ] = handleObj.needsContext ?
  329. jQuery( sel, this ).index( cur ) > -1 :
  330. jQuery.find( sel, this, null, [ cur ] ).length;
  331. }
  332. if ( matchedSelectors[ sel ] ) {
  333. matchedHandlers.push( handleObj );
  334. }
  335. }
  336. if ( matchedHandlers.length ) {
  337. handlerQueue.push( { elem: cur, handlers: matchedHandlers } );
  338. }
  339. }
  340. }
  341. }
  342. // Add the remaining (directly-bound) handlers
  343. cur = this;
  344. if ( delegateCount < handlers.length ) {
  345. handlerQueue.push( { elem: cur, handlers: handlers.slice( delegateCount ) } );
  346. }
  347. return handlerQueue;
  348. },
  349. addProp: function( name, hook ) {
  350. Object.defineProperty( jQuery.Event.prototype, name, {
  351. enumerable: true,
  352. configurable: true,
  353. get: isFunction( hook ) ?
  354. function() {
  355. if ( this.originalEvent ) {
  356. return hook( this.originalEvent );
  357. }
  358. } :
  359. function() {
  360. if ( this.originalEvent ) {
  361. return this.originalEvent[ name ];
  362. }
  363. },
  364. set: function( value ) {
  365. Object.defineProperty( this, name, {
  366. enumerable: true,
  367. configurable: true,
  368. writable: true,
  369. value: value
  370. } );
  371. }
  372. } );
  373. },
  374. fix: function( originalEvent ) {
  375. return originalEvent[ jQuery.expando ] ?
  376. originalEvent :
  377. new jQuery.Event( originalEvent );
  378. },
  379. special: {
  380. load: {
  381. // Prevent triggered image.load events from bubbling to window.load
  382. noBubble: true
  383. },
  384. click: {
  385. // Utilize native event to ensure correct state for checkable inputs
  386. setup: function( data ) {
  387. // For mutual compressibility with _default, replace `this` access with a local var.
  388. // `|| data` is dead code meant only to preserve the variable through minification.
  389. var el = this || data;
  390. // Claim the first handler
  391. if ( rcheckableType.test( el.type ) &&
  392. el.click && nodeName( el, "input" ) ) {
  393. // dataPriv.set( el, "click", ... )
  394. leverageNative( el, "click", returnTrue );
  395. }
  396. // Return false to allow normal processing in the caller
  397. return false;
  398. },
  399. trigger: function( data ) {
  400. // For mutual compressibility with _default, replace `this` access with a local var.
  401. // `|| data` is dead code meant only to preserve the variable through minification.
  402. var el = this || data;
  403. // Force setup before triggering a click
  404. if ( rcheckableType.test( el.type ) &&
  405. el.click && nodeName( el, "input" ) ) {
  406. leverageNative( el, "click" );
  407. }
  408. // Return non-false to allow normal event-path propagation
  409. return true;
  410. },
  411. // For cross-browser consistency, suppress native .click() on links
  412. // Also prevent it if we're currently inside a leveraged native-event stack
  413. _default: function( event ) {
  414. var target = event.target;
  415. return rcheckableType.test( target.type ) &&
  416. target.click && nodeName( target, "input" ) &&
  417. dataPriv.get( target, "click" ) ||
  418. nodeName( target, "a" );
  419. }
  420. },
  421. beforeunload: {
  422. postDispatch: function( event ) {
  423. // Support: Firefox 20+
  424. // Firefox doesn't alert if the returnValue field is not set.
  425. if ( event.result !== undefined && event.originalEvent ) {
  426. event.originalEvent.returnValue = event.result;
  427. }
  428. }
  429. }
  430. }
  431. };
  432. // Ensure the presence of an event listener that handles manually-triggered
  433. // synthetic events by interrupting progress until reinvoked in response to
  434. // *native* events that it fires directly, ensuring that state changes have
  435. // already occurred before other listeners are invoked.
  436. function leverageNative( el, type, expectSync ) {
  437. // Missing expectSync indicates a trigger call, which must force setup through jQuery.event.add
  438. if ( !expectSync ) {
  439. if ( dataPriv.get( el, type ) === undefined ) {
  440. jQuery.event.add( el, type, returnTrue );
  441. }
  442. return;
  443. }
  444. // Register the controller as a special universal handler for all event namespaces
  445. dataPriv.set( el, type, false );
  446. jQuery.event.add( el, type, {
  447. namespace: false,
  448. handler: function( event ) {
  449. var notAsync, result,
  450. saved = dataPriv.get( this, type );
  451. if ( ( event.isTrigger & 1 ) && this[ type ] ) {
  452. // Interrupt processing of the outer synthetic .trigger()ed event
  453. // Saved data should be false in such cases, but might be a leftover capture object
  454. // from an async native handler (gh-4350)
  455. if ( !saved.length ) {
  456. // Store arguments for use when handling the inner native event
  457. // There will always be at least one argument (an event object), so this array
  458. // will not be confused with a leftover capture object.
  459. saved = slice.call( arguments );
  460. dataPriv.set( this, type, saved );
  461. // Trigger the native event and capture its result
  462. // Support: IE <=9 - 11+
  463. // focus() and blur() are asynchronous
  464. notAsync = expectSync( this, type );
  465. this[ type ]();
  466. result = dataPriv.get( this, type );
  467. if ( saved !== result || notAsync ) {
  468. dataPriv.set( this, type, false );
  469. } else {
  470. result = {};
  471. }
  472. if ( saved !== result ) {
  473. // Cancel the outer synthetic event
  474. event.stopImmediatePropagation();
  475. event.preventDefault();
  476. return result.value;
  477. }
  478. // If this is an inner synthetic event for an event with a bubbling surrogate
  479. // (focus or blur), assume that the surrogate already propagated from triggering the
  480. // native event and prevent that from happening again here.
  481. // This technically gets the ordering wrong w.r.t. to `.trigger()` (in which the
  482. // bubbling surrogate propagates *after* the non-bubbling base), but that seems
  483. // less bad than duplication.
  484. } else if ( ( jQuery.event.special[ type ] || {} ).delegateType ) {
  485. event.stopPropagation();
  486. }
  487. // If this is a native event triggered above, everything is now in order
  488. // Fire an inner synthetic event with the original arguments
  489. } else if ( saved.length ) {
  490. // ...and capture the result
  491. dataPriv.set( this, type, {
  492. value: jQuery.event.trigger(
  493. // Support: IE <=9 - 11+
  494. // Extend with the prototype to reset the above stopImmediatePropagation()
  495. jQuery.extend( saved[ 0 ], jQuery.Event.prototype ),
  496. saved.slice( 1 ),
  497. this
  498. )
  499. } );
  500. // Abort handling of the native event
  501. event.stopImmediatePropagation();
  502. }
  503. }
  504. } );
  505. }
  506. jQuery.removeEvent = function( elem, type, handle ) {
  507. // This "if" is needed for plain objects
  508. if ( elem.removeEventListener ) {
  509. elem.removeEventListener( type, handle );
  510. }
  511. };
  512. jQuery.Event = function( src, props ) {
  513. // Allow instantiation without the 'new' keyword
  514. if ( !( this instanceof jQuery.Event ) ) {
  515. return new jQuery.Event( src, props );
  516. }
  517. // Event object
  518. if ( src && src.type ) {
  519. this.originalEvent = src;
  520. this.type = src.type;
  521. // Events bubbling up the document may have been marked as prevented
  522. // by a handler lower down the tree; reflect the correct value.
  523. this.isDefaultPrevented = src.defaultPrevented ||
  524. src.defaultPrevented === undefined &&
  525. // Support: Android <=2.3 only
  526. src.returnValue === false ?
  527. returnTrue :
  528. returnFalse;
  529. // Create target properties
  530. // Support: Safari <=6 - 7 only
  531. // Target should not be a text node (#504, #13143)
  532. this.target = ( src.target && src.target.nodeType === 3 ) ?
  533. src.target.parentNode :
  534. src.target;
  535. this.currentTarget = src.currentTarget;
  536. this.relatedTarget = src.relatedTarget;
  537. // Event type
  538. } else {
  539. this.type = src;
  540. }
  541. // Put explicitly provided properties onto the event object
  542. if ( props ) {
  543. jQuery.extend( this, props );
  544. }
  545. // Create a timestamp if incoming event doesn't have one
  546. this.timeStamp = src && src.timeStamp || Date.now();
  547. // Mark it as fixed
  548. this[ jQuery.expando ] = true;
  549. };
  550. // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
  551. // https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
  552. jQuery.Event.prototype = {
  553. constructor: jQuery.Event,
  554. isDefaultPrevented: returnFalse,
  555. isPropagationStopped: returnFalse,
  556. isImmediatePropagationStopped: returnFalse,
  557. isSimulated: false,
  558. preventDefault: function() {
  559. var e = this.originalEvent;
  560. this.isDefaultPrevented = returnTrue;
  561. if ( e && !this.isSimulated ) {
  562. e.preventDefault();
  563. }
  564. },
  565. stopPropagation: function() {
  566. var e = this.originalEvent;
  567. this.isPropagationStopped = returnTrue;
  568. if ( e && !this.isSimulated ) {
  569. e.stopPropagation();
  570. }
  571. },
  572. stopImmediatePropagation: function() {
  573. var e = this.originalEvent;
  574. this.isImmediatePropagationStopped = returnTrue;
  575. if ( e && !this.isSimulated ) {
  576. e.stopImmediatePropagation();
  577. }
  578. this.stopPropagation();
  579. }
  580. };
  581. // Includes all common event props including KeyEvent and MouseEvent specific props
  582. jQuery.each( {
  583. altKey: true,
  584. bubbles: true,
  585. cancelable: true,
  586. changedTouches: true,
  587. ctrlKey: true,
  588. detail: true,
  589. eventPhase: true,
  590. metaKey: true,
  591. pageX: true,
  592. pageY: true,
  593. shiftKey: true,
  594. view: true,
  595. "char": true,
  596. code: true,
  597. charCode: true,
  598. key: true,
  599. keyCode: true,
  600. button: true,
  601. buttons: true,
  602. clientX: true,
  603. clientY: true,
  604. offsetX: true,
  605. offsetY: true,
  606. pointerId: true,
  607. pointerType: true,
  608. screenX: true,
  609. screenY: true,
  610. targetTouches: true,
  611. toElement: true,
  612. touches: true,
  613. which: function( event ) {
  614. var button = event.button;
  615. // Add which for key events
  616. if ( event.which == null && rkeyEvent.test( event.type ) ) {
  617. return event.charCode != null ? event.charCode : event.keyCode;
  618. }
  619. // Add which for click: 1 === left; 2 === middle; 3 === right
  620. if ( !event.which && button !== undefined && rmouseEvent.test( event.type ) ) {
  621. if ( button & 1 ) {
  622. return 1;
  623. }
  624. if ( button & 2 ) {
  625. return 3;
  626. }
  627. if ( button & 4 ) {
  628. return 2;
  629. }
  630. return 0;
  631. }
  632. return event.which;
  633. }
  634. }, jQuery.event.addProp );
  635. jQuery.each( { focus: "focusin", blur: "focusout" }, function( type, delegateType ) {
  636. jQuery.event.special[ type ] = {
  637. // Utilize native event if possible so blur/focus sequence is correct
  638. setup: function() {
  639. // Claim the first handler
  640. // dataPriv.set( this, "focus", ... )
  641. // dataPriv.set( this, "blur", ... )
  642. leverageNative( this, type, expectSync );
  643. // Return false to allow normal processing in the caller
  644. return false;
  645. },
  646. trigger: function() {
  647. // Force setup before trigger
  648. leverageNative( this, type );
  649. // Return non-false to allow normal event-path propagation
  650. return true;
  651. },
  652. delegateType: delegateType
  653. };
  654. } );
  655. // Create mouseenter/leave events using mouseover/out and event-time checks
  656. // so that event delegation works in jQuery.
  657. // Do the same for pointerenter/pointerleave and pointerover/pointerout
  658. //
  659. // Support: Safari 7 only
  660. // Safari sends mouseenter too often; see:
  661. // https://bugs.chromium.org/p/chromium/issues/detail?id=470258
  662. // for the description of the bug (it existed in older Chrome versions as well).
  663. jQuery.each( {
  664. mouseenter: "mouseover",
  665. mouseleave: "mouseout",
  666. pointerenter: "pointerover",
  667. pointerleave: "pointerout"
  668. }, function( orig, fix ) {
  669. jQuery.event.special[ orig ] = {
  670. delegateType: fix,
  671. bindType: fix,
  672. handle: function( event ) {
  673. var ret,
  674. target = this,
  675. related = event.relatedTarget,
  676. handleObj = event.handleObj;
  677. // For mouseenter/leave call the handler if related is outside the target.
  678. // NB: No relatedTarget if the mouse left/entered the browser window
  679. if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) {
  680. event.type = handleObj.origType;
  681. ret = handleObj.handler.apply( this, arguments );
  682. event.type = fix;
  683. }
  684. return ret;
  685. }
  686. };
  687. } );
  688. jQuery.fn.extend( {
  689. on: function( types, selector, data, fn ) {
  690. return on( this, types, selector, data, fn );
  691. },
  692. one: function( types, selector, data, fn ) {
  693. return on( this, types, selector, data, fn, 1 );
  694. },
  695. off: function( types, selector, fn ) {
  696. var handleObj, type;
  697. if ( types && types.preventDefault && types.handleObj ) {
  698. // ( event ) dispatched jQuery.Event
  699. handleObj = types.handleObj;
  700. jQuery( types.delegateTarget ).off(
  701. handleObj.namespace ?
  702. handleObj.origType + "." + handleObj.namespace :
  703. handleObj.origType,
  704. handleObj.selector,
  705. handleObj.handler
  706. );
  707. return this;
  708. }
  709. if ( typeof types === "object" ) {
  710. // ( types-object [, selector] )
  711. for ( type in types ) {
  712. this.off( type, selector, types[ type ] );
  713. }
  714. return this;
  715. }
  716. if ( selector === false || typeof selector === "function" ) {
  717. // ( types [, fn] )
  718. fn = selector;
  719. selector = undefined;
  720. }
  721. if ( fn === false ) {
  722. fn = returnFalse;
  723. }
  724. return this.each( function() {
  725. jQuery.event.remove( this, types, fn, selector );
  726. } );
  727. }
  728. } );
  729. return jQuery;
  730. } );