mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-31 23:22:39 +00:00
Add drag and drop filename support
This commit is contained in:
parent
c71185d11e
commit
91bff38f43
3 changed files with 10 additions and 3 deletions
9
public/editor.js
vendored
9
public/editor.js
vendored
|
@ -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 = () => {
|
||||
|
|
2
templates/base/gist_header.html
vendored
2
templates/base/gist_header.html
vendored
|
@ -75,7 +75,7 @@
|
|||
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://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
|
|
2
templates/pages/edit.html
vendored
2
templates/pages/edit.html
vendored
|
@ -25,7 +25,7 @@
|
|||
{{ 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://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
|
|
Loading…
Reference in a new issue