|
10 | 10 | const classHeader = 'header'; |
11 | 11 |
|
12 | 12 | const selectorIsNone = '.' + classNone; |
13 | | - const selectorNotNone = ':not(' + selectorIsNone + ')'; |
| 13 | + const selectorNotNone = `:not(${selectorIsNone})`; |
14 | 14 | const selectorPathList = '.path-list'; |
15 | 15 | const selectorItemList = '.item-list'; |
16 | | - const selectorItem = 'li:not(.' + classHeader + '):not(.parent)'; |
| 16 | + const selectorItem = `li:not(.${classHeader}):not(.parent)`; |
17 | 17 | const selectorItemIsNone = selectorItem + selectorIsNone; |
18 | 18 | const selectorItemNotNone = selectorItem + selectorNotNone; |
19 | 19 |
|
20 | | - const leavingEvent = typeof window.onpagehide !== strUndef ? 'pagehide' : 'beforeunload'; |
21 | | - |
22 | 20 | const Enter = 'Enter'; |
23 | 21 | const Escape = 'Escape'; |
24 | 22 | const Esc = 'Esc'; |
|
33 | 31 | let filteredText = ''; |
34 | 32 |
|
35 | 33 | function matchFilter(input) { |
36 | | - return input.toLowerCase().indexOf(filteredText) >= 0; |
| 34 | + return input.toLowerCase().includes(filteredText); |
37 | 35 | } |
38 | 36 |
|
39 | 37 | let lastFocused; |
|
47 | 45 | const input = filter.querySelector('input'); |
48 | 46 | if (!input) return; |
49 | 47 |
|
50 | | - let clear = filter.querySelector('button'); |
51 | | - if (!clear) clear = document.createElement('button'); |
| 48 | + const clear = filter.querySelector('button') || document.createElement('button'); |
52 | 49 |
|
53 | 50 | const itemList = document.querySelector(selectorItemList) |
54 | 51 |
|
|
62 | 59 | clear.style.display = 'block'; |
63 | 60 |
|
64 | 61 | let selector |
65 | | - if (filteringText.indexOf(filteredText) >= 0) { // increment search, find in visible items |
| 62 | + if (filteringText.includes(filteredText)) { // increment search, find in visible items |
66 | 63 | selector = selectorItemNotNone; |
67 | | - } else if (filteredText.indexOf(filteringText) >= 0) { // decrement search, find in hidden items |
| 64 | + } else if (filteredText.includes(filteringText)) { // decrement search, find in hidden items |
68 | 65 | selector = selectorItemIsNone; |
69 | 66 | } else { |
70 | 67 | selector = selectorItem; |
71 | 68 | } |
72 | 69 | filteredText = filteringText; |
73 | 70 |
|
74 | 71 | items = itemList.querySelectorAll(selector); |
75 | | - if (!items.forEach) items = Array.prototype.slice.call(items); // IE9+/ClassicEdge |
76 | | - items.forEach(function (item) { |
| 72 | + items.forEach(item => { |
77 | 73 | const name = item.querySelector('.name'); |
78 | 74 | if (matchFilter(name.textContent)) { |
79 | 75 | if (selector !== selectorItemNotNone) { |
|
90 | 86 | filteredText = ''; |
91 | 87 |
|
92 | 88 | items = itemList.querySelectorAll(selectorItemIsNone); |
93 | | - if (!items.forEach) items = Array.prototype.slice.call(items); // IE9+/ClassicEdge |
94 | | - items.forEach(function (item) { |
95 | | - item.classList.remove(classNone); |
96 | | - }); |
| 89 | + items.forEach(item => item.classList.remove(classNone)); |
97 | 90 | } |
98 | 91 | }; |
99 | 92 |
|
|
143 | 136 | sessionStorage.removeItem(location.pathname); |
144 | 137 | } |
145 | 138 |
|
146 | | - window.addEventListener(leavingEvent, function () { |
| 139 | + window.addEventListener('pagehide', function () { |
147 | 140 | if (input.value) { |
148 | 141 | sessionStorage.setItem(location.pathname, input.value); |
149 | 142 | } |
150 | 143 | }); |
151 | | - |
152 | 144 | } |
153 | 145 | if (input.value) { |
154 | 146 | doFilter(); |
|
200 | 192 | prevChildName = decodeURIComponent(prevChildName); |
201 | 193 | if (!matchFilter(prevChildName)) return; |
202 | 194 |
|
203 | | - let items = document.body.querySelectorAll(selectorItemList + '>' + selectorItemNotNone); |
204 | | - items = Array.prototype.slice.call(items); |
| 195 | + const items = Array.from(document.body.querySelectorAll(selectorItemList + '>' + selectorItemNotNone)); |
205 | 196 | const selectorName = '.field.name'; |
206 | 197 | const selectorLink = 'a'; |
207 | 198 | for (let i = 0; i < items.length; i++) { |
|
237 | 228 | } |
238 | 229 | let startLI = startA && startA.closest('li'); |
239 | 230 | if (!startLI) { |
240 | | - if (isBackward) { |
241 | | - startLI = container.firstElementChild; |
242 | | - } else { |
243 | | - startLI = container.lastElementChild; |
244 | | - } |
| 231 | + startLI = isBackward ? container.firstElementChild : container.lastElementChild; |
245 | 232 | } |
246 | 233 | if (!startLI) { |
247 | 234 | return; |
|
266 | 253 | } |
267 | 254 |
|
268 | 255 | function getFirstFocusableSibling(container) { |
269 | | - const a = container.querySelector('li:not(.' + classNone + '):not(.' + classHeader + ') a'); |
| 256 | + const a = container.querySelector(`li:not(.${classNone}):not(.${classHeader}) a`); |
270 | 257 | return a; |
271 | 258 | } |
272 | 259 |
|
|
278 | 265 |
|
279 | 266 | function getMatchedFocusableSibling(container, isBackward, startA, buf) { |
280 | 267 | let skipRound = buf.length === 1; // find next single-char prefix |
281 | | - let firstCheckA; |
282 | | - let secondCheckA; |
| 268 | + let firstCheckedA; |
| 269 | + let secondCheckedA; |
283 | 270 | let a = startA; |
284 | 271 | do { |
285 | 272 | if (skipRound) { |
|
290 | 277 | continue; |
291 | 278 | } |
292 | 279 |
|
293 | | - // firstCheckA maybe a focused a that not belongs to the list |
294 | | - // secondCheckA must be in the list |
295 | | - if (!firstCheckA) { |
296 | | - firstCheckA = a; |
297 | | - } else if (firstCheckA === a) { |
| 280 | + // firstCheckedA maybe a focused a that not belongs to the list |
| 281 | + // secondCheckedA must be in the list |
| 282 | + if (!firstCheckedA) { |
| 283 | + firstCheckedA = a; |
| 284 | + } else if (firstCheckedA === a) { |
298 | 285 | return; |
299 | | - } else if (!secondCheckA) { |
300 | | - secondCheckA = a; |
301 | | - } else if (secondCheckA === a) { |
| 286 | + } else if (!secondCheckedA) { |
| 287 | + secondCheckedA = a; |
| 288 | + } else if (secondCheckedA === a) { |
302 | 289 | return; |
303 | 290 | } |
304 | 291 |
|
|
317 | 304 | const SKIP_TAGS = ['INPUT', 'BUTTON', 'TEXTAREA']; |
318 | 305 |
|
319 | 306 | const PLATFORM = navigator.platform || navigator.userAgent; |
320 | | - const IS_MAC_PLATFORM = PLATFORM.indexOf('Mac') >= 0 || PLATFORM.indexOf('iPhone') >= 0 || PLATFORM.indexOf('iPad') >= 0 || PLATFORM.indexOf('iPod') >= 0 |
| 307 | + const IS_MAC_PLATFORM = PLATFORM.includes('Mac') || PLATFORM.includes('iPhone') || PLATFORM.includes('iPad') || PLATFORM.includes('iPod') |
321 | 308 |
|
322 | 309 | let lookupKey; |
323 | 310 | let lookupBuffer; |
|
380 | 367 | } |
381 | 368 |
|
382 | 369 | function getFocusItemByKeyPress(e) { |
383 | | - if (SKIP_TAGS.indexOf(e.target.tagName) >= 0) { |
| 370 | + if (SKIP_TAGS.includes(e.target.tagName)) { |
384 | 371 | return; |
385 | 372 | } |
386 | 373 |
|
|
598 | 585 | } |
599 | 586 |
|
600 | 587 | function enableFileDirModeSwitch() { |
601 | | - const classHidden = 'hidden'; |
602 | 588 | const classActive = 'active'; |
603 | 589 |
|
604 | 590 | function onClickOpt(optTarget, clearInput) { |
|
669 | 655 | return; |
670 | 656 | } |
671 | 657 |
|
672 | | - const nodir = Array.prototype.slice.call(files).every(function (file) { |
673 | | - return file.webkitRelativePath.indexOf('/') < 0; |
674 | | - }); |
675 | | - if (nodir) { |
| 658 | + const noDir = Array.prototype.slice.call(files).every(file => |
| 659 | + file.webkitRelativePath.includes('/') |
| 660 | + ); |
| 661 | + if (noDir) { |
676 | 662 | onClickOptFile(); // prevent clear input files |
677 | 663 | } |
678 | 664 | }); |
|
699 | 685 | sessionStorage.removeItem(uploadTypeField); |
700 | 686 | } |
701 | 687 |
|
702 | | - window.addEventListener(leavingEvent, function () { |
| 688 | + window.addEventListener('pagehide', function () { |
703 | 689 | const activeUploadType = fileInput.name; |
704 | 690 | if (activeUploadType !== file) { |
705 | 691 | sessionStorage.setItem(uploadTypeField, activeUploadType) |
|
923 | 909 | const tagName = e.target.tagName; |
924 | 910 | if (tagName === 'TEXTAREA') { |
925 | 911 | return; |
926 | | - } else if (tagName === 'INPUT' && nonTextInputTypes.indexOf(e.target.type) < 0) { |
| 912 | + } else if (tagName === 'INPUT' && !nonTextInputTypes.includes(e.target.type)) { |
927 | 913 | return; |
928 | 914 | } |
929 | 915 |
|
|
967 | 953 | }); |
968 | 954 | } |
969 | 955 |
|
970 | | - const modes = enableFileDirModeSwitch(); |
| 956 | + const {switchToFileMode, switchToDirMode} = enableFileDirModeSwitch(); |
971 | 957 | const uploadProgressively = enableUploadProgress(); |
972 | 958 | enableFormUploadProgress(uploadProgressively); |
973 | | - enableDndUploadProgress(uploadProgressively, modes.switchToFileMode, modes.switchToDirMode); |
974 | | - enablePasteUploadProgress(uploadProgressively, modes.switchToFileMode, modes.switchToDirMode); |
| 959 | + enableDndUploadProgress(uploadProgressively, switchToFileMode, switchToDirMode); |
| 960 | + enablePasteUploadProgress(uploadProgressively, switchToFileMode, switchToDirMode); |
975 | 961 | } |
976 | 962 |
|
977 | 963 | function enableNonRefreshDelete() { |
|
0 commit comments