@afixt/test-utils 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/.github/dependabot.yml +36 -0
- package/.github/workflows/ci.yml +71 -0
- package/.github/workflows/security.yml +142 -0
- package/.husky/pre-commit +1 -0
- package/.jscpd.json +27 -0
- package/.markdownlint.json +9 -0
- package/.prettierignore +13 -0
- package/.prettierrc +10 -0
- package/docs/arrayUtils.js.html +2 -2
- package/docs/domUtils.js.html +2 -2
- package/docs/getAccessibleName.js.html +2 -2
- package/docs/getAccessibleText.js.html +2 -2
- package/docs/getAriaAttributesByElement.js.html +2 -2
- package/docs/getCSSGeneratedContent.js.html +2 -2
- package/docs/getComputedRole.js.html +2 -2
- package/docs/getFocusableElements.js.html +2 -2
- package/docs/getGeneratedContent.js.html +2 -2
- package/docs/getImageText.js.html +2 -2
- package/docs/getStyleObject.js.html +2 -2
- package/docs/global.html +2 -2
- package/docs/hasAccessibleName.js.html +2 -2
- package/docs/hasAttribute.js.html +2 -2
- package/docs/hasCSSGeneratedContent.js.html +2 -2
- package/docs/hasHiddenParent.js.html +2 -2
- package/docs/hasParent.js.html +2 -2
- package/docs/hasValidAriaAttributes.js.html +2 -2
- package/docs/hasValidAriaRole.js.html +2 -2
- package/docs/index.html +2 -2
- package/docs/index.js.html +2 -2
- package/docs/isAriaAttributesValid.js.html +2 -2
- package/docs/isComplexTable.js.html +2 -2
- package/docs/isDataTable.js.html +2 -2
- package/docs/isFocusable.js.html +2 -2
- package/docs/isHidden.js.html +2 -2
- package/docs/isOffScreen.js.html +2 -2
- package/docs/isValidUrl.js.html +2 -2
- package/docs/isVisible.js.html +2 -2
- package/docs/module-afixt-test-utils.html +2 -2
- package/docs/scripts/core.js +726 -726
- package/docs/scripts/core.min.js +22 -22
- package/docs/scripts/resize.js +90 -90
- package/docs/scripts/search.js +265 -265
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -202
- package/docs/scripts/third-party/fuse.js +8 -8
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -369
- package/docs/scripts/third-party/hljs-original.js +5171 -5171
- package/docs/scripts/third-party/popper.js +5 -5
- package/docs/scripts/third-party/tippy.js +1 -1
- package/docs/scripts/third-party/tocbot.js +671 -671
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -1159
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -412
- package/docs/styles/clean-jsdoc-theme-light.css +482 -482
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +29 -29
- package/docs/testContrast.js.html +2 -2
- package/docs/testLang.js.html +2 -2
- package/docs/testOrder.js.html +2 -2
- package/eslint.config.mjs +84 -0
- package/package.json +68 -41
- package/scratchpads/issue-6-standardize-repo.md +109 -0
- package/src/getAccessibleName.js +156 -112
- package/src/getAccessibleText.js +71 -42
- package/test/getAccessibleName.test.js +379 -315
- package/test/getAccessibleText.test.js +375 -308
- package/.eslintrc +0 -78
- package/.github/workflows/test.yml +0 -26
package/docs/scripts/search.js
CHANGED
|
@@ -1,265 +1,265 @@
|
|
|
1
|
-
/* global document */
|
|
2
|
-
|
|
3
|
-
const searchId = 'LiBfqbJVcV';
|
|
4
|
-
const searchHash = '#' + searchId;
|
|
5
|
-
const searchContainer = document.querySelector('#PkfLWpAbet');
|
|
6
|
-
const searchWrapper = document.querySelector('#iCxFxjkHbP');
|
|
7
|
-
const searchCloseButton = document.querySelector('#VjLlGakifb');
|
|
8
|
-
const searchInput = document.querySelector('#vpcKVYIppa');
|
|
9
|
-
const resultBox = document.querySelector('#fWwVHRuDuN');
|
|
10
|
-
|
|
11
|
-
function showResultText(text) {
|
|
12
|
-
resultBox.innerHTML = `<span class="search-result-c-text">${text}</span>`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function hideSearch() {
|
|
16
|
-
// eslint-disable-next-line no-undef
|
|
17
|
-
if (window.location.hash === searchHash) {
|
|
18
|
-
// eslint-disable-next-line no-undef
|
|
19
|
-
history.go(-1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line no-undef
|
|
23
|
-
window.onhashchange = null;
|
|
24
|
-
|
|
25
|
-
if (searchContainer) {
|
|
26
|
-
searchContainer.style.display = 'none';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function listenCloseKey(event) {
|
|
31
|
-
if (event.key === 'Escape') {
|
|
32
|
-
hideSearch();
|
|
33
|
-
// eslint-disable-next-line no-undef
|
|
34
|
-
window.removeEventListener('keyup', listenCloseKey);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function showSearch() {
|
|
39
|
-
try {
|
|
40
|
-
// Closing mobile menu before opening
|
|
41
|
-
// search box.
|
|
42
|
-
// It is defined in core.js
|
|
43
|
-
// eslint-disable-next-line no-undef
|
|
44
|
-
hideMobileMenu();
|
|
45
|
-
} catch (error) {
|
|
46
|
-
console.error(error);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// eslint-disable-next-line no-undef
|
|
50
|
-
window.onhashchange = hideSearch;
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line no-undef
|
|
53
|
-
if (window.location.hash !== searchHash) {
|
|
54
|
-
// eslint-disable-next-line no-undef
|
|
55
|
-
history.pushState(null, null, searchHash);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (searchContainer) {
|
|
59
|
-
searchContainer.style.display = 'flex';
|
|
60
|
-
// eslint-disable-next-line no-undef
|
|
61
|
-
window.addEventListener('keyup', listenCloseKey);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (searchInput) {
|
|
65
|
-
searchInput.focus();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function fetchAllData() {
|
|
70
|
-
// eslint-disable-next-line no-undef
|
|
71
|
-
const { hostname, protocol, port } = location;
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line no-undef
|
|
74
|
-
const base = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + baseURL;
|
|
75
|
-
// eslint-disable-next-line no-undef
|
|
76
|
-
const url = new URL('data/search.json', base);
|
|
77
|
-
const result = await fetch(url);
|
|
78
|
-
const { list } = await result.json();
|
|
79
|
-
|
|
80
|
-
return list;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// eslint-disable-next-line no-unused-vars
|
|
84
|
-
function onClickSearchItem(event) {
|
|
85
|
-
const target = event.currentTarget;
|
|
86
|
-
|
|
87
|
-
if (target) {
|
|
88
|
-
const href = target.getAttribute('href') || '';
|
|
89
|
-
let elementId = href.split('#')[1] || '';
|
|
90
|
-
let element = document.getElementById(elementId);
|
|
91
|
-
|
|
92
|
-
if (!element) {
|
|
93
|
-
elementId = decodeURI(elementId);
|
|
94
|
-
element = document.getElementById(elementId);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (element) {
|
|
98
|
-
setTimeout(function() {
|
|
99
|
-
// eslint-disable-next-line no-undef
|
|
100
|
-
bringElementIntoView(element); // defined in core.js
|
|
101
|
-
}, 100);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function buildSearchResult(result) {
|
|
107
|
-
let output = '';
|
|
108
|
-
const removeHTMLTagsRegExp = /(<([^>]+)>)/ig;
|
|
109
|
-
|
|
110
|
-
for (const res of result) {
|
|
111
|
-
const { title = '', description = '' } = res.item;
|
|
112
|
-
|
|
113
|
-
const _link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
|
|
114
|
-
const _title = title.replace(removeHTMLTagsRegExp, "");
|
|
115
|
-
const _description = description.replace(removeHTMLTagsRegExp, "");
|
|
116
|
-
|
|
117
|
-
output += `
|
|
118
|
-
<a onclick="onClickSearchItem(event)" href="${_link}" class="search-result-item">
|
|
119
|
-
<div class="search-result-item-title">${_title}</div>
|
|
120
|
-
<div class="search-result-item-p">${_description || 'No description available.'}</div>
|
|
121
|
-
</a>
|
|
122
|
-
`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return output;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function getSearchResult(list, keys, searchKey) {
|
|
129
|
-
const defaultOptions = {
|
|
130
|
-
shouldSort: true,
|
|
131
|
-
threshold: 0.4,
|
|
132
|
-
location: 0,
|
|
133
|
-
distance: 100,
|
|
134
|
-
maxPatternLength: 32,
|
|
135
|
-
minMatchCharLength: 1,
|
|
136
|
-
keys: keys
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const options = { ...defaultOptions };
|
|
140
|
-
|
|
141
|
-
// eslint-disable-next-line no-undef
|
|
142
|
-
const searchIndex = Fuse.createIndex(options.keys, list);
|
|
143
|
-
|
|
144
|
-
// eslint-disable-next-line no-undef
|
|
145
|
-
const fuse = new Fuse(list, options, searchIndex);
|
|
146
|
-
|
|
147
|
-
const result = fuse.search(searchKey);
|
|
148
|
-
|
|
149
|
-
if (result.length > 20) {
|
|
150
|
-
return result.slice(0, 20);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function debounce(func, wait, immediate) {
|
|
157
|
-
let timeout;
|
|
158
|
-
|
|
159
|
-
return function() {
|
|
160
|
-
const args = arguments;
|
|
161
|
-
|
|
162
|
-
clearTimeout(timeout);
|
|
163
|
-
timeout = setTimeout(() => {
|
|
164
|
-
timeout = null;
|
|
165
|
-
if (!immediate) {
|
|
166
|
-
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
167
|
-
func.apply(this, args);
|
|
168
|
-
}
|
|
169
|
-
}, wait);
|
|
170
|
-
|
|
171
|
-
if (immediate && !timeout) {
|
|
172
|
-
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
173
|
-
func.apply(this, args);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
let searchData;
|
|
179
|
-
|
|
180
|
-
async function search(event) {
|
|
181
|
-
const value = event.target.value;
|
|
182
|
-
const keys = ['title', 'description'];
|
|
183
|
-
|
|
184
|
-
if (!resultBox) {
|
|
185
|
-
console.error('Search result container not found');
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (!value) {
|
|
191
|
-
showResultText('Type anything to view search result');
|
|
192
|
-
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (!searchData) {
|
|
197
|
-
showResultText('Loading...');
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
// eslint-disable-next-line require-atomic-updates
|
|
201
|
-
searchData = await fetchAllData();
|
|
202
|
-
} catch (e) {
|
|
203
|
-
console.log(e);
|
|
204
|
-
showResultText('Failed to load result.');
|
|
205
|
-
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const result = getSearchResult(searchData, keys, value);
|
|
211
|
-
|
|
212
|
-
if (!result.length) {
|
|
213
|
-
showResultText('No result found! Try some different combination.');
|
|
214
|
-
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// eslint-disable-next-line require-atomic-updates
|
|
219
|
-
resultBox.innerHTML = buildSearchResult(result);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function onDomContentLoaded() {
|
|
223
|
-
const searchButton = document.querySelectorAll('.search-button');
|
|
224
|
-
const debouncedSearch = debounce(search, 300);
|
|
225
|
-
|
|
226
|
-
if (searchCloseButton) {
|
|
227
|
-
searchCloseButton.addEventListener('click', hideSearch);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (searchButton) {
|
|
231
|
-
searchButton.forEach(function(item) {
|
|
232
|
-
item.addEventListener('click', showSearch);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (searchContainer) {
|
|
237
|
-
searchContainer.addEventListener('click', hideSearch);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (searchWrapper) {
|
|
241
|
-
searchWrapper.addEventListener('click', function(event) {
|
|
242
|
-
event.stopPropagation();
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (searchInput) {
|
|
247
|
-
searchInput.addEventListener('keyup', debouncedSearch);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// eslint-disable-next-line no-undef
|
|
251
|
-
if (window.location.hash === searchHash) {
|
|
252
|
-
showSearch();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// eslint-disable-next-line no-undef
|
|
257
|
-
window.addEventListener('DOMContentLoaded', onDomContentLoaded);
|
|
258
|
-
|
|
259
|
-
// eslint-disable-next-line no-undef
|
|
260
|
-
window.addEventListener('hashchange', function() {
|
|
261
|
-
// eslint-disable-next-line no-undef
|
|
262
|
-
if (window.location.hash === searchHash) {
|
|
263
|
-
showSearch();
|
|
264
|
-
}
|
|
265
|
-
});
|
|
1
|
+
/* global document */
|
|
2
|
+
|
|
3
|
+
const searchId = 'LiBfqbJVcV';
|
|
4
|
+
const searchHash = '#' + searchId;
|
|
5
|
+
const searchContainer = document.querySelector('#PkfLWpAbet');
|
|
6
|
+
const searchWrapper = document.querySelector('#iCxFxjkHbP');
|
|
7
|
+
const searchCloseButton = document.querySelector('#VjLlGakifb');
|
|
8
|
+
const searchInput = document.querySelector('#vpcKVYIppa');
|
|
9
|
+
const resultBox = document.querySelector('#fWwVHRuDuN');
|
|
10
|
+
|
|
11
|
+
function showResultText(text) {
|
|
12
|
+
resultBox.innerHTML = `<span class="search-result-c-text">${text}</span>`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hideSearch() {
|
|
16
|
+
// eslint-disable-next-line no-undef
|
|
17
|
+
if (window.location.hash === searchHash) {
|
|
18
|
+
// eslint-disable-next-line no-undef
|
|
19
|
+
history.go(-1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line no-undef
|
|
23
|
+
window.onhashchange = null;
|
|
24
|
+
|
|
25
|
+
if (searchContainer) {
|
|
26
|
+
searchContainer.style.display = 'none';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function listenCloseKey(event) {
|
|
31
|
+
if (event.key === 'Escape') {
|
|
32
|
+
hideSearch();
|
|
33
|
+
// eslint-disable-next-line no-undef
|
|
34
|
+
window.removeEventListener('keyup', listenCloseKey);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function showSearch() {
|
|
39
|
+
try {
|
|
40
|
+
// Closing mobile menu before opening
|
|
41
|
+
// search box.
|
|
42
|
+
// It is defined in core.js
|
|
43
|
+
// eslint-disable-next-line no-undef
|
|
44
|
+
hideMobileMenu();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line no-undef
|
|
50
|
+
window.onhashchange = hideSearch;
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line no-undef
|
|
53
|
+
if (window.location.hash !== searchHash) {
|
|
54
|
+
// eslint-disable-next-line no-undef
|
|
55
|
+
history.pushState(null, null, searchHash);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (searchContainer) {
|
|
59
|
+
searchContainer.style.display = 'flex';
|
|
60
|
+
// eslint-disable-next-line no-undef
|
|
61
|
+
window.addEventListener('keyup', listenCloseKey);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (searchInput) {
|
|
65
|
+
searchInput.focus();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function fetchAllData() {
|
|
70
|
+
// eslint-disable-next-line no-undef
|
|
71
|
+
const { hostname, protocol, port } = location;
|
|
72
|
+
|
|
73
|
+
// eslint-disable-next-line no-undef
|
|
74
|
+
const base = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + baseURL;
|
|
75
|
+
// eslint-disable-next-line no-undef
|
|
76
|
+
const url = new URL('data/search.json', base);
|
|
77
|
+
const result = await fetch(url);
|
|
78
|
+
const { list } = await result.json();
|
|
79
|
+
|
|
80
|
+
return list;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line no-unused-vars
|
|
84
|
+
function onClickSearchItem(event) {
|
|
85
|
+
const target = event.currentTarget;
|
|
86
|
+
|
|
87
|
+
if (target) {
|
|
88
|
+
const href = target.getAttribute('href') || '';
|
|
89
|
+
let elementId = href.split('#')[1] || '';
|
|
90
|
+
let element = document.getElementById(elementId);
|
|
91
|
+
|
|
92
|
+
if (!element) {
|
|
93
|
+
elementId = decodeURI(elementId);
|
|
94
|
+
element = document.getElementById(elementId);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (element) {
|
|
98
|
+
setTimeout(function() {
|
|
99
|
+
// eslint-disable-next-line no-undef
|
|
100
|
+
bringElementIntoView(element); // defined in core.js
|
|
101
|
+
}, 100);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function buildSearchResult(result) {
|
|
107
|
+
let output = '';
|
|
108
|
+
const removeHTMLTagsRegExp = /(<([^>]+)>)/ig;
|
|
109
|
+
|
|
110
|
+
for (const res of result) {
|
|
111
|
+
const { title = '', description = '' } = res.item;
|
|
112
|
+
|
|
113
|
+
const _link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
|
|
114
|
+
const _title = title.replace(removeHTMLTagsRegExp, "");
|
|
115
|
+
const _description = description.replace(removeHTMLTagsRegExp, "");
|
|
116
|
+
|
|
117
|
+
output += `
|
|
118
|
+
<a onclick="onClickSearchItem(event)" href="${_link}" class="search-result-item">
|
|
119
|
+
<div class="search-result-item-title">${_title}</div>
|
|
120
|
+
<div class="search-result-item-p">${_description || 'No description available.'}</div>
|
|
121
|
+
</a>
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return output;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getSearchResult(list, keys, searchKey) {
|
|
129
|
+
const defaultOptions = {
|
|
130
|
+
shouldSort: true,
|
|
131
|
+
threshold: 0.4,
|
|
132
|
+
location: 0,
|
|
133
|
+
distance: 100,
|
|
134
|
+
maxPatternLength: 32,
|
|
135
|
+
minMatchCharLength: 1,
|
|
136
|
+
keys: keys
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const options = { ...defaultOptions };
|
|
140
|
+
|
|
141
|
+
// eslint-disable-next-line no-undef
|
|
142
|
+
const searchIndex = Fuse.createIndex(options.keys, list);
|
|
143
|
+
|
|
144
|
+
// eslint-disable-next-line no-undef
|
|
145
|
+
const fuse = new Fuse(list, options, searchIndex);
|
|
146
|
+
|
|
147
|
+
const result = fuse.search(searchKey);
|
|
148
|
+
|
|
149
|
+
if (result.length > 20) {
|
|
150
|
+
return result.slice(0, 20);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function debounce(func, wait, immediate) {
|
|
157
|
+
let timeout;
|
|
158
|
+
|
|
159
|
+
return function() {
|
|
160
|
+
const args = arguments;
|
|
161
|
+
|
|
162
|
+
clearTimeout(timeout);
|
|
163
|
+
timeout = setTimeout(() => {
|
|
164
|
+
timeout = null;
|
|
165
|
+
if (!immediate) {
|
|
166
|
+
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
167
|
+
func.apply(this, args);
|
|
168
|
+
}
|
|
169
|
+
}, wait);
|
|
170
|
+
|
|
171
|
+
if (immediate && !timeout) {
|
|
172
|
+
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
173
|
+
func.apply(this, args);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let searchData;
|
|
179
|
+
|
|
180
|
+
async function search(event) {
|
|
181
|
+
const value = event.target.value;
|
|
182
|
+
const keys = ['title', 'description'];
|
|
183
|
+
|
|
184
|
+
if (!resultBox) {
|
|
185
|
+
console.error('Search result container not found');
|
|
186
|
+
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!value) {
|
|
191
|
+
showResultText('Type anything to view search result');
|
|
192
|
+
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!searchData) {
|
|
197
|
+
showResultText('Loading...');
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
// eslint-disable-next-line require-atomic-updates
|
|
201
|
+
searchData = await fetchAllData();
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.log(e);
|
|
204
|
+
showResultText('Failed to load result.');
|
|
205
|
+
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const result = getSearchResult(searchData, keys, value);
|
|
211
|
+
|
|
212
|
+
if (!result.length) {
|
|
213
|
+
showResultText('No result found! Try some different combination.');
|
|
214
|
+
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// eslint-disable-next-line require-atomic-updates
|
|
219
|
+
resultBox.innerHTML = buildSearchResult(result);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function onDomContentLoaded() {
|
|
223
|
+
const searchButton = document.querySelectorAll('.search-button');
|
|
224
|
+
const debouncedSearch = debounce(search, 300);
|
|
225
|
+
|
|
226
|
+
if (searchCloseButton) {
|
|
227
|
+
searchCloseButton.addEventListener('click', hideSearch);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (searchButton) {
|
|
231
|
+
searchButton.forEach(function(item) {
|
|
232
|
+
item.addEventListener('click', showSearch);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (searchContainer) {
|
|
237
|
+
searchContainer.addEventListener('click', hideSearch);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (searchWrapper) {
|
|
241
|
+
searchWrapper.addEventListener('click', function(event) {
|
|
242
|
+
event.stopPropagation();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (searchInput) {
|
|
247
|
+
searchInput.addEventListener('keyup', debouncedSearch);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// eslint-disable-next-line no-undef
|
|
251
|
+
if (window.location.hash === searchHash) {
|
|
252
|
+
showSearch();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// eslint-disable-next-line no-undef
|
|
257
|
+
window.addEventListener('DOMContentLoaded', onDomContentLoaded);
|
|
258
|
+
|
|
259
|
+
// eslint-disable-next-line no-undef
|
|
260
|
+
window.addEventListener('hashchange', function() {
|
|
261
|
+
// eslint-disable-next-line no-undef
|
|
262
|
+
if (window.location.hash === searchHash) {
|
|
263
|
+
showSearch();
|
|
264
|
+
}
|
|
265
|
+
});
|