diff --git a/public/editor.js b/public/editor.js index aab8ad4..c859ea9 100644 --- a/public/editor.js +++ b/public/editor.js @@ -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 = () => { diff --git a/templates/base/gist_header.html b/templates/base/gist_header.html index 5b2952d..c5eb5cb 100644 --- a/templates/base/gist_header.html +++ b/templates/base/gist_header.html @@ -75,7 +75,7 @@ Edit -
+ {{ .csrfHtml }}
-
+ {{ .csrfHtml }}