diff options
author | Marvin Borner | 2019-04-07 17:17:17 +0200 |
---|---|---|
committer | Marvin Borner | 2019-04-07 17:17:17 +0200 |
commit | 5ec7ec5c50eeb3e2c281c0edfee6c74d7d512500 (patch) | |
tree | 071270805b5b2169d4aa26462647f9a5737b231e /src/main/resources/js/files.js | |
parent | 4e2024432ee680f98d91d07b050ac60151ebec4c (diff) |
Added drag and drop file upload
Diffstat (limited to 'src/main/resources/js/files.js')
-rw-r--r-- | src/main/resources/js/files.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js new file mode 100644 index 0000000..24140b0 --- /dev/null +++ b/src/main/resources/js/files.js @@ -0,0 +1,31 @@ +const drop = document.getElementById("drop"); + +drop.addEventListener('dragover', e => { + e.stopPropagation(); + e.preventDefault(); + e.dataTransfer.dropEffect = 'copy'; + drop.style.background = "rgba(12,99,250,0.3)"; +}); + +drop.addEventListener('dragleave', e => + drop.style.background = "white" +); + +drop.addEventListener('drop', e => { + // TODO: Fix directory uploading + e.stopPropagation(); + e.preventDefault(); + drop.style.background = "white"; + const files = e.dataTransfer.files; + + for (let i = 0; i < files.length; i++) { + let request = new XMLHttpRequest(); + let formData = new FormData(); + + drop.insertAdjacentHTML('beforeend', `<a class="filename" href="${files[i].name}">${files[i].name}</a><br><hr>`); + + formData.append("file", files[i]); + request.open("POST", "/upload/" + path); + request.send(formData); + } +}); |