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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
"use strict";
(self["__WordPressPrivateInteractivityAPI__"] = self["__WordPressPrivateInteractivityAPI__"] || []).push([[3],{
/***/ 932:
/***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
/* harmony import */ var _wordpress_interactivity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(754);
/**
* WordPress dependencies
*/
const focusableSelectors = ['a[href]', 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])', 'select:not([disabled]):not([aria-hidden])', 'textarea:not([disabled]):not([aria-hidden])', 'button:not([disabled]):not([aria-hidden])', '[contenteditable]', '[tabindex]:not([tabindex^="-"])'];
// This is a fix for Safari in iOS/iPadOS. Without it, Safari doesn't focus out
// when the user taps in the body. It can be removed once we add an overlay to
// capture the clicks, instead of relying on the focusout event.
document.addEventListener('click', () => {});
const openMenu = (store, menuOpenedOn) => {
const {
context,
selectors
} = store;
selectors.core.navigation.menuOpenedBy(store)[menuOpenedOn] = true;
if (context.core.navigation.type === 'overlay') {
// Add a `has-modal-open` class to the <html> root.
document.documentElement.classList.add('has-modal-open');
}
};
const closeMenu = (store, menuClosedOn) => {
const {
context,
selectors
} = store;
selectors.core.navigation.menuOpenedBy(store)[menuClosedOn] = false;
// Check if the menu is still open or not.
if (!selectors.core.navigation.isMenuOpen(store)) {
if (context.core.navigation.modal?.contains(window.document.activeElement)) {
context.core.navigation.previousFocus?.focus();
}
context.core.navigation.modal = null;
context.core.navigation.previousFocus = null;
if (context.core.navigation.type === 'overlay') {
document.documentElement.classList.remove('has-modal-open');
}
}
};
(0,_wordpress_interactivity__WEBPACK_IMPORTED_MODULE_0__/* .store */ .h)({
effects: {
core: {
navigation: {
initMenu: store => {
const {
context,
selectors,
ref
} = store;
if (selectors.core.navigation.isMenuOpen(store)) {
const focusableElements = ref.querySelectorAll(focusableSelectors);
context.core.navigation.modal = ref;
context.core.navigation.firstFocusableElement = focusableElements[0];
context.core.navigation.lastFocusableElement = focusableElements[focusableElements.length - 1];
}
},
focusFirstElement: store => {
const {
selectors,
ref
} = store;
if (selectors.core.navigation.isMenuOpen(store)) {
ref.querySelector('.wp-block-navigation-item > *:first-child').focus();
}
}
}
}
},
selectors: {
core: {
navigation: {
roleAttribute: store => {
const {
context,
selectors
} = store;
return context.core.navigation.type === 'overlay' && selectors.core.navigation.isMenuOpen(store) ? 'dialog' : null;
},
ariaModal: store => {
const {
context,
selectors
} = store;
return context.core.navigation.type === 'overlay' && selectors.core.navigation.isMenuOpen(store) ? 'true' : null;
},
ariaLabel: store => {
const {
context,
selectors
} = store;
return context.core.navigation.type === 'overlay' && selectors.core.navigation.isMenuOpen(store) ? context.core.navigation.ariaLabel : null;
},
isMenuOpen: ({
context
}) =>
// The menu is opened if either `click`, `hover` or `focus` is true.
Object.values(context.core.navigation[context.core.navigation.type === 'overlay' ? 'overlayOpenedBy' : 'submenuOpenedBy']).filter(Boolean).length > 0,
menuOpenedBy: ({
context
}) => context.core.navigation[context.core.navigation.type === 'overlay' ? 'overlayOpenedBy' : 'submenuOpenedBy']
}
}
},
actions: {
core: {
navigation: {
openMenuOnHover(store) {
const {
navigation
} = store.context.core;
if (navigation.type === 'submenu' &&
// Only open on hover if the overlay is closed.
Object.values(navigation.overlayOpenedBy || {}).filter(Boolean).length === 0) openMenu(store, 'hover');
},
closeMenuOnHover(store) {
closeMenu(store, 'hover');
},
openMenuOnClick(store) {
const {
context,
ref
} = store;
context.core.navigation.previousFocus = ref;
openMenu(store, 'click');
},
closeMenuOnClick(store) {
closeMenu(store, 'click');
closeMenu(store, 'focus');
},
openMenuOnFocus(store) {
openMenu(store, 'focus');
},
toggleMenuOnClick: store => {
const {
selectors,
context,
ref
} = store;
// Safari won't send focus to the clicked element, so we need to manually place it: https://bugs.webkit.org/show_bug.cgi?id=22261
if (window.document.activeElement !== ref) ref.focus();
const menuOpenedBy = selectors.core.navigation.menuOpenedBy(store);
if (menuOpenedBy.click || menuOpenedBy.focus) {
closeMenu(store, 'click');
closeMenu(store, 'focus');
} else {
context.core.navigation.previousFocus = ref;
openMenu(store, 'click');
}
},
handleMenuKeydown: store => {
const {
context,
selectors,
event
} = store;
if (selectors.core.navigation.menuOpenedBy(store).click) {
// If Escape close the menu.
if (event?.key === 'Escape') {
closeMenu(store, 'click');
closeMenu(store, 'focus');
return;
}
// Trap focus if it is an overlay (main menu).
if (context.core.navigation.type === 'overlay' && event.key === 'Tab') {
// If shift + tab it change the direction.
if (event.shiftKey && window.document.activeElement === context.core.navigation.firstFocusableElement) {
event.preventDefault();
context.core.navigation.lastFocusableElement.focus();
} else if (!event.shiftKey && window.document.activeElement === context.core.navigation.lastFocusableElement) {
event.preventDefault();
context.core.navigation.firstFocusableElement.focus();
}
}
}
},
handleMenuFocusout: store => {
const {
context,
event
} = store;
// If focus is outside modal, and in the document, close menu
// event.target === The element losing focus
// event.relatedTarget === The element receiving focus (if any)
// When focusout is outsite the document,
// `window.document.activeElement` doesn't change.
// The event.relatedTarget is null when something outside the navigation menu is clicked. This is only necessary for Safari.
if (event.relatedTarget === null || !context.core.navigation.modal?.contains(event.relatedTarget) && event.target !== window.document.activeElement) {
closeMenu(store, 'click');
closeMenu(store, 'focus');
}
}
}
}
}
});
/***/ })
},
/******/ function(__webpack_require__) { // webpackRuntimeModules
/******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
/******/ var __webpack_exports__ = (__webpack_exec__(932));
/******/ }
]);
|