forked from danialfarid/ng-file-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-file-upload-shim.min.js
12 lines (12 loc) · 3.48 KB
/
angular-file-upload-shim.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/**!
* AngularJS file upload shim for HTML5 FormData
* @author Danial <danial.farid@gmail.com>
* @version 1.1.5
*/
(function(){window.XMLHttpRequest&&(XMLHttpRequest=window.FormData?function(c){return function(){var a=new c;a.send=function(c){return function(){arguments[0]instanceof FormData&&arguments[0].__setXHR_&&arguments[0].__setXHR_(a);c.apply(a,arguments)}}(a.send);return a}}(XMLHttpRequest):function(c){return function(){var a=new c,g=a.send;a.__requestHeaders=[];a.open=function(b){a.upload={addEventListener:function(b,d,c){"progress"==b&&(a.__progress=d)}};return function(f,d,c){b.apply(a,[f,d,c]);a.__url=
d}}(a.open);a.getResponseHeader=function(b){return function(c){return a.__fileApiXHR?a.__fileApiXHR.getResponseHeader(c):b.apply(a,[c])}}(a.getResponseHeader);a.getAllResponseHeaders=function(b){return function(){return a.__fileApiXHR?a.__fileApiXHR.getAllResponseHeaders():b.apply(a)}}(a.getAllResponseHeaders);a.abort=function(b){return function(){return a.__fileApiXHR?a.__fileApiXHR.abort():null==b?null:b.apply(a)}}(a.abort);a.send=function(){if(arguments[0].__isShim&&arguments[0].__setXHR_){var b=
arguments[0];arguments[0].__setXHR_&&(b=arguments[0],b.__setXHR_(a));for(var c={url:a.__url,complete:function(c,b){Object.defineProperty(a,"status",{get:function(){return b.status}});Object.defineProperty(a,"statusText",{get:function(){return b.statusText}});Object.defineProperty(a,"readyState",{get:function(){return 4}});Object.defineProperty(a,"response",{get:function(){return b.response}});Object.defineProperty(a,"responseText",{get:function(){return b.responseText}});a.__fileApiXHR=b;a.onreadystatechange()},
progress:function(b){a.__progress(b)},headers:a.__requestHeaders,data:{},files:{}},d=0;d<b.data.length;d++){var e=b.data[d];null!=e.val&&null!=e.val.name&&null!=e.val.size&&null!=e.val.type?c.files[e.key]=e.val:c.data[e.key]=e.val}setTimeout(function(){a.__fileApiXHR=FileAPI.upload(c)},1)}else g.apply(a,arguments)};return a}}(XMLHttpRequest));window.FormData||(HTMLInputElement.prototype.addEventListener=HTMLInputElement.prototype.attachEvent=function(c){return function(a,g,b,f){if("change"!==a.toLowerCase()&&
"onchange"!==a.toLowerCase()||"file"!=this.getAttribute("type"))c.apply(this,[a,g,b,f]);else{if(!this.__isWrapped&&(null!=this.getAttribute("ng-file-select")||null!=this.getAttribute("data-ng-file-select"))){var d=document.createElement("div");d.innerHTML='<div class="js-fileapi-wrapper" style="position:relative; overflow:hidden"></div>';var d=d.firstChild,e=this.parentNode;e.insertBefore(d,this);e.removeChild(this);d.appendChild(this);this.__isWrapped=!0}c.apply(this,[a,function(a){var b=FileAPI.getFiles(a);
a.target||(a.target={});a.target.files=b;a.target.files.item=function(b){return a.target.files[b]||null};g(a)},b,f])}}}(HTMLInputElement.prototype.addEventListener||HTMLInputElement.prototype.attachEvent),window.FormData=FormData=function(){return{append:function(c,a,g){this.data.push({key:c,val:a,name:g})},data:[],__isShim:!0}},function(){if(!window.FileAPI||!FileAPI.upload){var c="",a=document.createElement("script"),g=document.getElementsByTagName("script"),b,f,d;if(window.FileAPI&&window.FileAPI.jsPath)c=
window.FileAPI.jsPath;else for(b=0;b<g.length;b++)if(d=g[b].src,f=d.indexOf("angular-file-upload-shim.js"),-1==f&&(f=d.indexOf("angular-file-upload-shim.min.js")),-1<f){c=d.substring(0,f);break}window.FileAPI&&null!=FileAPI.staticPath||(FileAPI={staticPath:c});a.setAttribute("src",c+"FileAPI.min.js");document.getElementsByTagName("head")[0].appendChild(a)}}())})();