|
39 | 39 | var lastFocused; |
40 | 40 |
|
41 | 41 | function enableFilter() { |
42 | | - if (!document.querySelector) { |
43 | | - var filter = document.getElementById && document.getElementById('panel-filter'); |
44 | | - if (filter) { |
45 | | - filter.className += ' none'; |
46 | | - } |
47 | | - return; |
48 | | - } |
49 | | - |
50 | 42 | // pre check |
51 | 43 | var filter = document.body.querySelector('.filter'); |
52 | 44 | if (!filter) { |
53 | 45 | return; |
54 | 46 | } |
55 | | - if (!filter.addEventListener) { |
56 | | - filter.className += ' none'; |
57 | | - return; |
58 | | - } |
59 | 47 |
|
60 | 48 | var input = filter.querySelector('input'); |
61 | 49 | if (!input) { |
|
187 | 175 | } |
188 | 176 |
|
189 | 177 | function keepFocusOnBackwardForward() { |
190 | | - if (window.onpageshow === undefined || !document.querySelector) return; |
191 | | - |
192 | 178 | function onFocus(e) { |
193 | 179 | var link = e.target; |
194 | 180 | while (link && !(link instanceof HTMLAnchorElement)) { |
|
210 | 196 | } |
211 | 197 |
|
212 | 198 | function focusChildOnNavUp() { |
213 | | - if (!document.querySelector) return; |
214 | | - |
215 | 199 | function extractCleanUrl(url) { |
216 | 200 | var sepIndex = url.indexOf('?'); |
217 | 201 | if (sepIndex < 0) sepIndex = url.indexOf('#'); |
|
261 | 245 | } |
262 | 246 |
|
263 | 247 | function enableKeyboardNavigate() { |
264 | | - if ( |
265 | | - !document.querySelector || |
266 | | - !document.addEventListener || |
267 | | - !document.body.parentElement |
268 | | - ) { |
269 | | - return; |
270 | | - } |
271 | | - |
272 | 248 | var pathList = document.body.querySelector('.path-list'); |
273 | 249 | var itemList = document.body.querySelector('.item-list'); |
274 | 250 | if (!pathList && !itemList) { |
|
536 | 512 | } |
537 | 513 |
|
538 | 514 | function enhanceUpload() { |
539 | | - if (!document.querySelector || !document.addEventListener) { |
540 | | - return; |
541 | | - } |
542 | | - |
543 | 515 | var upload = document.body.querySelector('.upload'); |
544 | 516 | if (!upload) { |
545 | 517 | return; |
|
597 | 569 | }).then(function (file) { |
598 | 570 | var relativePath = dirPath + file.name; |
599 | 571 | files.push({file: file, relativePath: relativePath}); |
600 | | - })['catch'](function (err) { // workaround IE8- syntax error for ".catch"(reserved keyword) |
| 572 | + }).catch(function (err) { |
601 | 573 | logError(err); |
602 | 574 | }); |
603 | 575 | } else if (handle.kind === handleKindDir) { |
|
632 | 604 |
|
633 | 605 | var files = []; |
634 | 606 | var hasDir = false; |
635 | | - if (!dataTransferItems || !dataTransferItems.length) return onDone(files, hasDir); |
636 | 607 |
|
637 | 608 | var items = Array.prototype.slice.call(dataTransferItems); |
638 | 609 | Promise.all(items.map(function (item) { |
|
698 | 669 |
|
699 | 670 | var files = []; |
700 | 671 | var hasDir = false; |
701 | | - if (!dataTransferItems || !dataTransferItems.length || !dataTransferItems[0].webkitGetAsEntry) return onDone(files, hasDir); |
702 | 672 |
|
703 | 673 | var entries = []; |
704 | 674 | for (var i = 0, len = dataTransferItems.length; i < len; i++) { |
|
798 | 768 | } |
799 | 769 | } |
800 | 770 |
|
801 | | - if (typeof fileInput.webkitdirectory === strUndef) { |
802 | | - uploadType.className += ' ' + classNone; |
803 | | - return; |
804 | | - } |
805 | 771 | optDirFile && optDirFile.classList.remove(classHidden); |
806 | 772 | optInnerDirFile && optInnerDirFile.classList.remove(classHidden); |
807 | 773 |
|
|
844 | 810 | return; |
845 | 811 | } |
846 | 812 | var files = e.target.files; |
847 | | - if (!files || !files.length) { |
| 813 | + if (!files.length) { |
848 | 814 | return; |
849 | 815 | } |
850 | 816 |
|
851 | 817 | var nodir = Array.prototype.slice.call(files).every(function (file) { |
852 | | - return !file.webkitRelativePath || file.webkitRelativePath.indexOf('/') < 0; |
| 818 | + return file.webkitRelativePath.indexOf('/') < 0; |
853 | 819 | }); |
854 | 820 | if (nodir) { |
855 | 821 | onClickOptFile(); // prevent clear input files |
|
879 | 845 | } |
880 | 846 |
|
881 | 847 | function enableUploadProgress() { // also fix Safari upload filename has no path info |
882 | | - if (typeof FormData === strUndef) { |
883 | | - return; |
884 | | - } |
885 | | - |
886 | 848 | var uploading = false; |
887 | 849 | var batches = []; |
888 | 850 | var classUploading = 'uploading'; |
|
932 | 894 | } |
933 | 895 |
|
934 | 896 | function uploadProgressively(files) { |
935 | | - if (!files || !files.length) { |
| 897 | + if (!files.length) { |
936 | 898 | return; |
937 | 899 | } |
938 | 900 |
|
|
1031 | 993 | e.currentTarget.classList.remove(classDragging); |
1032 | 994 | fileInput.value = ''; |
1033 | 995 |
|
1034 | | - if (!e.dataTransfer || !e.dataTransfer.files || !e.dataTransfer.files.length) { |
| 996 | + if (!e.dataTransfer.files.length) { |
1035 | 997 | return; |
1036 | 998 | } |
1037 | 999 |
|
1038 | | - dataTransferToFiles(e.dataTransfer, canMkdir && Boolean(uploadProgressively), function (files, hasDir) { |
| 1000 | + dataTransferToFiles(e.dataTransfer, canMkdir, function (files, hasDir) { |
1039 | 1001 | if (hasDir) { |
1040 | 1002 | switchToDirMode(); |
1041 | 1003 | uploadProgressively(files); |
1042 | 1004 | } else { |
1043 | 1005 | switchToFileMode(); |
1044 | | - if (uploadProgressively) { |
1045 | | - uploadProgressively(files); |
1046 | | - } else { |
1047 | | - fileInput.files = files; |
1048 | | - form.submit(); |
1049 | | - } |
| 1006 | + uploadProgressively(files); |
1050 | 1007 | } |
1051 | 1008 | }, function () { |
1052 | 1009 | typeof showUploadDirFailMessage !== strUndef && showUploadDirFailMessage(); |
|
1135 | 1092 | return; |
1136 | 1093 | } |
1137 | 1094 | var data = e.clipboardData; |
1138 | | - if (!data) { |
1139 | | - return; |
1140 | | - } |
1141 | 1095 |
|
1142 | 1096 | var items = data.items; |
1143 | | - if (!items || !items.length) { |
| 1097 | + if (!items.length) { |
1144 | 1098 | generatePastedFiles(data); |
1145 | 1099 | return; |
1146 | 1100 | } |
|
1174 | 1128 | }); |
1175 | 1129 | } |
1176 | 1130 |
|
1177 | | - function enableAddPasteFormSubmit() { |
1178 | | - document.documentElement.addEventListener('paste', function (e) { |
1179 | | - var data = e.clipboardData; |
1180 | | - if (data && data.files && data.files.length) { |
1181 | | - switchToFileMode(); |
1182 | | - fileInput.files = data.files; |
1183 | | - form.submit(); |
1184 | | - } |
1185 | | - }); |
1186 | | - } |
1187 | | - |
1188 | 1131 | enableAddDirFile(); |
1189 | 1132 | var uploadProgressively = enableUploadProgress(); |
1190 | | - if (uploadProgressively) { |
1191 | | - enableFormUploadProgress(uploadProgressively); |
1192 | | - enableAddPasteProgressively(uploadProgressively); |
1193 | | - } else { |
1194 | | - enableAddPasteFormSubmit(); |
1195 | | - } |
| 1133 | + enableFormUploadProgress(uploadProgressively); |
| 1134 | + enableAddPasteProgressively(uploadProgressively); |
1196 | 1135 | enableAddDragDrop(uploadProgressively); |
1197 | 1136 | } |
1198 | 1137 |
|
1199 | 1138 | function enableNonRefreshDelete() { |
1200 | | - if (!document.querySelector) { |
1201 | | - return; |
1202 | | - } |
1203 | | - |
1204 | 1139 | var itemList = document.body.querySelector('.item-list'); |
1205 | | - if (!itemList || !itemList.addEventListener) { |
1206 | | - return; |
1207 | | - } |
| 1140 | + if (!itemList) return; |
1208 | 1141 | if (!itemList.classList.contains('has-deletable')) return; |
1209 | 1142 |
|
1210 | 1143 | itemList.addEventListener('submit', function (e) { |
|
0 commit comments