-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpomf.min.js
164 lines (152 loc) · 4.79 KB
/
pomf.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
document.addEventListener("DOMContentLoaded", function () {
function a(a) {
var b = document.createElement("li"),
c = document.createElement("span");
(c.textContent = a.name), (c.className = "file-name");
var d = document.createElement("span");
(d.className = "progress-percent"), (d.textContent = "0%");
var e = document.createElement("progress");
return (
(e.className = "file-progress"),
e.setAttribute("max", "100"),
e.setAttribute("value", "0"),
b.appendChild(c),
b.appendChild(e),
b.appendChild(d),
document.getElementById("upload-filelist").appendChild(b),
b
);
}
function b(a) {
var b = a.target,
c = b.bar,
d = b.percent;
if (a.lengthComputable) {
var e = Math.floor((a.loaded / a.total) * 100);
c.setAttribute("value", e), (d.textContent = e + "%");
}
}
function c(a) {
var b = a.target,
c = b.bar,
d = b.row,
e = b.percent;
(e.style.visibility = "hidden"),
(c.style.visibility = "hidden"),
d.removeChild(c),
d.removeChild(e);
var f = b.status,
g = document.createElement("span");
(g.className = "file-url"), d.appendChild(g);
var h = document.createElement("a");
if (200 === f) {
var i = JSON.parse(b.responseText);
i.success
? ((h.textContent = i.files[0].url.replace(/.*?:\/\//g, "")),
(h.href = i.files[0].url),
g.appendChild(h))
: (c.innerHTML = "Error: " + i.description);
} else 413 === f ? ((h.textContent = "File Too big!"), g.appendChild(h)) : ((h.textContent = "Server error!"), g.appendChild(h));
}
function d(a, d) {
var e = d.querySelector(".file-progress"),
f = d.querySelector(".progress-percent"),
g = new XMLHttpRequest();
g.open("POST", "/upload.php"),
(g.row = d),
(g.bar = e),
(g.percent = f),
(g.upload.bar = e),
(g.upload.percent = f),
g.addEventListener("load", c, !1),
(g.upload.onprogress = b);
var h = new FormData();
h.append("files[]", a), g.send(h);
}
function e(a) {
a.stopPropagation(), a.preventDefault();
}
function f(a, b, c) {
e(c),
1 == a.dragCount && (b.textContent = "Drop it here~"),
(a.dragCount += 1);
}
function g(a, b, c) {
e(c),
(a.dragCount -= 1),
0 == a.dragCount && (b.textContent = "Select or drop file(s)");
}
function h(b, c, f) {
e(f), g(b, c, f);
for (var h = f.dataTransfer.files.length, i = 0; i < h; i++) {
var j = f.dataTransfer.files[i],
k = a(j);
d(j, k);
}
}
function i(b) {
for (var c = b.target.files.length, e = 0; e < c; e++) {
var f = b.target.files[e],
g = a(f);
d(f, g);
}
}
function j(a, b) {
e(b), a.click();
}
window.addEventListener("paste", function (b) {
var c = (b.clipboardData || b.originalEvent.clipboardData).items;
for (index in c) {
var e = c[index];
if ("file" === e.kind) {
var f = e.getAsFile(),
g = new File(
[f],
"pasted-image." + f.type.match(/(?:[^\/]*\/)([^;]*)/)[1]
);
g.type = f.type;
var h = a(g);
d(g, h);
}
}
});
var k = { dragCount: 0 },
l = document.getElementById("upload-btn");
window.addEventListener("dragenter", f.bind(this, k, l), !1),
window.addEventListener("dragleave", g.bind(this, k, l), !1),
window.addEventListener("drop", g.bind(this, k, l), !1),
window.addEventListener("dragover", e, !1);
var m = document.getElementById("upload-input");
m.addEventListener("change", i),
l.addEventListener("click", j.bind(this, m)),
l.addEventListener("drop", h.bind(this, k, l), !1),
document.getElementById("upload-form").classList.add("js");
});
window.onload = function () {
var anonF = document.getElementById("anonFalse");
anonF.onclick = function () {
SetAnonState(false);
};
var anonT = document.getElementById("anonTrue");
anonT.onclick = function () {
SetAnonState(true);
};
};
function SetAnonState(state) {
// If state is true then set IsAnon cookie to true, else set it to false
if (state) {
document.cookie = "IsAnon=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
} else {
document.cookie = "IsAnon=false; expires=Fri, 31 Dec 9999 23:59:59 GMT";
}
}
document.addEventListener("DOMContentLoaded", function () {
document.querySelector("#anonTrue").addEventListener("click", function () {
document.querySelector("#anonTrue").classList.add("active");
document.querySelector("#anonFalse").classList.remove("active");
});
document.querySelector("#anonFalse").addEventListener("click", function () {
document.querySelector("#anonFalse").classList.add("active");
document.querySelector("#anonTrue").classList.remove("active");
});
});