ng-file-upload-shim.js 8.14 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2
/*! 12.2.13 */
!function () { function a(a, b) { window.XMLHttpRequest.prototype[a] = b(window.XMLHttpRequest.prototype[a]) } function b(a, b, c) { try { Object.defineProperty(a, b, { get: c }) } catch (d) { } } if (window.FileAPI || (window.FileAPI = {}), !window.XMLHttpRequest) throw "AJAX is not supported. XMLHttpRequest is not defined."; if (FileAPI.shouldLoad = !window.FormData || FileAPI.forceLoad, FileAPI.shouldLoad) { var c = function (a) { if (!a.__listeners) { a.upload || (a.upload = {}), a.__listeners = []; var b = a.upload.addEventListener; a.upload.addEventListener = function (c, d) { a.__listeners[c] = d, b && b.apply(this, arguments) } } }; a("open", function (a) { return function (b, d, e) { c(this), this.__url = d; try { a.apply(this, [b, d, e]) } catch (f) { f.message.indexOf("Access is denied") > -1 && (this.__origError = f, a.apply(this, [b, "_fix_for_ie_crossdomain__", e])) } } }), a("getResponseHeader", function (a) { return function (b) { return this.__fileApiXHR && this.__fileApiXHR.getResponseHeader ? this.__fileApiXHR.getResponseHeader(b) : null == a ? null : a.apply(this, [b]) } }), a("getAllResponseHeaders", function (a) { return function () { return this.__fileApiXHR && this.__fileApiXHR.getAllResponseHeaders ? this.__fileApiXHR.getAllResponseHeaders() : null == a ? null : a.apply(this) } }), a("abort", function (a) { return function () { return this.__fileApiXHR && this.__fileApiXHR.abort ? this.__fileApiXHR.abort() : null == a ? null : a.apply(this) } }), a("setRequestHeader", function (a) { return function (b, d) { if ("__setXHR_" === b) { c(this); var e = d(this); e instanceof Function && e(this) } else this.__requestHeaders = this.__requestHeaders || {}, this.__requestHeaders[b] = d, a.apply(this, arguments) } }), a("send", function (a) { return function () { var c = this; if (arguments[0] && arguments[0].__isFileAPIShim) { var d = arguments[0], e = { url: c.__url, jsonp: !1, cache: !0, complete: function (a, d) { a && angular.isString(a) && -1 !== a.indexOf("#2174") && (a = null), c.__completed = !0, !a && c.__listeners.load && c.__listeners.load({ type: "load", loaded: c.__loaded, total: c.__total, target: c, lengthComputable: !0 }), !a && c.__listeners.loadend && c.__listeners.loadend({ type: "loadend", loaded: c.__loaded, total: c.__total, target: c, lengthComputable: !0 }), "abort" === a && c.__listeners.abort && c.__listeners.abort({ type: "abort", loaded: c.__loaded, total: c.__total, target: c, lengthComputable: !0 }), void 0 !== d.status && b(c, "status", function () { return 0 === d.status && a && "abort" !== a ? 500 : d.status }), void 0 !== d.statusText && b(c, "statusText", function () { return d.statusText }), b(c, "readyState", function () { return 4 }), void 0 !== d.response && b(c, "response", function () { return d.response }); var e = d.responseText || (a && 0 === d.status && "abort" !== a ? a : void 0); b(c, "responseText", function () { return e }), b(c, "response", function () { return e }), a && b(c, "err", function () { return a }), c.__fileApiXHR = d, c.onreadystatechange && c.onreadystatechange(), c.onload && c.onload() }, progress: function (a) { if (a.target = c, c.__listeners.progress && c.__listeners.progress(a), c.__total = a.total, c.__loaded = a.loaded, a.total === a.loaded) { var b = this; setTimeout(function () { c.__completed || (c.getAllResponseHeaders = function () { }, b.complete(null, { status: 204, statusText: "No Content" })) }, FileAPI.noContentTimeout || 1e4) } }, headers: c.__requestHeaders }; e.data = {}, e.files = {}; for (var f = 0; f < d.data.length; f++) { var g = d.data[f]; null != g.val && null != g.val.name && null != g.val.size && null != g.val.type ? e.files[g.key] = g.val : e.data[g.key] = g.val } setTimeout(function () { if (!FileAPI.hasFlash) throw 'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"'; c.__fileApiXHR = FileAPI.upload(e) }, 1) } else { if (this.__origError) throw this.__origError; a.apply(c, arguments) } } }), window.XMLHttpRequest.__isFileAPIShim = !0, window.FormData = FormData = function () { return { append: function (a, b, c) { b.__isFileAPIBlobShim && (b = b.data[0]), this.data.push({ key: a, val: b, name: c }) }, data: [], __isFileAPIShim: !0 } }, window.Blob = Blob = function (a) { return { data: a, __isFileAPIBlobShim: !0 } } } }(), function () { function a(a) { return "input" === a[0].tagName.toLowerCase() && a.attr("type") && "file" === a.attr("type").toLowerCase() } function b() { try { var a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if (a) return !0 } catch (b) { if (void 0 !== navigator.mimeTypes["application/x-shockwave-flash"]) return !0 } return !1 } function c(a) { var b = 0, c = 0; if (window.jQuery) return jQuery(a).offset(); if (a.offsetParent) do b += a.offsetLeft - a.scrollLeft, c += a.offsetTop - a.scrollTop, a = a.offsetParent; while (a); return { left: b, top: c } } if (FileAPI.shouldLoad) { if (FileAPI.hasFlash = b(), FileAPI.forceLoad && (FileAPI.html5 = !1), !FileAPI.upload) { var d, e, f, g, h, i = document.createElement("script"), j = document.getElementsByTagName("script"); if (window.FileAPI.jsUrl) d = window.FileAPI.jsUrl; else if (window.FileAPI.jsPath) e = window.FileAPI.jsPath; else for (f = 0; f < j.length; f++) if (h = j[f].src, g = h.search(/\/ng\-file\-upload[\-a-zA-z0-9\.]*\.js/), g > -1) { e = h.substring(0, g + 1); break } null == FileAPI.staticPath && (FileAPI.staticPath = e), i.setAttribute("src", d || e + "FileAPI.min.js"), document.getElementsByTagName("head")[0].appendChild(i) } FileAPI.ngfFixIE = function (d, e, f) { if (!b()) throw 'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"'; var g = function () { var b = e.parent(); d.attr("disabled") ? b && b.removeClass("js-fileapi-wrapper") : (e.attr("__ngf_flash_") || (e.unbind("change"), e.unbind("click"), e.bind("change", function (a) { h.apply(this, [a]), f.apply(this, [a]) }), e.attr("__ngf_flash_", "true")), b.addClass("js-fileapi-wrapper"), a(d) || (b.css("position", "absolute").css("top", c(d[0]).top + "px").css("left", c(d[0]).left + "px").css("width", d[0].offsetWidth + "px").css("height", d[0].offsetHeight + "px").css("filter", "alpha(opacity=0)").css("display", d.css("display")).css("overflow", "hidden").css("z-index", "900000").css("visibility", "visible"), e.css("width", d[0].offsetWidth + "px").css("height", d[0].offsetHeight + "px").css("position", "absolute").css("top", "0px").css("left", "0px"))) }; d.bind("mouseenter", g); var h = function (a) { for (var b = FileAPI.getFiles(a), c = 0; c < b.length; c++) void 0 === b[c].size && (b[c].size = 0), void 0 === b[c].name && (b[c].name = "file"), void 0 === b[c].type && (b[c].type = "undefined"); a.target || (a.target = {}), a.target.files = b, a.target.files !== b && (a.__files_ = b), (a.__files_ || a.target.files).item = function (b) { return (a.__files_ || a.target.files)[b] || null } } }, FileAPI.disableFileInput = function (a, b) { b ? a.removeClass("js-fileapi-wrapper") : a.addClass("js-fileapi-wrapper") } } }(), window.FileReader || (window.FileReader = function () { var a = this, b = !1; this.listeners = {}, this.addEventListener = function (b, c) { a.listeners[b] = a.listeners[b] || [], a.listeners[b].push(c) }, this.removeEventListener = function (b, c) { a.listeners[b] && a.listeners[b].splice(a.listeners[b].indexOf(c), 1) }, this.dispatchEvent = function (b) { var c = a.listeners[b.type]; if (c) for (var d = 0; d < c.length; d++) c[d].call(a, b) }, this.onabort = this.onerror = this.onload = this.onloadstart = this.onloadend = this.onprogress = null; var c = function (b, c) { var d = { type: b, target: a, loaded: c.loaded, total: c.total, error: c.error }; return null != c.result && (d.target.result = c.result), d }, d = function (d) { b || (b = !0, a.onloadstart && a.onloadstart(c("loadstart", d))); var e; "load" === d.type ? (a.onloadend && a.onloadend(c("loadend", d)), e = c("load", d), a.onload && a.onload(e), a.dispatchEvent(e)) : "progress" === d.type ? (e = c("progress", d), a.onprogress && a.onprogress(e), a.dispatchEvent(e)) : (e = c("error", d), a.onerror && a.onerror(e), a.dispatchEvent(e)) }; this.readAsDataURL = function (a) { FileAPI.readAsDataURL(a, d) }, this.readAsText = function (a) { FileAPI.readAsText(a, d) } });