diff --git a/angular-file-upload-html5-shim.js b/angular-file-upload-html5-shim.js index 9074e87..1a65631 100644 --- a/angular-file-upload-html5-shim.js +++ b/angular-file-upload-html5-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for angular XHR HTML5 browsers * @author Danial - * @version 1.2.0 + * @version 1.2.1 */ if (window.XMLHttpRequest) { if (window.FormData) { @@ -12,7 +12,11 @@ if (window.XMLHttpRequest) { xhr.setRequestHeader = (function(orig) { return function(header, value) { if (header === '__setXHR_') { - value(xhr); + var val = value(xhr); + // fix for angular < 1.2.0 + if (val instanceof Function) { + val(xhr); + } } else { orig.apply(xhr, arguments); } diff --git a/angular-file-upload-html5-shim.min.js b/angular-file-upload-html5-shim.min.js index e854358..1c70bff 100644 --- a/angular-file-upload-html5-shim.min.js +++ b/angular-file-upload-html5-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.0 */ -window.XMLHttpRequest&&window.FormData&&(XMLHttpRequest=function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){"__setXHR_"===c?d(b):a.apply(b,arguments)}}(b.setRequestHeader),b}}(XMLHttpRequest)); \ No newline at end of file +/*! 1.2.1 */ +window.XMLHttpRequest&&window.FormData&&(XMLHttpRequest=function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){if("__setXHR_"===c){var e=d(b);e instanceof Function&&e(b)}else a.apply(b,arguments)}}(b.setRequestHeader),b}}(XMLHttpRequest)); \ No newline at end of file diff --git a/angular-file-upload-shim.js b/angular-file-upload-shim.js index 9bd16c4..b082514 100755 --- a/angular-file-upload-shim.js +++ b/angular-file-upload-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for HTML5 FormData * @author Danial - * @version 1.2.0 + * @version 1.2.1 */ (function() { @@ -14,7 +14,11 @@ if (window.XMLHttpRequest) { xhr.setRequestHeader = (function(orig) { return function(header, value) { if (header === '__setXHR_') { - value(xhr); + var val = value(xhr); + // fix for angular < 1.2.0 + if (val instanceof Function) { + val(xhr); + } } else { orig.apply(xhr, arguments); } @@ -63,7 +67,11 @@ if (window.XMLHttpRequest) { xhr.setRequestHeader = (function(orig) { return function(header, value) { if (header === '__setXHR_') { - value(xhr); + var val = value(xhr); + // fix for angular < 1.2.0 + if (val instanceof Function) { + val(xhr); + } } else { orig.apply(xhr, arguments); } diff --git a/angular-file-upload-shim.min.js b/angular-file-upload-shim.min.js index 2ec588e..7768cea 100755 --- a/angular-file-upload-shim.min.js +++ b/angular-file-upload-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.0 */ -!function(){if(window.XMLHttpRequest&&(XMLHttpRequest=window.FormData?function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){"__setXHR_"===c?d(b):a.apply(b,arguments)}}(b.setRequestHeader),b}}(XMLHttpRequest):function(a){return function(){var b=new a,c=b.send;return b.__requestHeaders=[],b.open=function(a){return b.upload={addEventListener:function(a,c){"progress"===a&&(b.__progress=c),"load"===a&&(b.__load=c)}},function(c,d,e){a.apply(b,[c,d,e]),b.__url=d}}(b.open),b.getResponseHeader=function(a){return function(c){return b.__fileApiXHR?b.__fileApiXHR.getResponseHeader(c):a.apply(b,[c])}}(b.getResponseHeader),b.getAllResponseHeaders=function(a){return function(){return b.__fileApiXHR?b.__fileApiXHR.getAllResponseHeaders():a.apply(b)}}(b.getAllResponseHeaders),b.abort=function(a){return function(){return b.__fileApiXHR?b.__fileApiXHR.abort():null==a?null:a.apply(b)}}(b.abort),b.setRequestHeader=function(a){return function(c,d){"__setXHR_"===c?d(b):a.apply(b,arguments)}}(b.setRequestHeader),b.send=function(){if(arguments[0]&&arguments[0].__isShim){var a=arguments[0],d={url:b.__url,complete:function(a,c){b.__load({type:"load",loaded:b.__total,total:b.__total,target:b,lengthComputable:!0}),Object.defineProperty(b,"status",{get:function(){return c.status}}),Object.defineProperty(b,"statusText",{get:function(){return c.statusText}}),Object.defineProperty(b,"readyState",{get:function(){return 4}}),Object.defineProperty(b,"response",{get:function(){return c.response}}),Object.defineProperty(b,"responseText",{get:function(){return c.responseText}}),b.__fileApiXHR=c,b.onreadystatechange()},progress:function(a){a.target=b,b.__progress(a),b.__total=a.total},headers:b.__requestHeaders};d.data={},d.files={};for(var e=0;e',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),a||c.appendChild(document.createTextNode("Flash is required")),b.__isWrapped=!0}},e=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},f=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(b,c,g,h){f(this,b)?(d(this),a.apply(this,[b,e(c),g,h])):a.apply(this,[b,c,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(b,c){f(this,b)?(d(this),a.apply(this,[b,e(c)])):a.apply(this,[b,c])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(!window.FileAPI||!FileAPI.upload){var a,b,c,d="",e=document.createElement("script"),f=document.getElementsByTagName("script");if(window.FileAPI&&window.FileAPI.jsPath)d=window.FileAPI.jsPath;else for(a=0;a-1){d=c.substring(0,b);break}window.FileAPI&&null!=FileAPI.staticPath||(FileAPI={staticPath:d}),e.setAttribute("src",d+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(e)}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),a||c.appendChild(document.createTextNode("Flash is required")),b.__isWrapped=!0}},e=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},f=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(b,c,g,h){f(this,b)?(d(this),a.apply(this,[b,e(c),g,h])):a.apply(this,[b,c,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(b,c){f(this,b)?(d(this),a.apply(this,[b,e(c)])):a.apply(this,[b,c])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(!window.FileAPI||!FileAPI.upload){var a,b,c,d="",e=document.createElement("script"),f=document.getElementsByTagName("script");if(window.FileAPI&&window.FileAPI.jsPath)d=window.FileAPI.jsPath;else for(a=0;a-1){d=c.substring(0,b);break}window.FileAPI&&null!=FileAPI.staticPath||(FileAPI={staticPath:d}),e.setAttribute("src",d+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(e)}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d - * @version 1.2.0 + * @version 1.2.1 */ (function() { diff --git a/angular-file-upload.min.js b/angular-file-upload.min.js index 1aa701d..a9bfbef 100755 --- a/angular-file-upload.min.js +++ b/angular-file-upload.min.js @@ -1,2 +1,2 @@ -/*! 1.2.0 */ +/*! 1.2.1 */ !function(){var a=angular.module("angularFileUpload",[]);a.service("$upload",["$http","$rootScope","$timeout",function(a,b,c){function d(b){b.method=b.method||"POST",b.headers=b.headers||{},b.transformRequest=b.transformRequest||function(b){return b instanceof ArrayBuffer?b:a.defaults.transformRequest[0](b)},b.headers.__setXHR_=function(){return function(a){b.__XHR=a,a.upload.addEventListener("progress",function(a){b.progress&&c(function(){b.progress(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&c(function(){b.progress(a)})},!1)}};var d=a(b);return d.progress=function(a){return b.progress=a,d},d.abort=function(){return b.__XHR&&c(function(){b.__XHR.abort()}),d},d.then=function(a,c){return function(d,e,f){return b.progress=f||b.progress,c.apply(a,[d,e,f]),a}}(d,d.then),d}this.upload=function(b){b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData;if(b.data)for(var e in b.data){var f=b.data[e];if(b.formDataAppender)b.formDataAppender(c,e,f);else{if("function"==typeof b.transformRequest)f=b.transformRequest(f);else for(var g=0;g