Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | define( [ |
| 2 | "../core", |
| 3 | "../data/var/dataPriv", |
| 4 | "./support", |
| 5 | |
| 6 | "../event", |
| 7 | "./trigger" |
| 8 | ], function( jQuery, dataPriv, support ) { |
| 9 | |
| 10 | "use strict"; |
| 11 | |
| 12 | // Support: Firefox <=44 |
| 13 | // Firefox doesn't have focus(in | out) events |
| 14 | // Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787 |
| 15 | // |
| 16 | // Support: Chrome <=48 - 49, Safari <=9.0 - 9.1 |
| 17 | // focus(in | out) events fire after focus & blur events, |
| 18 | // which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order |
| 19 | // Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857 |
| 20 | if ( !support.focusin ) { |
| 21 | jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) { |
| 22 | |
| 23 | // Attach a single capturing handler on the document while someone wants focusin/focusout |
| 24 | var handler = function( event ) { |
| 25 | jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) ); |
| 26 | }; |
| 27 | |
| 28 | jQuery.event.special[ fix ] = { |
| 29 | setup: function() { |
Renovate bot | f591dcf | 2023-12-30 14:13:54 +0000 | [diff] [blame] | 30 | |
| 31 | // Handle: regular nodes (via `this.ownerDocument`), window |
| 32 | // (via `this.document`) & document (via `this`). |
| 33 | var doc = this.ownerDocument || this.document || this, |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 34 | attaches = dataPriv.access( doc, fix ); |
| 35 | |
| 36 | if ( !attaches ) { |
| 37 | doc.addEventListener( orig, handler, true ); |
| 38 | } |
| 39 | dataPriv.access( doc, fix, ( attaches || 0 ) + 1 ); |
| 40 | }, |
| 41 | teardown: function() { |
Renovate bot | f591dcf | 2023-12-30 14:13:54 +0000 | [diff] [blame] | 42 | var doc = this.ownerDocument || this.document || this, |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 43 | attaches = dataPriv.access( doc, fix ) - 1; |
| 44 | |
| 45 | if ( !attaches ) { |
| 46 | doc.removeEventListener( orig, handler, true ); |
| 47 | dataPriv.remove( doc, fix ); |
| 48 | |
| 49 | } else { |
| 50 | dataPriv.access( doc, fix, attaches ); |
| 51 | } |
| 52 | } |
| 53 | }; |
| 54 | } ); |
| 55 | } |
| 56 | |
| 57 | return jQuery; |
| 58 | } ); |