Skip to content

Commit

Permalink
Add drag and drop filename support
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed Mar 23, 2023
1 parent c71185d commit 91bff38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion public/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion templates/base/gist_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h1 class="text-2xl font-bold leading-tight break-all">
Edit
</a>
</div>
<form id="delete" onsubmit="alert('Are you sure you want to delete this gist ?')" class="ml-2 flex items-center" method="post" action="/{{ .gist.User.Username }}/{{ .gist.Uuid }}/delete">
<form id="delete" onsubmit="return confirm('Are you sure you want to delete this gist ?')" class="ml-2 flex items-center" method="post" action="/{{ .gist.User.Username }}/{{ .gist.Uuid }}/delete">
{{ .csrfHtml }}
<button type="submit" class="relative inline-flex items-center space-x-2 rounded-md border border-gray-600 bg-gray-800 px-2 py-1.5 text-xs font-medium text-rose-400 hover:bg-rose-700 hover:border-rose-600 hover:text-slate-300 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500">
<svg xmlns="http:https://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="text-2xl font-bold leading-tight text-slate-300">
{{ end }}
</button>
</form>
<form id="delete" onsubmit="alert('Are you sure you want to delete this gist ?')" class="ml-2 flex items-center" method="post" action="/{{ .gist.User.Username }}/{{ .gist.Uuid }}/delete">
<form id="delete" onsubmit="return confirm('Are you sure you want to delete this gist ?')" class="ml-2 flex items-center" method="post" action="/{{ .gist.User.Username }}/{{ .gist.Uuid }}/delete">
{{ .csrfHtml }}
<button type="submit" class="relative inline-flex items-center space-x-2 rounded-md border border-gray-600 bg-gray-800 px-2 py-1.5 text-xs font-medium text-rose-400 hover:bg-rose-700 hover:border-rose-600 hover:text-slate-300 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500">
<svg xmlns="http:https://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
Expand Down

0 comments on commit 91bff38

Please sign in to comment.