You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

3 lines
2.8 KiB

/*! UIkit 3.0.0-rc.17 | http://www.getuikit.com | (c) 2014 - 2018 YOOtheme | MIT License */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("uikit-util")):"function"==typeof define&&define.amd?define("uikitupload",["uikit-util"],t):e.UIkitUpload=t(e.UIkit.util)}(this,function(a){"use strict";var e={props:{allow:String,clsDragover:String,concurrent:Number,maxSize:Number,method:String,mime:String,msgInvalidMime:String,msgInvalidName:String,msgInvalidSize:String,multiple:Boolean,name:String,params:Object,type:String,url:String},data:{allow:!1,clsDragover:"uk-dragover",concurrent:1,maxSize:0,method:"POST",mime:!1,msgInvalidMime:"Invalid File Type: %s",msgInvalidName:"Invalid File Name: %s",msgInvalidSize:"Invalid File Size: %s Kilobytes Max",multiple:!1,name:"files[]",params:{},type:"",url:"",abort:a.noop,beforeAll:a.noop,beforeSend:a.noop,complete:a.noop,completeAll:a.noop,error:a.noop,fail:a.noop,load:a.noop,loadEnd:a.noop,loadStart:a.noop,progress:a.noop},events:{change:function(e){a.matches(e.target,'input[type="file"]')&&(e.preventDefault(),e.target.files&&this.upload(e.target.files),e.target.value="")},drop:function(e){r(e);var t=e.dataTransfer;t&&t.files&&(a.removeClass(this.$el,this.clsDragover),this.upload(t.files))},dragenter:function(e){r(e)},dragover:function(e){r(e),a.addClass(this.$el,this.clsDragover)},dragleave:function(e){r(e),a.removeClass(this.$el,this.clsDragover)}},methods:{upload:function(e){var r=this;if(e.length){a.trigger(this.$el,"upload",[e]);for(var t=0;t<e.length;t++){if(r.maxSize&&1e3*r.maxSize<e[t].size)return void r.fail(r.msgInvalidSize.replace("%s",r.maxSize));if(r.allow&&!o(r.allow,e[t].name))return void r.fail(r.msgInvalidName.replace("%s",r.allow));if(r.mime&&!o(r.mime,e[t].type))return void r.fail(r.msgInvalidMime.replace("%s",r.mime))}this.multiple||(e=[e[0]]),this.beforeAll(this,e);var i=function(e,t){for(var o=[],r=0;r<e.length;r+=t){for(var i=[],n=0;n<t;n++)i.push(e[r+n]);o.push(i)}return o}(e,this.concurrent),n=function(e){var t=new FormData;for(var o in e.forEach(function(e){return t.append(r.name,e)}),r.params)t.append(o,r.params[o]);a.ajax(r.url,{data:t,method:r.method,responseType:r.type,beforeSend:function(e){var t=e.xhr;t.upload&&a.on(t.upload,"progress",r.progress),["loadStart","load","loadEnd","abort"].forEach(function(e){return a.on(t,e.toLowerCase(),r[e])}),r.beforeSend(e)}}).then(function(e){r.complete(e),i.length?n(i.shift()):r.completeAll(e)},function(e){return r.error(e)})};n(i.shift())}}}};function o(e,t){return t.match(new RegExp("^"+e.replace(/\//g,"\\/").replace(/\*\*/g,"(\\/[^\\/]+)*").replace(/\*/g,"[^\\/]+").replace(/((?!\\))\?/g,"$1.")+"$","i"))}function r(e){e.preventDefault(),e.stopPropagation()}return"undefined"!=typeof window&&window.UIkit&&window.UIkit.component("upload",e),e});