forked from danialfarid/ng-file-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-file-upload.min.js
10 lines (10 loc) · 2.35 KB
/
angular-file-upload.min.js
1
2
3
4
5
6
7
8
9
10
/**!
* AngularJS file upload/drop directive with http post and progress
* @author Danial <danial.farid@gmail.com>
* @version 1.1.5
*/
(function(){var l=angular.module("angularFileUpload",[]);l.service("$upload",["$http","$rootScope",function(f,k){this.upload=function(a){a.method=a.method||"POST";a.headers=a.headers||{};a.headers["Content-Type"]=void 0;a.transformRequest=a.transformRequest||f.defaults.transformRequest;var c=new FormData;if(a.data)for(var d in a.data){var e=a.data[d];if(a.formDataAppender)a.formDataAppender(c,d,e);else{if("function"==typeof a.transformRequest)e=a.transformRequest(e);else for(var g=0;g<a.transformRequest.length;g++){var m=
a.transformRequest[g];"function"==typeof m&&(e=m(e))}c.append(d,e)}}a.transformRequest=angular.identity;c.append(a.fileFormDataName||"file",a.file,a.file.name);c.__setXHR_=function(b){a.__XHR=b;b.upload.addEventListener("progress",function(b){a.progress&&(a.progress(b),k.$$phase||k.$apply())},!1)};a.data=c;var b=f(a);b.progress=function(c){a.progress=c;return b};b.abort=function(){a.__XHR&&a.__XHR.abort();return b};b.then=function(b,c){return function(g,e,d){a.progress=d||a.progress;c.apply(b,[g,
e,d]);return b}}(b,b.then);return b}}]);l.directive("ngFileSelect",["$parse","$http",function(f,k){return function(a,c,d){var e=f(d.ngFileSelect);c.bind("change",function(c){var d=[],b,h;b=c.target.files;if(null!=b)for(h=0;h<b.length;h++)d.push(b.item(h));a.$apply(function(){e(a,{$files:d,$event:c})})});c.bind("click",function(){this.value=null})}}]);l.directive("ngFileDropAvailable",["$parse","$http",function(f,k){return function(a,c,d){if("draggable"in document.createElement("span")){var e=f(d.ngFileDropAvailable);
a.$$phase?e(a):a.$apply(function(){e(a)})}}}]);l.directive("ngFileDrop",["$parse","$http",function(f,k){return function(a,c,d){if("draggable"in document.createElement("span")){var e=f(d.ngFileDrop);c[0].addEventListener("dragover",function(a){a.stopPropagation();a.preventDefault();c.addClass(d.ngFileDragOverClass||"dragover")},!1);c[0].addEventListener("dragleave",function(a){c.removeClass(d.ngFileDragOverClass||"dragover")},!1);c[0].addEventListener("drop",function(g){g.stopPropagation();g.preventDefault();
c.removeClass(d.ngFileDragOverClass||"dragover");var f=[],b=g.dataTransfer.files,h;if(null!=b)for(h=0;h<b.length;h++)f.push(b.item(h));a.$apply(function(){e(a,{$files:f,$event:g})})},!1)}}}])})();