()
| 1768 | Main initUpload: Sets up file input, drop area, and form submission. |
| 1769 | ----------------------------------------------------- */ |
| 1770 | function initUpload() { |
| 1771 | window.__FR_FLAGS = window.__FR_FLAGS || { wired: {} }; |
| 1772 | window.__FR_FLAGS.wired = window.__FR_FLAGS.wired || {}; |
| 1773 | |
| 1774 | const uploadForm = document.getElementById("uploadFileForm"); |
| 1775 | const dropArea = document.getElementById("uploadDropArea"); |
| 1776 | |
| 1777 | // Always (re)build the inner markup and wire the Choose button |
| 1778 | setDropAreaDefault(); |
| 1779 | wireChooseButton(); |
| 1780 | |
| 1781 | const fileInput = document.getElementById("file"); |
| 1782 | |
| 1783 | // For file picker, remove directory attributes so only files can be chosen. |
| 1784 | if (fileInput) { |
| 1785 | fileInput.removeAttribute("webkitdirectory"); |
| 1786 | fileInput.removeAttribute("mozdirectory"); |
| 1787 | fileInput.removeAttribute("directory"); |
| 1788 | fileInput.setAttribute("multiple", ""); |
| 1789 | } |
| 1790 | |
| 1791 | // Drag–and–drop events use Resumable when available, XHR as fallback. |
| 1792 | if (dropArea && !dropArea.__uploadBound) { |
| 1793 | dropArea.__uploadBound = true; |
| 1794 | dropArea.classList.add("upload-drop-area"); |
| 1795 | |
| 1796 | dropArea.addEventListener("dragover", function (e) { |
| 1797 | e.preventDefault(); |
| 1798 | dropArea.style.backgroundColor = document.body.classList.contains("dark-mode") ? "#333" : "#f8f8f8"; |
| 1799 | }); |
| 1800 | |
| 1801 | dropArea.addEventListener("dragleave", function (e) { |
| 1802 | e.preventDefault(); |
| 1803 | dropArea.style.backgroundColor = ""; |
| 1804 | }); |
| 1805 | |
| 1806 | dropArea.addEventListener("drop", function (e) { |
| 1807 | e.preventDefault(); |
| 1808 | dropArea.style.backgroundColor = ""; |
| 1809 | const dt = e.dataTransfer || window.__pendingDropData || null; |
| 1810 | window.__pendingDropData = null; |
| 1811 | if (dt && dt.items && dt.items.length > 0) { |
| 1812 | getFilesFromDataTransferItems(dt.items).then(files => { |
| 1813 | if (files.length > 0) { |
| 1814 | queueResumableFiles(files); |
| 1815 | } |
| 1816 | }); |
| 1817 | } else if (dt && dt.files && dt.files.length > 0) { |
| 1818 | queueResumableFiles(Array.from(dt.files)); |
| 1819 | } |
| 1820 | }); |
| 1821 | |
| 1822 | // Only trigger file picker when clicking the *bare* drop area, not controls inside it |
| 1823 | dropArea.addEventListener("click", function (e) { |
| 1824 | // If the click originated from the "Choose files" button or the file input itself, |
| 1825 | // let their handlers deal with it. |
| 1826 | if (e.target.closest('#customChooseBtn') || e.target.closest('#file')) { |
| 1827 | return; |
no test coverage detected