forked from twilson63/ngUpload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng-upload.min.js
1 lines (1 loc) · 2.2 KB
/
ng-upload.min.js
1
angular.module("ngUpload",[]).directive("uploadSubmit",["$parse",function(t){return{restrict:"AC",link:function(e,n,a){var o={};o.enableControls=a.uploadOptionsEnableControls,a.hasOwnProperty("uploadOptionsConvertHidden")&&(o.convertHidden="false"!=a.uploadOptionsConvertHidden);var i=angular.element(n).parents("form"),r=t(a.uploadSubmit);if(!angular.isFunction(r)){var l="The expression on the ngUpload directive does not point to a valid function.";throw l+"\n"}n.bind("click",function(t){if(t&&(t.preventDefault=!0),!n.attr("disabled")){var a=angular.element("<iframe id='upload_iframe' name='upload_iframe' border='0' width='0' height='0' style='width: 0px; height: 0px; border: none; display: none' />");i.parent().append(a),a.bind("load",function(){var t=a[0],o=t.contentDocument||t.contentWindow.document,i=o.body.innerText||o.body.textContent;try{i=$.parseJSON(i)}catch(l){console&&console.log("WARN: XHR response is not valid json")}e.$$phase?r(e,{content:i,completed:!0}):e.$apply(function(){r(e,{content:i,completed:!0})}),""!==i&&setTimeout(function(){a.remove()},250),n.attr("disabled",null),n.attr("title","Click to start upload.")}),e.$$phase?r(e,{content:"Please wait...",completed:!1}):e.$apply(function(){r(e,{content:"Please wait...",completed:!1})});var l=!0;o.enableControls||(n.attr("disabled","disabled"),l=!1),n.attr("title",(l?"[ENABLED]: ":"[DISABLED]: ")+"Uploading, please wait..."),o.convertHidden&&i.find(":hidden[ng-model]").each(function(){$(this).attr("value",e.$eval($(this).attr("ng-model")))}),i.submit()}}).attr("title","Click to start upload.")}}}]).directive("ngUpload",["$parse",function(){return{restrict:"AC",link:function(t,e,n){var a={};n.hasOwnProperty("uploadOptionsEnableRailsCsrf")&&(a.enableRailsCsrf="false"!=n.uploadOptionsEnableRailsCsrf),e.attr("target","upload_iframe"),e.attr("method","post");var o=-1==e.attr("action").indexOf("?")?"?":"&";e.attr("action",e.attr("action")+o+"_t="+(new Date).getTime()),e.attr("enctype","multipart/form-data"),e.attr("encoding","multipart/form-data"),a.enableRailsCsrf&&$("<input />").attr("id","upload-csrf-token").attr("type","hidden").attr("name",$("meta[name=csrf-param]").attr("content")).val($("meta[name=csrf-token]").attr("content")).appendTo(e)}}}]);