|
1 | 1 | {% include "header.html" %} |
2 | 2 |
|
3 | | -<form action="upload" method="POST" enctype="multipart/form-data"> |
| 3 | +<form id="pasta-form" action="upload" method="POST" enctype="multipart/form-data"> |
4 | 4 | <br> |
5 | 5 | <div id="settings"> |
6 | 6 | <div> |
|
158 | 158 | </div> |
159 | 159 | {%- endif %} |
160 | 160 | </div> |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | 161 | </div> |
166 | 162 | <label>Content</label> |
167 | 163 | <textarea style="width: 100%; min-height: 100px; margin-bottom: 2em" name="content" autofocus></textarea> |
168 | 164 | <div style="overflow:auto;"> |
169 | 165 | {% if !args.no_file_upload %} |
170 | 166 | <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> |
173 | 169 | <br> |
174 | 170 | <input type="file" id="file" name="file" /> |
175 | 171 | </div> |
|
190 | 186 | <script> |
191 | 187 | const hiddenFileButton = document.getElementById('file'); |
192 | 188 | const attachFileButton = document.getElementById('attach-file-button'); |
| 189 | + const dropContainer = document.getElementById('pasta-form'); |
193 | 190 |
|
194 | 191 | hiddenFileButton.addEventListener('change', function () { |
195 | 192 | 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 | + |
197 | 212 | </script> |
198 | 213 |
|
199 | 214 | <style> |
|
0 commit comments