META-INF.resources.scripts.vendor.plugins.plupload.js.plupload.min.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lightadmin Show documentation
Show all versions of lightadmin Show documentation
Pluggable data management solution for Java web applications developed in a "Rapid" manner
/**
* Plupload - multi-runtime File Uploader
* v2.0.0beta
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Date: 2012-11-30
*/
;
(function (e, t, n) {
function s(e) {
function r(e, t, r) {
var i = {chunks: "slice_blob", resize: "send_binary_string", jpgresize: "send_binary_string", pngresize: "send_binary_string", progress: "report_upload_progress", multi_selection: "select_multiple", max_file_size: "access_binary", dragdrop: "drag_and_drop", drop_element: "drag_and_drop", headers: "send_custom_headers", canSendBinary: "send_binary", triggerDialog: "summon_file_dialog"};
i[e] ? n[i[e]] = t : r || (n[e] = t)
}
var t = e.required_features, n = {};
return typeof t == "string" ? o.each(t.split(/\s*,\s*/), function (e) {
r(e, !0)
}) : typeof t == "object" ? o.each(t, function (e, t) {
r(t, e)
}) : t === !0 && (e.multipart || (n.send_binary_string = !0), e.chunk_size > 0 && (n.slice_blob = !0), o.each(e, function (e, t) {
r(t, !!e, !0)
})), n
}
var r = e.setTimeout, i = {}, o = {VERSION: "2.0.0beta", STOPPED: 1, STARTED: 2, QUEUED: 1, UPLOADING: 2, FAILED: 4, DONE: 5, GENERIC_ERROR: -100, HTTP_ERROR: -200, IO_ERROR: -300, SECURITY_ERROR: -400, INIT_ERROR: -500, FILE_SIZE_ERROR: -600, FILE_EXTENSION_ERROR: -601, FILE_DUPLICATE_ERROR: -602, IMAGE_FORMAT_ERROR: -700, IMAGE_MEMORY_ERROR: -701, IMAGE_DIMENSIONS_ERROR: -702, mimeTypes: t.mimes, ua: t.ua, typeOf: t.typeOf, extend: t.extend, guid: t.guid, each: t.each, getPos: t.getPos, getSize: t.getSize, xmlEncode: function (e) {
var t = {"<": "lt", ">": "gt", "&": "amp", '"': "quot", "'": "#39"}, n = /[<>&\"\']/g;
return e ? ("" + e).replace(n, function (e) {
return t[e] ? "&" + t[e] + ";" : e
}) : e
}, toArray: t.toArray, inArray: t.inArray, addI18n: t.addI18n, translate: t.translate, isEmptyObj: t.isEmptyObj, hasClass: t.hasClass, addClass: t.addClass, removeClass: t.removeClass, getStyle: t.getStyle, addEvent: t.addEvent, removeEvent: t.removeEvent, removeAllEvents: t.removeAllEvents, cleanName: function (e) {
var t, n;
n = [/[\300-\306]/g, "A", /[\340-\346]/g, "a", /\307/g, "C", /\347/g, "c", /[\310-\313]/g, "E", /[\350-\353]/g, "e", /[\314-\317]/g, "I", /[\354-\357]/g, "i", /\321/g, "N", /\361/g, "n", /[\322-\330]/g, "O", /[\362-\370]/g, "o", /[\331-\334]/g, "U", /[\371-\374]/g, "u"];
for (t = 0; t < n.length; t += 2)e = e.replace(n[t], n[t + 1]);
return e = e.replace(/\s+/g, "_"), e = e.replace(/[^a-z0-9_\-\.]+/gi, ""), e
}, buildUrl: function (e, t) {
var n = "";
return o.each(t, function (e, t) {
n += (n ? "&" : "") + encodeURIComponent(t) + "=" + encodeURIComponent(e)
}), n && (e += (e.indexOf("?") > 0 ? "&" : "?") + n), e
}, formatSize: function (e) {
return e === n || /\D/.test(e) ? o.translate("N/A") : e > 1099511627776 ? Math.round(e / 1099511627776, 1) + " " + o.translate("tb") : e > 1073741824 ? Math.round(e / 1073741824, 1) + " " + o.translate("gb") : e > 1048576 ? Math.round(e / 1048576, 1) + " " + o.translate("mb") : e > 1024 ? Math.round(e / 1024, 1) + " " + o.translate("kb") : e + " " + o.translate("b")
}, parseSize: t.parseSizeStr, predictRuntime: function (e, t) {
var n, r;
return t && (e.runtimes = t), n = new o.Uploader(e), r = n.runtime, n.destroy(), r
}, addFileFilter: function (e, t) {
i[e] = t
}};
o.addFileFilter("mime_types", function () {
function n(e) {
var t = [];
return o.each(e, function (e) {
o.each(e.extensions.split(/,/), function (e) {
/^\s*\*\s*$/.test(e) ? t.push("\\.*") : t.push("\\." + e.replace(new RegExp("[" + "/^$.*+?|()[]{}\\".replace(/./g, "\\$&") + "]", "g"), "\\$&"))
})
}), new RegExp("(" + t.join("|") + ")$", "i")
}
var e, t;
return function (r, i, s) {
if (!t || r != e)t = n(r), e = [].slice.call(r);
t.test(i.name) ? s(!0) : (this.trigger("Error", {code: o.FILE_EXTENSION_ERROR, message: o.translate("File extension error."), file: i}), s(!1))
}
}()), o.addFileFilter("max_file_size", function (e, t, n) {
var r;
t.size !== r && e && t.size > e ? (this.trigger("Error", {code: o.FILE_SIZE_ERROR, message: o.translate("File size error."), file: t}), n(!1)) : n(!0)
}), o.addFileFilter("prevent_duplicates", function (e, t, n) {
if (e) {
var r = this.files.length;
while (r--)if (t.name === this.files[r].name && t.size === this.files[r].size) {
this.trigger("Error", {code: o.FILE_DUPLICATE_ERROR, message: o.translate("Duplicate file error."), file: t}), n(!1);
return
}
}
n(!0)
}), o.Uploader = function (e) {
function m() {
var e, t = 0, n;
if (this.state == o.STARTED) {
for (n = 0; n < u.length; n++)!e && u[n].status == o.QUEUED ? (e = u[n], this.trigger("BeforeUpload", e) && (e.status = o.UPLOADING, this.trigger("UploadFile", e))) : t++;
t == u.length && (this.state !== o.STOPPED && (this.state = o.STOPPED, this.trigger("StateChanged")), this.trigger("UploadComplete", u))
}
}
function g(e) {
e.percent = e.size > 0 ? Math.ceil(e.loaded / e.size * 100) : 100, y()
}
function y() {
var e, t;
c.reset();
for (e = 0; e < u.length; e++)t = u[e], t.size !== n ? (c.size += t.origSize, c.loaded += t.loaded * t.origSize / t.size) : c.size = n, t.status == o.DONE ? c.uploaded++ : t.status == o.FAILED ? c.failed++ : c.queued++;
c.size === n ? c.percent = u.length > 0 ? Math.ceil(c.uploaded / u.length * 100) : 0 : (c.bytesPerSec = Math.ceil(c.loaded / ((+(new Date) - l || 1) / 1e3)), c.percent = c.size > 0 ? Math.ceil(c.loaded / c.size * 100) : 0)
}
function b() {
var n = this, r = 0, i = {accept: e.filters.mime_types, runtime_order: e.runtimes, required_caps: f, swf_url: e.flash_swf_url, xap_url: e.silverlight_xap_url};
o.each(e.runtimes.split(/\s*,\s*/), function (t) {
e[t] && (i[t] = e[t])
}), t.inSeries([function (s) {
e.browse_button ? (p = new t.FileInput(o.extend({}, i, {name: e.file_data_name, multiple: e.multi_selection, container: e.container, browse_button: e.browse_button})), p.onready = function () {
var e = t.Runtime.getInfo(this.ruid);
t.extend(n.features, {chunks: e.can("slice_blob"), multipart: e.can("send_multipart"), multi_selection: e.can("select_multiple")}), r++, s()
}, p.onchange = function () {
n.addFile(this.files)
}, p.bind("mouseenter mouseleave mousedown mouseup", function (n) {
if (!h) {
var r = t.get(e.browse_button);
r && (e.browse_button_hover && ("mouseenter" === n.type ? t.addClass(r, e.browse_button_hover) : "mouseleave" === n.type && t.removeClass(r, e.browse_button_hover)), e.browse_button_active && ("mousedown" === n.type ? t.addClass(r, e.browse_button_active) : "mouseup" === n.type && t.removeClass(r, e.browse_button_active)), r = null)
}
}), p.bind("error runtimeerror", function () {
p = null, s()
}), p.init()) : s()
}, function (s) {
e.drop_element ? (d = new t.FileDrop(o.extend({}, i, {drop_zone: e.drop_element})), d.onready = function () {
var e = t.Runtime.getInfo(this.ruid);
n.features.dragdrop = e.can("drag_and_drop"), r++, s()
}, d.ondrop = function () {
n.addFile(this.files)
}, d.bind("error runtimeerror", function () {
d = null, s()
}), d.init()) : s()
}], function () {
typeof e.init == "function" ? e.init(n) : o.each(e.init, function (e, t) {
n.bind(t, e)
}), r ? n.trigger("PostInit") : n.trigger("Error", {code: o.INIT_ERROR, message: o.translate("Init error.")})
})
}
function w(e, n) {
if (e.ruid) {
var r = t.Runtime.getInfo(e.ruid);
if (r)return r.can(n)
}
return!1
}
function E(e, n, r) {
var i = new t.Image;
try {
i.onload = function () {
i.downsize(n.width, n.height, n.crop, n.preserve_headers)
}, i.onresize = function () {
r(this.getAsBlob(e.type, n.quality)), this.destroy()
}, i.onerror = function () {
r(e)
}, i.load(e)
} catch (s) {
r(e)
}
}
var u = [], a = {}, f = {}, l, c, h = !1, p, d, v;
c = new o.QueueProgress, e = o.extend({runtimes: t.Runtime.order, max_retries: 0, multipart: !0, multi_selection: !0, file_data_name: "file", flash_swf_url: "js/Moxie.swf", silverlight_xap_url: "js/Moxie.xap", send_chunk_number: !0}, e), e.resize && (e.resize = o.extend({preserve_headers: !0, crop: !1}, e.resize)), o.typeOf(e.filters) === "array" && (e.filters = {mime_types: e.filters}), e.filters = o.extend({mime_types: [], prevent_duplicates: !!e.prevent_duplicates, max_file_size: e.max_file_size}, e.filters), e.filters.max_file_size = o.parseSize(e.filters.max_file_size) || 0, e.chunk_size = o.parseSize(e.chunk_size) || 0, e.required_features = f = s(o.extend({}, e)), o.extend(this, {id: o.guid(), state: o.STOPPED, features: {}, runtime: t.Runtime.thatCan(f, e.runtimes), files: u, settings: e, total: c, init: function () {
var n = this;
e.browse_button = t.get(e.browse_button), e.drop_element = t.get(e.drop_element), typeof e.preinit == "function" ? e.preinit(n) : o.each(e.preinit, function (e, t) {
n.bind(t, e)
});
if (!e.browse_button || !e.url) {
this.trigger("Error", {code: o.INIT_ERROR, message: o.translate("Init error.")});
return
}
n.bind("FilesAdded", function (e, t) {
[].push.apply(u, t), r(function () {
n.trigger("QueueChanged"), n.refresh()
}, 1)
}), n.bind("CancelUpload", function () {
v && v.abort()
}), e.unique_names && n.bind("BeforeUpload", function (e, t) {
var n = t.name.match(/\.([^.]+)$/), r = "part";
n && (r = n[1]), t.target_name = t.id + "." + r
}), n.bind("UploadFile", function (n, i) {
function p() {
l-- > 0 ? r(d, 1) : (i.loaded = h, n.trigger("Error", {code: o.HTTP_ERROR, message: o.translate("HTTP Error."), file: i, response: v.responseText, status: v.status, responseHeaders: v.getAllResponseHeaders()}))
}
function d() {
var l, m, g, y;
if (i.status == o.DONE || i.status == o.FAILED || n.state == o.STOPPED)return;
g = {name: i.target_name || i.name}, a && u.chunks && c.size > a ? (y = Math.min(a, c.size - h), l = c.slice(h, h + y)) : (y = c.size, l = c), a && u.chunks && (e.send_chunk_number ? (g.chunk = Math.ceil(h / a), g.chunks = Math.ceil(c.size / a)) : (g.offset = h, g.total = c.size)), v = new t.XMLHttpRequest, v.upload && (v.upload.onprogress = function (e) {
i.loaded = Math.min(i.size, h + e.loaded), n.trigger("UploadProgress", i)
}), v.onload = function () {
if (v.status >= 400) {
p();
return
}
y < c.size ? (l.destroy(), h += y, i.loaded = Math.min(h, c.size), n.trigger("ChunkUploaded", i, {offset: i.loaded, total: c.size, response: v.responseText, status: v.status, responseHeaders: v.getAllResponseHeaders()}), t.Env.browser === "Android Browser" && n.trigger("UploadProgress", i)) : i.loaded = i.size, l = m = null, !h || h >= c.size ? (i.size != i.origSize && (c.destroy(), c = null), n.trigger("UploadProgress", i), i.status = o.DONE, n.trigger("FileUploaded", i, {response: v.responseText, status: v.status, responseHeaders: v.getAllResponseHeaders()})) : r(d, 1)
}, v.onerror = function () {
p()
}, v.onloadend = function () {
this.destroy(), v = null
}, n.settings.multipart && u.multipart ? (g.name = i.target_name || i.name, v.open("post", s, !0), o.each(n.settings.headers, function (e, t) {
v.setRequestHeader(t, e)
}), m = new t.FormData, o.each(o.extend(g, n.settings.multipart_params), function (e, t) {
m.append(t, e)
}), m.append(n.settings.file_data_name, l), v.send(m, {runtime_order: n.settings.runtimes, required_caps: f, swf_url: n.settings.flash_swf_url, xap_url: n.settings.silverlight_xap_url})) : (s = o.buildUrl(n.settings.url, o.extend(g, n.settings.multipart_params)), v.open("post", s, !0), v.setRequestHeader("Content-Type", "application/octet-stream"), o.each(n.settings.headers, function (e, t) {
v.setRequestHeader(t, e)
}), v.send(l, {runtime_order: n.settings.runtimes, required_caps: f, swf_url: n.settings.flash_swf_url, xap_url: n.settings.silverlight_xap_url}))
}
var s = n.settings.url, u = n.features, a = e.chunk_size, l = e.max_retries, c, h = 0;
i.loaded && (h = i.loaded = a * Math.floor(i.loaded / a)), c = i.getSource(), !t.isEmptyObj(n.settings.resize) && w(c, "send_binary_string") && !!~t.inArray(c.type, ["image/jpeg", "image/png"]) ? E.call(this, c, n.settings.resize, function (e) {
c = e, i.size = e.size, d()
}) : d()
}), n.bind("UploadProgress", function (e, t) {
g(t)
}), n.bind("StateChanged", function (e) {
if (e.state == o.STARTED)l = +(new Date); else if (e.state == o.STOPPED)for (var t = e.files.length - 1; t >= 0; t--)e.files[t].status == o.UPLOADING && (e.files[t].status = o.QUEUED, y())
}), n.bind("QueueChanged", y), n.bind("Error", function (e, t) {
t.file && (t.file.status = o.FAILED, g(t.file), e.state == o.STARTED && r(function () {
m.call(n)
}, 1))
}), n.bind("FileUploaded", function () {
y(), r(function () {
m.call(n)
}, 1)
}), n.trigger("Init", {runtime: this.runtime}), b.call(this)
}, refresh: function () {
p && p.trigger("Refresh"), this.trigger("Refresh")
}, start: function () {
this.state != o.STARTED && (this.state = o.STARTED, this.trigger("StateChanged"), m.call(this))
}, stop: function () {
this.state != o.STOPPED && (this.state = o.STOPPED, this.trigger("StateChanged"), this.trigger("CancelUpload"))
}, disableBrowse: function () {
h = arguments[0] !== n ? arguments[0] : !0, p && p.disable(h), this.trigger("DisableBrowse", h)
}, getFile: function (e) {
var t;
for (t = u.length - 1; t >= 0; t--)if (u[t].id === e)return u[t]
}, addFile: function (e, n) {
function f() {
var e = d || p;
return e ? e.getRuntime().uid : !1
}
function l(e, n) {
var s = [];
t.each(r.settings.filters, function (t, n) {
i[n] && s.push(function (s) {
i[n].call(r, t, e, function (e) {
s(!e)
})
})
}), t.inSeries(s, n)
}
function c(e) {
var r = t.typeOf(e);
if (e instanceof t.File) {
if (!e.ruid && !e.isDetached()) {
if (!a)return!1;
e.ruid = a, e.connectRuntime(a)
}
c(new o.File(e))
} else e instanceof t.Blob ? (c(e.getSource()), e.destroy()) : e instanceof o.File ? (n && (e.name = n), s.push(function (t) {
l(e, function (n) {
n || u.push(e), t()
})
})) : t.inArray(r, ["file", "blob"]) !== -1 ? c(new t.File(null, e)) : r === "node" && t.typeOf(e.files) === "filelist" ? t.each(e.files, c) : r === "array" && (n = null, t.each(e, c))
}
var r = this, s = [], u = [], a;
a = f(), c(e), s.length && t.inSeries(s, function () {
u.length && r.trigger("FilesAdded", u)
})
}, removeFile: function (e) {
var t = typeof e == "string" ? e : e.id;
for (var n = u.length - 1; n >= 0; n--)if (u[n].id === t)return this.splice(n, 1)[0]
}, splice: function (e, t) {
var r = u.splice(e === n ? 0 : e, t === n ? u.length : t);
return this.trigger("FilesRemoved", r), this.trigger("QueueChanged"), o.each(r, function (e) {
e.destroy()
}), r
}, trigger: function (e) {
var t = a[e.toLowerCase()], n, r;
if (t) {
r = Array.prototype.slice.call(arguments), r[0] = this;
for (n = 0; n < t.length; n++)if (t[n].func.apply(t[n].scope, r) === !1)return!1
}
return!0
}, hasEventListener: function (e) {
return!!a[e.toLowerCase()]
}, bind: function (e, t, n) {
var r;
e = e.toLowerCase(), r = a[e] || [], r.push({func: t, scope: n || this}), a[e] = r
}, unbind: function (e) {
e = e.toLowerCase();
var t = a[e], r, i = arguments[1];
if (t) {
if (i !== n) {
for (r = t.length - 1; r >= 0; r--)if (t[r].func === i) {
t.splice(r, 1);
break
}
} else t = [];
t.length || delete a[e]
}
}, unbindAll: function () {
var e = this;
o.each(a, function (t, n) {
e.unbind(n)
})
}, destroy: function () {
this.stop(), o.each(u, function (e) {
e.destroy()
}), u = [], p && (p.destroy(), p = null), d && (d.destroy(), d = null), f = {}, l = c = h = v = null, this.trigger("Destroy"), this.unbindAll(), a = {}
}})
}, o.File = function () {
function n(n) {
o.extend(this, {id: o.guid(), name: n.name || n.fileName, type: n.type || "", size: n.size || n.fileSize, origSize: n.size || n.fileSize, loaded: 0, percent: 0, status: o.QUEUED, lastModifiedDate: n.lastModifiedDate || (new Date).toLocaleString(), getNative: function () {
var e = this.getSource().getSource();
return t.inArray(t.typeOf(e), ["blob", "file"]) !== -1 ? e : null
}, getSource: function () {
return e[this.id] ? e[this.id] : null
}, destroy: function () {
var t = this.getSource();
t && (t.destroy(), delete e[this.id])
}}), e[this.id] = n
}
var e = {};
return n
}(), o.QueueProgress = function () {
var e = this;
e.size = 0, e.loaded = 0, e.uploaded = 0, e.failed = 0, e.queued = 0, e.percent = 0, e.bytesPerSec = 0, e.reset = function () {
e.size = e.loaded = e.uploaded = e.failed = e.queued = e.percent = e.bytesPerSec = 0
}
}, e.plupload = o
})(window, mOxie);