Skip to content

Commit b9a6717

Browse files
committed
Add drag-and-drop to new file attachment button
1 parent 5e2513e commit b9a6717

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

templates/index.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% include "header.html" %}
22

3-
<form action="upload" method="POST" enctype="multipart/form-data">
3+
<form id="pasta-form" action="upload" method="POST" enctype="multipart/form-data">
44
<br>
55
<div id="settings">
66
<div>
@@ -158,18 +158,14 @@
158158
</div>
159159
{%- endif %}
160160
</div>
161-
162-
163-
164-
165161
</div>
166162
<label>Content</label>
167163
<textarea style="width: 100%; min-height: 100px; margin-bottom: 2em" name="content" autofocus></textarea>
168164
<div style="overflow:auto;">
169165
{% if !args.no_file_upload %}
170166
<div style="float: left">
171-
<label for="file" id="attach-file-button-label"><a role="button" id="attach-file-button">Attach
172-
File</a></label>
167+
<label for="file" id="attach-file-button-label"><a role="button" id="attach-file-button">Select or drop
168+
file attachment</a></label>
173169
<br>
174170
<input type="file" id="file" name="file" />
175171
</div>
@@ -190,10 +186,29 @@
190186
<script>
191187
const hiddenFileButton = document.getElementById('file');
192188
const attachFileButton = document.getElementById('attach-file-button');
189+
const dropContainer = document.getElementById('pasta-form');
193190

194191
hiddenFileButton.addEventListener('change', function () {
195192
attachFileButton.textContent = "Attached: " + this.files[0].name;
196-
})
193+
});
194+
195+
dropContainer.ondragover = dropContainer.ondragenter = function (evt) {
196+
evt.preventDefault();
197+
if (hiddenFileButton.files.length == 0) {
198+
attachFileButton.textContent = "Drop your file here";
199+
} else {
200+
attachFileButton.textContent = "Drop your file here to replace " + hiddenFileButton.files[0].name;
201+
}
202+
};
203+
204+
dropContainer.ondrop = function (evt) {
205+
const dataTransfer = new DataTransfer();
206+
dataTransfer.items.add(evt.dataTransfer.files[0]);
207+
hiddenFileButton.files = dataTransfer.files;
208+
attachFileButton.textContent = "Attached: " + hiddenFileButton.files[0].name;
209+
evt.preventDefault();
210+
};
211+
197212
</script>
198213

199214
<style>

0 commit comments

Comments
 (0)