From 91bff38f434c55b5e9e9fbd7e3414faf7c696d4c Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Thu, 23 Mar 2023 03:09:49 +0100 Subject: [PATCH] Add drag and drop filename support --- public/editor.js | 9 ++++++++- templates/base/gist_header.html | 2 +- templates/pages/edit.html | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) 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 }}