MCPcopy Index your code
hub / github.com/jquery/jquery / leverageNative

Function leverageNative

src/event.js:509–607  ·  view source on GitHub ↗
( el, type, isSetup )

Source from the content-addressed store, hash-verified

507// *native* events that it fires directly, ensuring that state changes have
508// already occurred before other listeners are invoked.
509function leverageNative( el, type, isSetup ) {
510
511 // Missing `isSetup` indicates a trigger call, which must force setup through jQuery.event.add
512 if ( !isSetup ) {
513 if ( dataPriv.get( el, type ) === undefined ) {
514 jQuery.event.add( el, type, returnTrue );
515 }
516 return;
517 }
518
519 // Register the controller as a special universal handler for all event namespaces
520 dataPriv.set( el, type, false );
521 jQuery.event.add( el, type, {
522 namespace: false,
523 handler: function( event ) {
524 var result,
525 saved = dataPriv.get( this, type );
526
527 // This controller function is invoked under multiple circumstances,
528 // differentiated by the stored value in `saved`:
529 // 1. For an outer synthetic `.trigger()`ed event (detected by
530 // `event.isTrigger & 1` and non-array `saved`), it records arguments
531 // as an array and fires an [inner] native event to prompt state
532 // changes that should be observed by registered listeners (such as
533 // checkbox toggling and focus updating), then clears the stored value.
534 // 2. For an [inner] native event (detected by `saved` being
535 // an array), it triggers an inner synthetic event, records the
536 // result, and preempts propagation to further jQuery listeners.
537 // 3. For an inner synthetic event (detected by `event.isTrigger & 1` and
538 // array `saved`), it prevents double-propagation of surrogate events
539 // but otherwise allows everything to proceed (particularly including
540 // further listeners).
541 // Possible `saved` data shapes: `[...], `{ value }`, `false`.
542 if ( ( event.isTrigger & 1 ) && this[ type ] ) {
543
544 // Interrupt processing of the outer synthetic .trigger()ed event
545 if ( !saved.length ) {
546
547 // Store arguments for use when handling the inner native event
548 // There will always be at least one argument (an event object),
549 // so this array will not be confused with a leftover capture object.
550 saved = slice.call( arguments );
551 dataPriv.set( this, type, saved );
552
553 // Trigger the native event and capture its result
554 this[ type ]();
555 result = dataPriv.get( this, type );
556 dataPriv.set( this, type, false );
557
558 if ( saved !== result ) {
559
560 // Cancel the outer synthetic event
561 event.stopImmediatePropagation();
562 event.preventDefault();
563
564 // Support: Chrome 86+
565 // In Chrome, if an element having a focusout handler is
566 // blurred by clicking outside of it, it invokes the handler

Callers 1

event.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected