summaryrefslogtreecommitdiff
path: root/assets/focus-visible/focus-visible.min.js
blob: fd5da23dbfd8e8c9d45112005a7730d457bd4dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
!(function (e, t) {
    'object' == typeof exports && 'undefined' != typeof module
        ? t()
        : 'function' == typeof define && define.amd
        ? define(t)
        : t();
})(0, function () {
    'use strict';
    function e(e) {
        var t = !0,
            n = !1,
            o = null,
            d = {
                text: !0,
                search: !0,
                url: !0,
                tel: !0,
                email: !0,
                password: !0,
                number: !0,
                date: !0,
                month: !0,
                week: !0,
                time: !0,
                datetime: !0,
                'datetime-local': !0,
            };
        function i(e) {
            return !!(
                e &&
                e !== document &&
                'HTML' !== e.nodeName &&
                'BODY' !== e.nodeName &&
                'classList' in e &&
                'contains' in e.classList
            );
        }
        function s(e) {
            e.classList.contains('focus-visible') ||
                (e.classList.add('focus-visible'),
                e.setAttribute('data-focus-visible-added', ''));
        }
        function u(e) {
            t = !1;
        }
        function a() {
            document.addEventListener('mousemove', c),
                document.addEventListener('mousedown', c),
                document.addEventListener('mouseup', c),
                document.addEventListener('pointermove', c),
                document.addEventListener('pointerdown', c),
                document.addEventListener('pointerup', c),
                document.addEventListener('touchmove', c),
                document.addEventListener('touchstart', c),
                document.addEventListener('touchend', c);
        }
        function c(e) {
            (e.target.nodeName && 'html' === e.target.nodeName.toLowerCase()) ||
                ((t = !1),
                document.removeEventListener('mousemove', c),
                document.removeEventListener('mousedown', c),
                document.removeEventListener('mouseup', c),
                document.removeEventListener('pointermove', c),
                document.removeEventListener('pointerdown', c),
                document.removeEventListener('pointerup', c),
                document.removeEventListener('touchmove', c),
                document.removeEventListener('touchstart', c),
                document.removeEventListener('touchend', c));
        }
        document.addEventListener(
            'keydown',
            function (n) {
                n.metaKey ||
                    n.altKey ||
                    n.ctrlKey ||
                    (i(e.activeElement) && s(e.activeElement), (t = !0));
            },
            !0,
        ),
            document.addEventListener('mousedown', u, !0),
            document.addEventListener('pointerdown', u, !0),
            document.addEventListener('touchstart', u, !0),
            document.addEventListener(
                'visibilitychange',
                function (e) {
                    'hidden' === document.visibilityState &&
                        (n && (t = !0), a());
                },
                !0,
            ),
            a(),
            e.addEventListener(
                'focus',
                function (e) {
                    var n, o, u;
                    i(e.target) &&
                        (t ||
                            ((n = e.target),
                            (o = n.type),
                            ('INPUT' === (u = n.tagName) &&
                                d[o] &&
                                !n.readOnly) ||
                                ('TEXTAREA' === u && !n.readOnly) ||
                                n.isContentEditable)) &&
                        s(e.target);
                },
                !0,
            ),
            e.addEventListener(
                'blur',
                function (e) {
                    var t;
                    i(e.target) &&
                        (e.target.classList.contains('focus-visible') ||
                            e.target.hasAttribute(
                                'data-focus-visible-added',
                            )) &&
                        ((n = !0),
                        window.clearTimeout(o),
                        (o = window.setTimeout(function () {
                            n = !1;
                        }, 100)),
                        (t = e.target).hasAttribute(
                            'data-focus-visible-added',
                        ) &&
                            (t.classList.remove('focus-visible'),
                            t.removeAttribute('data-focus-visible-added')));
                },
                !0,
            ),
            e.nodeType === Node.DOCUMENT_FRAGMENT_NODE && e.host
                ? e.host.setAttribute('data-js-focus-visible', '')
                : e.nodeType === Node.DOCUMENT_NODE &&
                  (document.documentElement.classList.add('js-focus-visible'),
                  document.documentElement.setAttribute(
                      'data-js-focus-visible',
                      '',
                  ));
    }
    if ('undefined' != typeof window && 'undefined' != typeof document) {
        var t;
        window.applyFocusVisiblePolyfill = e;
        try {
            t = new CustomEvent('focus-visible-polyfill-ready');
        } catch (e) {
            (t = document.createEvent('CustomEvent')).initCustomEvent(
                'focus-visible-polyfill-ready',
                !1,
                !1,
                {},
            );
        }
        window.dispatchEvent(t);
    }
    'undefined' != typeof document && e(document);
});
//# sourceMappingURL=focus-visible.min.js.map