Add drag and drop filename support

This commit is contained in:
Thomas Miceli
2023-03-23 03:09:49 +01:00
parent c71185d11e
commit 91bff38f43
3 changed files with 10 additions and 3 deletions

9
public/editor.js vendored
View File

@ -19,9 +19,12 @@ const newEditor = (dom, value = '') => {
})
}
const eventOnDrop = (e) => {
e.preventDefault(); // prevent the browser from opening the dropped file
e.target.closest('.editor').querySelector('input.form-filename').value = e.dataTransfer.files[0].name
}
document.onsubmit = () => {
console.log('onsubmit');
window.onbeforeunload = null;
}
@ -40,6 +43,8 @@ arr.forEach(el => {
}
});
currEditor.dom.addEventListener("drop", eventOnDrop);
// remove editor on delete
let deleteBtns = el.querySelector('button.delete-file')
if (deleteBtns !== null) {
@ -65,6 +70,8 @@ document.getElementById('add-file').onclick = () => {
// creating the new codemirror editor and append it in the editor div
editorsjs.push(newEditor(newEditorDom))
editorsParentdom.append(newEditorDom)
editorsParentdom.addEventListener("drop", eventOnDrop);
}
document.querySelector('form#create').onsubmit = () => {