upload.min.js
5.32 KB
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
/*! UIkit 2.26.3 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
!function (e) {
var t;
window.UIkit && (t = e(UIkit)), "function" == typeof define && define.amd && define("uikit-upload", ["uikit"], function () {
return t || e(UIkit)
})
}(function (e) {
"use strict";
function t(o, a) {
function r(t, n) {
var o = new FormData, a = new XMLHttpRequest;
if (n.before(n, t) !== !1) {
for (var r, i = 0; r = t[i]; i++)o.append(n.param, r);
for (var l in n.params)o.append(l, n.params[l]);
a.upload.addEventListener("progress", function (e) {
var t = e.loaded / e.total * 100;
n.progress(t, e)
}, !1), a.addEventListener("loadstart", function (e) {
n.loadstart(e)
}, !1), a.addEventListener("load", function (e) {
n.load(e)
}, !1), a.addEventListener("loadend", function (e) {
n.loadend(e)
}, !1), a.addEventListener("error", function (e) {
n.error(e)
}, !1), a.addEventListener("abort", function (e) {
n.abort(e)
}, !1), a.open(n.method, n.action, !0), "json" == n.type && a.setRequestHeader("Accept", "application/json"), a.onreadystatechange = function () {
if (n.readystatechange(a), 4 == a.readyState) {
var t = a.responseText;
if ("json" == n.type)try {
t = e.$.parseJSON(t)
} catch (o) {
t = !1
}
n.complete(t, a)
}
}, n.beforeSend(a), a.send(o)
}
}
if (!e.support.ajaxupload)return this;
if (a = e.$.extend({}, t.defaults, a), o.length) {
if ("*.*" !== a.allow)for (var i, l = 0; i = o[l]; l++)if (!n(a.allow, i.name))return "string" == typeof a.notallowed ? alert(a.notallowed) : a.notallowed(i, a), void 0;
var s = a.complete;
if (a.single) {
var d = o.length, f = 0, p = !0;
a.beforeAll(o), a.complete = function (e, t) {
f += 1, s(e, t), a.filelimit && f >= a.filelimit && (p = !1), p && d > f ? r([o[f]], a) : a.allcomplete(e, t)
}, r([o[0]], a)
} else a.complete = function (e, t) {
s(e, t), a.allcomplete(e, t)
}, r(o, a)
}
}
function n(e, t) {
var n = "^" + e.replace(/\//g, "\\/").replace(/\*\*/g, "(\\/[^\\/]+)*").replace(/\*/g, "[^\\/]+").replace(/((?!\\))\?/g, "$1.") + "$";
return n = "^" + n + "$", null !== t.match(new RegExp(n, "i"))
}
return e.component("uploadSelect", {
init: function () {
var e = this;
this.on("change", function () {
t(e.element[0].files, e.options);
var n = e.element.clone(!0).data("uploadSelect", e);
e.element.replaceWith(n), e.element = n
})
}
}), e.component("uploadDrop", {
defaults: {dragoverClass: "uk-dragover"}, init: function () {
var e = this, n = !1;
this.on("drop", function (n) {
n.dataTransfer && n.dataTransfer.files && (n.stopPropagation(), n.preventDefault(), e.element.removeClass(e.options.dragoverClass), e.element.trigger("dropped.uk.upload", [n.dataTransfer.files]), t(n.dataTransfer.files, e.options))
}).on("dragenter", function (e) {
e.stopPropagation(), e.preventDefault()
}).on("dragover", function (t) {
t.stopPropagation(), t.preventDefault(), n || (e.element.addClass(e.options.dragoverClass), n = !0)
}).on("dragleave", function (t) {
t.stopPropagation(), t.preventDefault(), e.element.removeClass(e.options.dragoverClass), n = !1
})
}
}), e.support.ajaxupload = function () {
function e() {
var e = document.createElement("INPUT");
return e.type = "file", "files" in e
}
function t() {
var e = new XMLHttpRequest;
return !!(e && "upload" in e && "onprogress" in e.upload)
}
function n() {
return !!window.FormData
}
return e() && t() && n()
}(), e.support.ajaxupload && e.$.event.props.push("dataTransfer"), t.defaults = {
action: "",
single: !0,
method: "POST",
param: "files[]",
params: {},
allow: "*.*",
type: "text",
filelimit: !1,
before: function () {
},
beforeSend: function () {
},
beforeAll: function () {
},
loadstart: function () {
},
load: function () {
},
loadend: function () {
},
error: function () {
},
abort: function () {
},
progress: function () {
},
complete: function () {
},
allcomplete: function () {
},
readystatechange: function () {
},
notallowed: function (e, t) {
alert("Só é permitido arquivo no formato: " + t.allow)
}
}, e.Utils.xhrupload = t, t
});