filesafe/public/libs/dropzone/dropzone.min.js

3 lines
45 KiB
JavaScript
Raw Normal View History

/*! dropzone v5.4.0 | Copyright (c) 2012 Matias Meno */"use strict";function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function __guard__(e,t){return"undefined"!=typeof e&&null!==e?t(e):void 0}function __guardMethod__(e,t,i){return"undefined"!=typeof e&&null!==e&&"function"==typeof e[t]?i(e,t):void 0}var _createClass=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),Emitter=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"on",value:function(e,t){return this._callbacks=this._callbacks||{},this._callbacks[e]||(this._callbacks[e]=[]),this._callbacks[e].push(t),this}},{key:"emit",value:function(e){this._callbacks=this._callbacks||{};var t=this._callbacks[e];if(t){for(var i=arguments.length,n=Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];for(var o=t,a=!0,l=0,o=a?o:o[Symbol.iterator]();;){var s;if(a){if(l>=o.length)break;s=o[l++]}else{if(l=o.next(),l.done)break;s=l.value}var u=s;u.apply(this,n)}}return this}},{key:"off",value:function(e,t){if(!this._callbacks||0===arguments.length)return this._callbacks={},this;var i=this._callbacks[e];if(!i)return this;if(1===arguments.length)return delete this._callbacks[e],this;for(var n=0;n<i.length;n++){var r=i[n];if(r===t){i.splice(n,1);break}}return this}}]),e}(),Dropzone=function(e){function t(e,i){_classCallCheck(this,t);var n=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this)),r=void 0,o=void 0;if(n.element=e,n.version=t.version,n.defaultOptions.previewTemplate=n.defaultOptions.previewTemplate.replace(/\n*/g,""),n.clickableElements=[],n.listeners=[],n.files=[],"string"==typeof n.element&&(n.element=document.querySelector(n.element)),!n.element||null==n.element.nodeType)throw new Error("Invalid dropzone element.");if(n.element.dropzone)throw new Error("Dropzone already attached.");t.instances.push(n),n.element.dropzone=n;var a=null!=(o=t.optionsForElement(n.element))?o:{};if(n.options=t.extend({},n.defaultOptions,a,null!=i?i:{}),n.options.forceFallback||!t.isBrowserSupported()){var l;return l=n.options.fallback.call(n),_possibleConstructorReturn(n,l)}if(null==n.options.url&&(n.options.url=n.element.getAttribute("action")),!n.options.url)throw new Error("No URL provided.");if(n.options.acceptedFiles&&n.options.acceptedMimeTypes)throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");if(n.options.uploadMultiple&&n.options.chunking)throw new Error("You cannot set both: uploadMultiple and chunking.");return n.options.acceptedMimeTypes&&(n.options.acceptedFiles=n.options.acceptedMimeTypes,delete n.options.acceptedMimeTypes),null!=n.options.renameFilename&&(n.options.renameFile=function(e){return n.options.renameFilename.call(n,e.name,e)}),n.options.method=n.options.method.toUpperCase(),(r=n.getExistingFallback())&&r.parentNode&&r.parentNode.removeChild(r),n.options.previewsContainer!==!1&&(n.options.previewsContainer?n.previewsContainer=t.getElement(n.options.previewsContainer,"previewsContainer"):n.previewsContainer=n.element),n.options.clickable&&(n.options.clickable===!0?n.clickableElements=[n.element]:n.clickableElements=t.getElements(n.options.clickable,"clickable")),n.init(),n}return _inherits(t,e),_createClass(t,null,[{key:"initClass",value:function(){this.prototype.Emitter=Emitter,this.prototype.events=["drop","
key:"_getChunk",value:function(e,t){for(var i=0;i<e.upload.totalChunkCount;i++)if(void 0!==e.upload.chunks[i]&&e.upload.chunks[i].xhr===t)return e.upload.chunks[i]}},{key:"_uploadData",value:function(e,i){for(var n=this,r=new XMLHttpRequest,o=e,a=!0,l=0,o=a?o:o[Symbol.iterator]();;){var s;if(a){if(l>=o.length)break;s=o[l++]}else{if(l=o.next(),l.done)break;s=l.value}var u=s;u.xhr=r}e[0].upload.chunked&&(e[0].upload.chunks[i[0].chunkIndex].xhr=r);var d=this.resolveOption(this.options.method,e),c=this.resolveOption(this.options.url,e);r.open(d,c,!0),r.timeout=this.resolveOption(this.options.timeout,e),r.withCredentials=!!this.options.withCredentials,r.onload=function(t){n._finishedUploading(e,r,t)},r.onerror=function(){n._handleUploadError(e,r)};var p=null!=r.upload?r.upload:r;p.onprogress=function(t){return n._updateFilesUploadProgress(e,r,t)};var h={Accept:"application/json","Cache-Control":"no-cache","X-Requested-With":"XMLHttpRequest"};this.options.headers&&t.extend(h,this.options.headers);for(var f in h){var v=h[f];v&&r.setRequestHeader(f,v)}var m=new FormData;if(this.options.params){var g=this.options.params;"function"==typeof g&&(g=g.call(this,e,r,e[0].upload.chunked?this._getChunk(e[0],r):null));for(var k in g){var b=g[k];m.append(k,b)}}for(var y=e,F=!0,w=0,y=F?y:y[Symbol.iterator]();;){var x;if(F){if(w>=y.length)break;x=y[w++]}else{if(w=y.next(),w.done)break;x=w.value}var E=x;this.emit("sending",E,r,m)}this.options.uploadMultiple&&this.emit("sendingmultiple",e,r,m),this._addFormElementData(m);for(var z=0;z<i.length;z++){var C=i[z];m.append(C.name,C.data,C.filename)}this.submitRequest(r,m,e)}},{key:"_transformFiles",value:function(e,t){for(var i=this,n=[],r=0,o=function(o){i.options.transformFile.call(i,e[o],function(i){n[o]=i,++r===e.length&&t(n)})},a=0;a<e.length;a++)o(a)}},{key:"_addFormElementData",value:function(e){if("FORM"===this.element.tagName)for(var t=this.element.querySelectorAll("input, textarea, select, button"),i=!0,n=0,t=i?t:t[Symbol.iterator]();;){var r;if(i){if(n>=t.length)break;r=t[n++]}else{if(n=t.next(),n.done)break;r=n.value}var o=r,a=o.getAttribute("name"),l=o.getAttribute("type");if(l&&(l=l.toLowerCase()),"undefined"!=typeof a&&null!==a)if("SELECT"===o.tagName&&o.hasAttribute("multiple"))for(var s=o.options,u=!0,d=0,s=u?s:s[Symbol.iterator]();;){var c;if(u){if(d>=s.length)break;c=s[d++]}else{if(d=s.next(),d.done)break;c=d.value}var p=c;p.selected&&e.append(a,p.value)}else(!l||"checkbox"!==l&&"radio"!==l||o.checked)&&e.append(a,o.value)}}},{key:"_updateFilesUploadProgress",value:function(e,t,i){var n=void 0;if("undefined"!=typeof i){if(n=100*i.loaded/i.total,e[0].upload.chunked){var r=e[0],o=this._getChunk(r,t);o.progress=n,o.total=i.total,o.bytesSent=i.loaded;r.upload.progress=0,r.upload.total=0,r.upload.bytesSent=0;for(var a=0;a<r.upload.totalChunkCount;a++)void 0!==r.upload.chunks[a]&&void 0!==r.upload.chunks[a].progress&&(r.upload.progress+=r.upload.chunks[a].progress,r.upload.total+=r.upload.chunks[a].total,r.upload.bytesSent+=r.upload.chunks[a].bytesSent);r.upload.progress=r.upload.progress/r.upload.totalChunkCount}else for(var l=e,s=!0,u=0,l=s?l:l[Symbol.iterator]();;){var d;if(s){if(u>=l.length)break;d=l[u++]}else{if(u=l.next(),u.done)break;d=u.value}var c=d;c.upload.progress=n,c.upload.total=i.total,c.upload.bytesSent=i.loaded}for(var p=e,h=!0,f=0,p=h?p:p[Symbol.iterator]();;){var v;if(h){if(f>=p.length)break;v=p[f++]}else{if(f=p.next(),f.done)break;v=f.value}var m=v;this.emit("uploadprogress",m,m.upload.progress,m.upload.bytesSent)}}else{var g=!0;n=100;for(var k=e,b=!0,y=0,k=b?k:k[Symbol.iterator]();;){var F;if(b){if(y>=k.length)break;F=k[y++]}else{if(y=k.next(),y.done)break;F=y.value}var w=F;100===w.upload.progress&&w.upload.bytesSent===w.upload.total||(g=!1),w.upload.progress=n,w.upload.bytesSent=w.upload.total}if(g)return;for(var x=e,E=!0,z=0,x=E?x:x[Symbol.iterator]();;){var C;if(E){if(z>=x.length)break;C=x[z++]}else{if(z=x.next(),z.done)break;C=z.value}var S=C;this.emit("uploadprogress",S,n,S.upload.bytesSent)}}}},{key:"_finishedUploading",value:function(e,i,n){var r=void 0;if(