summaryrefslogtreecommitdiff
path: root/static/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/script.js')
-rw-r--r--static/script.js78
1 files changed, 0 insertions, 78 deletions
diff --git a/static/script.js b/static/script.js
deleted file mode 100644
index a579a3e..0000000
--- a/static/script.js
+++ /dev/null
@@ -1,78 +0,0 @@
1"use strict";
2
3(function () {
4 const dropZone = document.body;
5 if (!dropZone) {
6 return;
7 }
8
9 const hoverClassName = "hover";
10
11 // Handle drag* events to handle style
12 // Add the css you want when the class "hover" is present
13 dropZone.addEventListener("dragenter", function (e) {
14 e.preventDefault();
15 dropZone.classList.add(hoverClassName);
16 });
17
18 dropZone.addEventListener("dragover", function (e) {
19 e.preventDefault();
20 dropZone.classList.add(hoverClassName);
21 });
22
23 dropZone.addEventListener("dragleave", function (e) {
24 e.preventDefault();
25 dropZone.classList.remove(hoverClassName);
26 });
27
28 // Handle copy/paste
29 dropZone.addEventListener("paste", function (e) {
30 e.preventDefault();
31
32 if (e.clipboardData.items.length != 1) {
33 return
34 }
35
36 const item = e.clipboardData.items[0];
37 if (item.type.indexOf("image") == -1) {
38 return;
39 }
40
41 fetch('/', {
42 method: 'POST',
43 body: item.getAsFile(),
44 })
45 .then(response => response.text())
46 .then(body => { // Yes, this is ugly
47 document.open()
48 document.write(body)
49 document.close()
50 })
51
52 });
53
54 dropZone.addEventListener("drop", function (e) {
55 e.preventDefault();
56 dropZone.classList.remove(hoverClassName);
57
58 const files = Array.from(e.dataTransfer.files);
59 if (files.length != 1 ) {
60 return;
61 }
62 const data = new FormData();
63 for (const file of files) {
64 data.append('file', file);
65 }
66
67 fetch('/', {
68 method: 'POST',
69 body: data,
70 })
71 .then(response => response.text())
72 .then(body => { // Yes, this is ugly
73 document.open()
74 document.write(body)
75 document.close()
76 })
77 });
78})();