blob: 3da86c7871d80c5f48032a9d11e119d2c31df2c8 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001define( [
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
20if ( !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 botf591dcf2023-12-30 14:13:54 +000030
31 // Handle: regular nodes (via `this.ownerDocument`), window
32 // (via `this.document`) & document (via `this`).
33 var doc = this.ownerDocument || this.document || this,
Copybara botbe50d492023-11-30 00:16:42 +010034 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 botf591dcf2023-12-30 14:13:54 +000042 var doc = this.ownerDocument || this.document || this,
Copybara botbe50d492023-11-30 00:16:42 +010043 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
57return jQuery;
58} );