2 lines
41 KiB
JavaScript
2 lines
41 KiB
JavaScript
(function(){var Dropzone,Emitter,camelize,contentLoaded,detectVerticalSquash,drawImageIOSFix,noop,without,__slice=[].slice,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);function ctor(){this.constructor=child}return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child};noop=function(){},Emitter=function(){function Emitter(){}return Emitter.prototype.addEventListener=Emitter.prototype.on,Emitter.prototype.on=function(event,fn){return this._callbacks=this._callbacks||{},this._callbacks[event]||(this._callbacks[event]=[]),this._callbacks[event].push(fn),this},Emitter.prototype.emit=function(){var args,callback,callbacks,event,_i,_len;if(event=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[],this._callbacks=this._callbacks||{},callbacks=this._callbacks[event])for(_i=0,_len=callbacks.length;_i<_len;_i++)(callback=callbacks[_i]).apply(this,args);return this},Emitter.prototype.removeListener=Emitter.prototype.off,Emitter.prototype.removeAllListeners=Emitter.prototype.off,Emitter.prototype.removeEventListener=Emitter.prototype.off,Emitter.prototype.off=function(event,fn){var callback,callbacks,i,_i,_len;if(!this._callbacks||0===arguments.length)return this._callbacks={},this;if(!(callbacks=this._callbacks[event]))return this;if(1===arguments.length)return delete this._callbacks[event],this;for(i=_i=0,_len=callbacks.length;_i<_len;i=++_i)if((callback=callbacks[i])===fn){callbacks.splice(i,1);break}return this},Emitter}(),(Dropzone=function(_super){var extend,resolveOption;function Dropzone(element,options){var elementOptions,fallback,_ref;if(this.element=element,this.version=Dropzone.version,this.defaultOptions.previewTemplate=this.defaultOptions.previewTemplate.replace(/\n*/g,""),this.clickableElements=[],this.listeners=[],this.files=[],"string"==typeof this.element&&(this.element=document.querySelector(this.element)),!this.element||null==this.element.nodeType)throw new Error("Invalid dropzone element.");if(this.element.dropzone)throw new Error("Dropzone already attached.");if(Dropzone.instances.push(this),this.element.dropzone=this,elementOptions=null!=(_ref=Dropzone.optionsForElement(this.element))?_ref:{},this.options=extend({},this.defaultOptions,elementOptions,null!=options?options:{}),this.options.forceFallback||!Dropzone.isBrowserSupported())return this.options.fallback.call(this);if(null==this.options.url&&(this.options.url=this.element.getAttribute("action")),!this.options.url)throw new Error("No URL provided.");if(this.options.acceptedFiles&&this.options.acceptedMimeTypes)throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");this.options.acceptedMimeTypes&&(this.options.acceptedFiles=this.options.acceptedMimeTypes,delete this.options.acceptedMimeTypes),this.options.method=this.options.method.toUpperCase(),(fallback=this.getExistingFallback())&&fallback.parentNode&&fallback.parentNode.removeChild(fallback),!1!==this.options.previewsContainer&&(this.options.previewsContainer?this.previewsContainer=Dropzone.getElement(this.options.previewsContainer,"previewsContainer"):this.previewsContainer=this.element),this.options.clickable&&(!0===this.options.clickable?this.clickableElements=[this.element]:this.clickableElements=Dropzone.getElements(this.options.clickable,"clickable")),this.init()}return __extends(Dropzone,_super),Dropzone.prototype.Emitter=Emitter,Dropzone.prototype.events=["drop","dragstart","dragend","dragenter","dragover","dragleave","addedfile","addedfiles","removedfile","thumbnail","error","errormultiple","processing","processingmultiple","uploadprogress","totaluploadprogress","sending","sendingmultiple","success","successmultiple","canceled","canceledmultiple","complete","completemultiple","reset","maxfilesexceeded","maxfilesreached","queuecomplete"],Dropzone.prototype.defaultOptions={url:null,method:"post",withCredentials:!1,parallelUploads:2,uploadMultiple:!1,maxFilesize:256,paramName:"file",createImageThumbnails:!0,maxThumbnailFilesize:10,thumbnailWidth:120,thumbnailHeight:120,filesizeBase:1e3,maxFiles:null,params:{},clickable:!0,ignoreHiddenFiles:!0,acceptedFiles:null,acceptedMimeTypes:null,autoProcessQueue:!0,autoQueue:!0,addRemoveLinks:!1,previewsContainer:null,capture:null,dictDefaultMessage:"Drop files here to upload",dictFallbackMessage:"Your browser does not support drag'n'drop file uploads.",dictFallbackText:"Please use the fallback form below to upload your files like in the olden days.",dictFileTooBig:"File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",dictInvalidFileType:"You can't upload files of this type.",dictResponseError:"Server responded with {{statusCode}} code.",dictCancelUpload:"Cancel upload",dictCancelUploadConfirmation:"Are you sure you want to cancel this upload?",dictRemoveFile:"Remove file",dictRemoveFileConfirmation:null,dictMaxFilesExceeded:"You can not upload any more files.",accept:function(file,done){return done()},init:function(){return noop},forceFallback:!1,fallback:function(){var child,messageElement,span,_i,_len,_ref;for(this.element.className=this.element.className+" dz-browser-not-supported",_i=0,_len=(_ref=this.element.getElementsByTagName("div")).length;_i<_len;_i++)child=_ref[_i],/(^| )dz-message($| )/.test(child.className)&&(messageElement=child,child.className="dz-message");return messageElement||(messageElement=Dropzone.createElement('<div class="dz-message"><span></span></div>'),this.element.appendChild(messageElement)),(span=messageElement.getElementsByTagName("span")[0])&&(null!=span.textContent?span.textContent=this.options.dictFallbackMessage:null!=span.innerText&&(span.innerText=this.options.dictFallbackMessage)),this.element.appendChild(this.getFallbackForm())},resize:function(file){var info,srcRatio,trgRatio;return info={srcX:0,srcY:0,srcWidth:file.width,srcHeight:file.height},srcRatio=file.width/file.height,info.optWidth=this.options.thumbnailWidth,info.optHeight=this.options.thumbnailHeight,null==info.optWidth&&null==info.optHeight?(info.optWidth=info.srcWidth,info.optHeight=info.srcHeight):null==info.optWidth?info.optWidth=srcRatio*info.optHeight:null==info.optHeight&&(info.optHeight=1/srcRatio*info.optWidth),trgRatio=info.optWidth/info.optHeight,file.height<info.optHeight||file.width<info.optWidth?(info.trgHeight=info.srcHeight,info.trgWidth=info.srcWidth):srcRatio>trgRatio?(info.srcHeight=file.height,info.srcWidth=info.srcHeight*trgRatio):(info.srcWidth=file.width,info.srcHeight=info.srcWidth/trgRatio),info.srcX=(file.width-info.srcWidth)/2,info.srcY=(file.height-info.srcHeight)/2,info},drop:function(e){return this.element.classList.remove("dz-drag-hover")},dragstart:noop,dragend:function(e){return this.element.classList.remove("dz-drag-hover")},dragenter:function(e){return this.element.classList.add("dz-drag-hover")},dragover:function(e){return this.element.classList.add("dz-drag-hover")},dragleave:function(e){return this.element.classList.remove("dz-drag-hover")},paste:noop,reset:function(){return this.element.classList.remove("dz-started")},addedfile:function(file){var node,removeFileEvent,removeLink,_i,_j,_k,_len,_len1,_len2,_ref,_ref1,_ref2,_results,_this;if(this.element===this.previewsContainer&&this.element.classList.add("dz-started"),this.previewsContainer){for(file.previewElement=Dropzone.createElement(this.options.previewTemplate.trim()),file.previewTemplate=file.previewElement,this.previewsContainer.appendChild(file.previewElement),_i=0,_len=(_ref=file.previewElement.querySelectorAll("[data-dz-name]")).length;_i<_len;_i++)(node=_ref[_i]).textContent=file.name;for(_j=0,_len1=(_ref1=file.previewElement.querySelectorAll("[data-dz-size]")).length;_j<_len1;_j++)(node=_ref1[_j]).innerHTML=this.filesize(file.size);for(this.options.addRemoveLinks&&(file._removeLink=Dropzone.createElement('<a class="dz-remove" href="javascript:undefined;" data-dz-remove>'+this.options.dictRemoveFile+"</a>"),file.previewElement.appendChild(file._removeLink)),_this=this,removeFileEvent=function(e){return e.preventDefault(),e.stopPropagation(),file.status===Dropzone.UPLOADING?Dropzone.confirm(_this.options.dictCancelUploadConfirmation,(function(){return _this.removeFile(file)})):_this.options.dictRemoveFileConfirmation?Dropzone.confirm(_this.options.dictRemoveFileConfirmation,(function(){return _this.removeFile(file)})):_this.removeFile(file)},_results=[],_k=0,_len2=(_ref2=file.previewElement.querySelectorAll("[data-dz-remove]")).length;_k<_len2;_k++)removeLink=_ref2[_k],_results.push(removeLink.addEventListener("click",removeFileEvent));return _results}},removedfile:function(file){var _ref;return file.previewElement&&null!=(_ref=file.previewElement)&&_ref.parentNode.removeChild(file.previewElement),this._updateMaxFilesReachedClass()},thumbnail:function(file,dataUrl){var thumbnailElement,_i,_len,_ref,_this;if(file.previewElement){for(file.previewElement.classList.remove("dz-file-preview"),_i=0,_len=(_ref=file.previewElement.querySelectorAll("[data-dz-thumbnail]")).length;_i<_len;_i++)(thumbnailElement=_ref[_i]).alt=file.name,thumbnailElement.src=dataUrl;return setTimeout((_this=this,function(){return file.previewElement.classList.add("dz-image-preview")}),1)}},error:function(file,message){var node,_i,_len,_ref,_results;if(file.previewElement){for(file.previewElement.classList.add("dz-error"),"String"!=typeof message&&message.error&&(message=message.error),_results=[],_i=0,_len=(_ref=file.previewElement.querySelectorAll("[data-dz-errormessage]")).length;_i<_len;_i++)node=_ref[_i],_results.push(node.textContent=message);return _results}},errormultiple:noop,processing:function(file){if(file.previewElement&&(file.previewElement.classList.add("dz-processing"),file._removeLink))return file._removeLink.textContent=this.options.dictCancelUpload},processingmultiple:noop,uploadprogress:function(file,progress,bytesSent){var node,_i,_len,_ref,_results;if(file.previewElement){for(_results=[],_i=0,_len=(_ref=file.previewElement.querySelectorAll("[data-dz-uploadprogress]")).length;_i<_len;_i++)"PROGRESS"===(node=_ref[_i]).nodeName?_results.push(node.value=progress):_results.push(node.style.width=progress+"%");return _results}},totaluploadprogress:noop,sending:noop,sendingmultiple:noop,success:function(file){if(file.previewElement)return file.previewElement.classList.add("dz-success")},successmultiple:noop,canceled:function(file){return this.emit("error",file,"Upload canceled.")},canceledmultiple:noop,complete:function(file){if(file._removeLink&&(file._removeLink.textContent=this.options.dictRemoveFile),file.previewElement)return file.previewElement.classList.add("dz-complete")},completemultiple:noop,maxfilesexceeded:noop,maxfilesreached:noop,queuecomplete:noop,addedfiles:noop,previewTemplate:'<div class="dz-preview dz-file-preview">\n <div class="dz-image"><img data-dz-thumbnail /></div>\n <div class="dz-details">\n <div class="dz-size"><span data-dz-size></span></div>\n <div class="dz-filename"><span data-dz-name></span></div>\n </div>\n <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>\n <div class="dz-error-message"><span data-dz-errormessage></span></div>\n <div class="dz-success-mark">\n <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">\n <title>Check</title>\n <defs></defs>\n <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">\n <path d="M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" stroke-opacity="0.198794158" stroke="#747474" fill-opacity="0.816519475" fill="#FFFFFF" sketch:type="MSShapeGroup"></path>\n </g>\n </svg>\n </div>\n <div class="dz-error-mark">\n <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">\n <title>Error</title>\n <defs></defs>\n <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">\n <g id="Check-+-Oval-2" sketch:type="MSLayerGroup" stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">\n <path d="M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" sketch:type="MSShapeGroup"></path>\n </g>\n </g>\n </svg>\n </div>\n</div>'},extend=function(){var key,object,objects,target,val,_i,_len;for(target=arguments[0],_i=0,_len=(objects=2<=arguments.length?__slice.call(arguments,1):[]).length;_i<_len;_i++)for(key in object=objects[_i])val=object[key],target[key]=val;return target},Dropzone.prototype.getAcceptedFiles=function(){var file,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)(file=_ref[_i]).accepted&&_results.push(file);return _results},Dropzone.prototype.getRejectedFiles=function(){var file,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)(file=_ref[_i]).accepted||_results.push(file);return _results},Dropzone.prototype.getFilesWithStatus=function(status){var file,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)(file=_ref[_i]).status===status&&_results.push(file);return _results},Dropzone.prototype.getQueuedFiles=function(){return this.getFilesWithStatus(Dropzone.QUEUED)},Dropzone.prototype.getUploadingFiles=function(){return this.getFilesWithStatus(Dropzone.UPLOADING)},Dropzone.prototype.getAddedFiles=function(){return this.getFilesWithStatus(Dropzone.ADDED)},Dropzone.prototype.getActiveFiles=function(){var file,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)(file=_ref[_i]).status!==Dropzone.UPLOADING&&file.status!==Dropzone.QUEUED||_results.push(file);return _results},Dropzone.prototype.init=function(){var eventName,noPropagation,setupHiddenFileInput,_i,_len,_ref,_ref1,_this;for("form"===this.element.tagName&&this.element.setAttribute("enctype","multipart/form-data"),this.element.classList.contains("dropzone")&&!this.element.querySelector(".dz-message")&&this.element.appendChild(Dropzone.createElement('<div class="dz-default dz-message"><span>'+this.options.dictDefaultMessage+"</span></div>")),this.clickableElements.length&&(_this=this,(setupHiddenFileInput=function(){return _this.hiddenFileInput&&document.body.removeChild(_this.hiddenFileInput),_this.hiddenFileInput=document.createElement("input"),_this.hiddenFileInput.setAttribute("type","file"),(null==_this.options.maxFiles||_this.options.maxFiles>1)&&_this.hiddenFileInput.setAttribute("multiple","multiple"),_this.hiddenFileInput.className="dz-hidden-input",null!=_this.options.acceptedFiles&&_this.hiddenFileInput.setAttribute("accept",_this.options.acceptedFiles),null!=_this.options.capture&&_this.hiddenFileInput.setAttribute("capture",_this.options.capture),_this.hiddenFileInput.style.visibility="hidden",_this.hiddenFileInput.style.position="absolute",_this.hiddenFileInput.style.top="0",_this.hiddenFileInput.style.left="0",_this.hiddenFileInput.style.height="0",_this.hiddenFileInput.style.width="0",document.body.appendChild(_this.hiddenFileInput),_this.hiddenFileInput.addEventListener("change",(function(){var file,files,_i,_len;if((files=_this.hiddenFileInput.files).length)for(_i=0,_len=files.length;_i<_len;_i++)file=files[_i],_this.addFile(file);return _this.emit("addedfiles",files),setupHiddenFileInput()}))})()),this.URL=null!=(_ref=window.URL)?_ref:window.webkitURL,_i=0,_len=(_ref1=this.events).length;_i<_len;_i++)eventName=_ref1[_i],this.on(eventName,this.options[eventName]);return this.on("uploadprogress",function(_this){return function(){return _this.updateTotalUploadProgress()}}(this)),this.on("removedfile",function(_this){return function(){return _this.updateTotalUploadProgress()}}(this)),this.on("canceled",function(_this){return function(file){return _this.emit("complete",file)}}(this)),this.on("complete",function(_this){return function(file){if(0===_this.getAddedFiles().length&&0===_this.getUploadingFiles().length&&0===_this.getQueuedFiles().length)return setTimeout((function(){return _this.emit("queuecomplete")}),0)}}(this)),noPropagation=function(e){return e.stopPropagation(),e.preventDefault?e.preventDefault():e.returnValue=!1},this.listeners=[{element:this.element,events:{dragstart:function(_this){return function(e){return _this.emit("dragstart",e)}}(this),dragenter:function(_this){return function(e){return noPropagation(e),_this.emit("dragenter",e)}}(this),dragover:function(_this){return function(e){var efct;try{efct=e.dataTransfer.effectAllowed}catch(_error){}return e.dataTransfer.dropEffect="move"===efct||"linkMove"===efct?"move":"copy",noPropagation(e),_this.emit("dragover",e)}}(this),dragleave:function(_this){return function(e){return _this.emit("dragleave",e)}}(this),drop:function(_this){return function(e){return noPropagation(e),_this.drop(e)}}(this),dragend:function(_this){return function(e){return _this.emit("dragend",e)}}(this)}}],this.clickableElements.forEach(function(_this){return function(clickableElement){return _this.listeners.push({element:clickableElement,events:{click:function(evt){return(clickableElement!==_this.element||evt.target===_this.element||Dropzone.elementInside(evt.target,_this.element.querySelector(".dz-message")))&&_this.hiddenFileInput.click(),!0}}})}}(this)),this.enable(),this.options.init.call(this)},Dropzone.prototype.destroy=function(){var _ref;return this.disable(),this.removeAllFiles(!0),(null!=(_ref=this.hiddenFileInput)?_ref.parentNode:void 0)&&(this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput),this.hiddenFileInput=null),delete this.element.dropzone,Dropzone.instances.splice(Dropzone.instances.indexOf(this),1)},Dropzone.prototype.updateTotalUploadProgress=function(){var activeFiles,file,totalBytes,totalBytesSent,totalUploadProgress,_i,_len,_ref;if(totalBytesSent=0,totalBytes=0,(activeFiles=this.getActiveFiles()).length){for(_i=0,_len=(_ref=this.getActiveFiles()).length;_i<_len;_i++)totalBytesSent+=(file=_ref[_i]).upload.bytesSent,totalBytes+=file.upload.total;totalUploadProgress=100*totalBytesSent/totalBytes}else totalUploadProgress=100;return this.emit("totaluploadprogress",totalUploadProgress,totalBytes,totalBytesSent)},Dropzone.prototype._getParamName=function(n){return"function"==typeof this.options.paramName?this.options.paramName(n):this.options.paramName+(this.options.uploadMultiple?"["+n+"]":"")},Dropzone.prototype.getFallbackForm=function(){var existingFallback,fields,fieldsString,form;return(existingFallback=this.getExistingFallback())?existingFallback:(fieldsString='<div class="dz-fallback">',this.options.dictFallbackText&&(fieldsString+="<p>"+this.options.dictFallbackText+"</p>"),fieldsString+='<input type="file" name="'+this._getParamName(0)+'" '+(this.options.uploadMultiple?'multiple="multiple"':void 0)+' /><input type="submit" value="Upload!"></div>',fields=Dropzone.createElement(fieldsString),"FORM"!==this.element.tagName?(form=Dropzone.createElement('<form action="'+this.options.url+'" enctype="multipart/form-data" method="'+this.options.method+'"></form>')).appendChild(fields):(this.element.setAttribute("enctype","multipart/form-data"),this.element.setAttribute("method",this.options.method)),null!=form?form:fields)},Dropzone.prototype.getExistingFallback=function(){var fallback,getFallback,tagName,_i,_len,_ref;for(getFallback=function(elements){var el,_i,_len;for(_i=0,_len=elements.length;_i<_len;_i++)if(el=elements[_i],/(^| )fallback($| )/.test(el.className))return el},_i=0,_len=(_ref=["div","form"]).length;_i<_len;_i++)if(tagName=_ref[_i],fallback=getFallback(this.element.getElementsByTagName(tagName)))return fallback},Dropzone.prototype.setupEventListeners=function(){var elementListeners,event,listener,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.listeners).length;_i<_len;_i++)elementListeners=_ref[_i],_results.push(function(){var _ref1,_results1;for(event in _results1=[],_ref1=elementListeners.events)listener=_ref1[event],_results1.push(elementListeners.element.addEventListener(event,listener,!1));return _results1}());return _results},Dropzone.prototype.removeEventListeners=function(){var elementListeners,event,listener,_i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.listeners).length;_i<_len;_i++)elementListeners=_ref[_i],_results.push(function(){var _ref1,_results1;for(event in _results1=[],_ref1=elementListeners.events)listener=_ref1[event],_results1.push(elementListeners.element.removeEventListener(event,listener,!1));return _results1}());return _results},Dropzone.prototype.disable=function(){var file,_i,_len,_ref,_results;for(this.clickableElements.forEach((function(element){return element.classList.remove("dz-clickable")})),this.removeEventListeners(),_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)file=_ref[_i],_results.push(this.cancelUpload(file));return _results},Dropzone.prototype.enable=function(){return this.clickableElements.forEach((function(element){return element.classList.add("dz-clickable")})),this.setupEventListeners()},Dropzone.prototype.filesize=function(size){var cutoff,i,selectedSize,selectedUnit,unit,units,_i,_len;if(selectedSize=0,selectedUnit="b",size>0){for(i=_i=0,_len=(units=["TB","GB","MB","KB","b"]).length;_i<_len;i=++_i)if(unit=units[i],size>=(cutoff=Math.pow(this.options.filesizeBase,4-i)/10)){selectedSize=size/Math.pow(this.options.filesizeBase,4-i),selectedUnit=unit;break}selectedSize=Math.round(10*selectedSize)/10}return"<strong>"+selectedSize+"</strong> "+selectedUnit},Dropzone.prototype._updateMaxFilesReachedClass=function(){return null!=this.options.maxFiles&&this.getAcceptedFiles().length>=this.options.maxFiles?(this.getAcceptedFiles().length===this.options.maxFiles&&this.emit("maxfilesreached",this.files),this.element.classList.add("dz-max-files-reached")):this.element.classList.remove("dz-max-files-reached")},Dropzone.prototype.drop=function(e){var files,items;e.dataTransfer&&(this.emit("drop",e),files=e.dataTransfer.files,this.emit("addedfiles",files),files.length&&((items=e.dataTransfer.items)&&items.length&&null!=items[0].webkitGetAsEntry?this._addFilesFromItems(items):this.handleFiles(files)))},Dropzone.prototype.paste=function(e){var items,_ref;if(null!=(null!=e&&null!=(_ref=e.clipboardData)?_ref.items:void 0))return this.emit("paste",e),(items=e.clipboardData.items).length?this._addFilesFromItems(items):void 0},Dropzone.prototype.handleFiles=function(files){var file,_i,_len,_results;for(_results=[],_i=0,_len=files.length;_i<_len;_i++)file=files[_i],_results.push(this.addFile(file));return _results},Dropzone.prototype._addFilesFromItems=function(items){var entry,item,_i,_len,_results;for(_results=[],_i=0,_len=items.length;_i<_len;_i++)null!=(item=items[_i]).webkitGetAsEntry&&(entry=item.webkitGetAsEntry())?entry.isFile?_results.push(this.addFile(item.getAsFile())):entry.isDirectory?_results.push(this._addFilesFromDirectory(entry,entry.name)):_results.push(void 0):null!=item.getAsFile&&(null==item.kind||"file"===item.kind)?_results.push(this.addFile(item.getAsFile())):_results.push(void 0);return _results},Dropzone.prototype._addFilesFromDirectory=function(directory,path){var dirReader,entriesReader,_this;return dirReader=directory.createReader(),_this=this,entriesReader=function(entries){var entry,_i,_len;for(_i=0,_len=entries.length;_i<_len;_i++)(entry=entries[_i]).isFile?entry.file((function(file){if(!_this.options.ignoreHiddenFiles||"."!==file.name.substring(0,1))return file.fullPath=path+"/"+file.name,_this.addFile(file)})):entry.isDirectory&&_this._addFilesFromDirectory(entry,path+"/"+entry.name)},dirReader.readEntries(entriesReader,(function(error){return"undefined"!=typeof console&&null!==console&&"function"==typeof console.log?console.log(error):void 0}))},Dropzone.prototype.accept=function(file,done){return file.size>1024*this.options.maxFilesize*1024?done(this.options.dictFileTooBig.replace("{{filesize}}",Math.round(file.size/1024/10.24)/100).replace("{{maxFilesize}}",this.options.maxFilesize)):Dropzone.isValidFile(file,this.options.acceptedFiles)?null!=this.options.maxFiles&&this.getAcceptedFiles().length>=this.options.maxFiles?(done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}",this.options.maxFiles)),this.emit("maxfilesexceeded",file)):this.options.accept.call(this,file,done):done(this.options.dictInvalidFileType)},Dropzone.prototype.addFile=function(file){return file.upload={progress:0,total:file.size,bytesSent:0},this.files.push(file),file.status=Dropzone.ADDED,this.emit("addedfile",file),this._enqueueThumbnail(file),this.accept(file,(_this=this,function(error){return error?(file.accepted=!1,_this._errorProcessing([file],error)):(file.accepted=!0,_this.options.autoQueue&&_this.enqueueFile(file)),_this._updateMaxFilesReachedClass()}));var _this},Dropzone.prototype.enqueueFiles=function(files){var file,_i,_len;for(_i=0,_len=files.length;_i<_len;_i++)file=files[_i],this.enqueueFile(file);return null},Dropzone.prototype.enqueueFile=function(file){if(file.status!==Dropzone.ADDED||!0!==file.accepted)throw new Error("This file can't be queued because it has already been processed or was rejected.");if(file.status=Dropzone.QUEUED,this.options.autoProcessQueue)return setTimeout((_this=this,function(){return _this.processQueue()}),0);var _this},Dropzone.prototype._thumbnailQueue=[],Dropzone.prototype._processingThumbnail=!1,Dropzone.prototype._enqueueThumbnail=function(file){if(this.options.createImageThumbnails&&file.type.match(/image.*/)&&file.size<=1024*this.options.maxThumbnailFilesize*1024)return this._thumbnailQueue.push(file),setTimeout((_this=this,function(){return _this._processThumbnailQueue()}),0);var _this},Dropzone.prototype._processThumbnailQueue=function(){var _this;if(!this._processingThumbnail&&0!==this._thumbnailQueue.length)return this._processingThumbnail=!0,this.createThumbnail(this._thumbnailQueue.shift(),(_this=this,function(){return _this._processingThumbnail=!1,_this._processThumbnailQueue()}))},Dropzone.prototype.removeFile=function(file){if(file.status===Dropzone.UPLOADING&&this.cancelUpload(file),this.files=without(this.files,file),this.emit("removedfile",file),0===this.files.length)return this.emit("reset")},Dropzone.prototype.removeAllFiles=function(cancelIfNecessary){var file,_i,_len,_ref;for(null==cancelIfNecessary&&(cancelIfNecessary=!1),_i=0,_len=(_ref=this.files.slice()).length;_i<_len;_i++)((file=_ref[_i]).status!==Dropzone.UPLOADING||cancelIfNecessary)&&this.removeFile(file);return null},Dropzone.prototype.createThumbnail=function(file,callback){var fileReader,_this;return(fileReader=new FileReader).onload=(_this=this,function(){return"image/svg+xml"===file.type?(_this.emit("thumbnail",file,fileReader.result),void(null!=callback&&callback())):_this.createThumbnailFromUrl(file,fileReader.result,callback)}),fileReader.readAsDataURL(file)},Dropzone.prototype.createThumbnailFromUrl=function(file,imageUrl,callback){var img,_this;return(img=document.createElement("img")).onload=(_this=this,function(){var canvas,ctx,resizeInfo,thumbnail,_ref,_ref1,_ref2,_ref3;if(file.width=img.width,file.height=img.height,null==(resizeInfo=_this.options.resize.call(_this,file)).trgWidth&&(resizeInfo.trgWidth=resizeInfo.optWidth),null==resizeInfo.trgHeight&&(resizeInfo.trgHeight=resizeInfo.optHeight),ctx=(canvas=document.createElement("canvas")).getContext("2d"),canvas.width=resizeInfo.trgWidth,canvas.height=resizeInfo.trgHeight,drawImageIOSFix(ctx,img,null!=(_ref=resizeInfo.srcX)?_ref:0,null!=(_ref1=resizeInfo.srcY)?_ref1:0,resizeInfo.srcWidth,resizeInfo.srcHeight,null!=(_ref2=resizeInfo.trgX)?_ref2:0,null!=(_ref3=resizeInfo.trgY)?_ref3:0,resizeInfo.trgWidth,resizeInfo.trgHeight),thumbnail=canvas.toDataURL("image/png"),_this.emit("thumbnail",file,thumbnail),null!=callback)return callback()}),null!=callback&&(img.onerror=callback),img.src=imageUrl},Dropzone.prototype.processQueue=function(){var i,parallelUploads,processingLength,queuedFiles;if(parallelUploads=this.options.parallelUploads,i=processingLength=this.getUploadingFiles().length,!(processingLength>=parallelUploads)&&(queuedFiles=this.getQueuedFiles()).length>0){if(this.options.uploadMultiple)return this.processFiles(queuedFiles.slice(0,parallelUploads-processingLength));for(;i<parallelUploads;){if(!queuedFiles.length)return;this.processFile(queuedFiles.shift()),i++}}},Dropzone.prototype.processFile=function(file){return this.processFiles([file])},Dropzone.prototype.processFiles=function(files){var file,_i,_len;for(_i=0,_len=files.length;_i<_len;_i++)(file=files[_i]).processing=!0,file.status=Dropzone.UPLOADING,this.emit("processing",file);return this.options.uploadMultiple&&this.emit("processingmultiple",files),this.uploadFiles(files)},Dropzone.prototype._getFilesWithXhr=function(xhr){var file,files;return function(){var _i,_len,_ref,_results;for(_results=[],_i=0,_len=(_ref=this.files).length;_i<_len;_i++)(file=_ref[_i]).xhr===xhr&&_results.push(file);return _results}.call(this)},Dropzone.prototype.cancelUpload=function(file){var groupedFile,groupedFiles,_i,_j,_len,_len1,_ref;if(file.status===Dropzone.UPLOADING){for(_i=0,_len=(groupedFiles=this._getFilesWithXhr(file.xhr)).length;_i<_len;_i++)(groupedFile=groupedFiles[_i]).status=Dropzone.CANCELED;for(file.xhr.abort(),_j=0,_len1=groupedFiles.length;_j<_len1;_j++)groupedFile=groupedFiles[_j],this.emit("canceled",groupedFile);this.options.uploadMultiple&&this.emit("canceledmultiple",groupedFiles)}else(_ref=file.status)!==Dropzone.ADDED&&_ref!==Dropzone.QUEUED||(file.status=Dropzone.CANCELED,this.emit("canceled",file),this.options.uploadMultiple&&this.emit("canceledmultiple",[file]));if(this.options.autoProcessQueue)return this.processQueue()},resolveOption=function(){var args,option;return option=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[],"function"==typeof option?option.apply(this,args):option},Dropzone.prototype.uploadFile=function(file){return this.uploadFiles([file])},Dropzone.prototype.uploadFiles=function(files){var file,formData,handleError,headerName,headerValue,headers,i,input,inputName,inputType,key,method,option,progressObj,response,updateProgress,url,value,xhr,_i,_j,_k,_l,_len,_len1,_len2,_len3,_m,_ref,_ref1,_ref2,_ref3,_ref4,_ref5,_this;for(xhr=new XMLHttpRequest,_i=0,_len=files.length;_i<_len;_i++)(file=files[_i]).xhr=xhr;for(headerName in method=resolveOption(this.options.method,files),url=resolveOption(this.options.url,files),xhr.open(method,url,!0),xhr.withCredentials=!!this.options.withCredentials,response=null,_this=this,handleError=function(){var _j,_len1,_results;for(_results=[],_j=0,_len1=files.length;_j<_len1;_j++)file=files[_j],_results.push(_this._errorProcessing(files,response||_this.options.dictResponseError.replace("{{statusCode}}",xhr.status),xhr));return _results},updateProgress=function(_this){return function(e){var allFilesFinished,progress,_j,_k,_l,_len1,_len2,_len3,_results;if(null!=e)for(progress=100*e.loaded/e.total,_j=0,_len1=files.length;_j<_len1;_j++)(file=files[_j]).upload={progress:progress,total:e.total,bytesSent:e.loaded};else{for(allFilesFinished=!0,progress=100,_k=0,_len2=files.length;_k<_len2;_k++)100===(file=files[_k]).upload.progress&&file.upload.bytesSent===file.upload.total||(allFilesFinished=!1),file.upload.progress=progress,file.upload.bytesSent=file.upload.total;if(allFilesFinished)return}for(_results=[],_l=0,_len3=files.length;_l<_len3;_l++)file=files[_l],_results.push(_this.emit("uploadprogress",file,progress,file.upload.bytesSent));return _results}}(this),xhr.onload=function(_this){return function(e){var _ref;if(files[0].status!==Dropzone.CANCELED&&4===xhr.readyState){if(response=xhr.responseText,xhr.getResponseHeader("content-type")&&~xhr.getResponseHeader("content-type").indexOf("application/json"))try{response=JSON.parse(response)}catch(_error){e=_error,response="Invalid JSON response from server."}return updateProgress(),200<=(_ref=xhr.status)&&_ref<300?_this._finished(files,response,e):handleError()}}}(this),xhr.onerror=function(_this){return function(){if(files[0].status!==Dropzone.CANCELED)return handleError()}}(this),(progressObj=null!=(_ref=xhr.upload)?_ref:xhr).onprogress=updateProgress,headers={Accept:"application/json","Cache-Control":"no-cache","X-Requested-With":"XMLHttpRequest"},this.options.headers&&extend(headers,this.options.headers),headers)(headerValue=headers[headerName])&&xhr.setRequestHeader(headerName,headerValue);if(formData=new FormData,this.options.params)for(key in _ref1=this.options.params)value=_ref1[key],formData.append(key,value);for(_j=0,_len1=files.length;_j<_len1;_j++)file=files[_j],this.emit("sending",file,xhr,formData);if(this.options.uploadMultiple&&this.emit("sendingmultiple",files,xhr,formData),"FORM"===this.element.tagName)for(_k=0,_len2=(_ref2=this.element.querySelectorAll("input, textarea, select, button")).length;_k<_len2;_k++)if(inputName=(input=_ref2[_k]).getAttribute("name"),inputType=input.getAttribute("type"),"SELECT"===input.tagName&&input.hasAttribute("multiple"))for(_l=0,_len3=(_ref3=input.options).length;_l<_len3;_l++)(option=_ref3[_l]).selected&&formData.append(inputName,option.value);else(!inputType||"checkbox"!==(_ref4=inputType.toLowerCase())&&"radio"!==_ref4||input.checked)&&formData.append(inputName,input.value);for(i=_m=0,_ref5=files.length-1;0<=_ref5?_m<=_ref5:_m>=_ref5;i=0<=_ref5?++_m:--_m)formData.append(this._getParamName(i),files[i],files[i].name);return this.submitRequest(xhr,formData,files)},Dropzone.prototype.submitRequest=function(xhr,formData,files){return xhr.send(formData)},Dropzone.prototype._finished=function(files,responseText,e){var file,_i,_len;for(_i=0,_len=files.length;_i<_len;_i++)(file=files[_i]).status=Dropzone.SUCCESS,this.emit("success",file,responseText,e),this.emit("complete",file);if(this.options.uploadMultiple&&(this.emit("successmultiple",files,responseText,e),this.emit("completemultiple",files)),this.options.autoProcessQueue)return this.processQueue()},Dropzone.prototype._errorProcessing=function(files,message,xhr){var file,_i,_len;for(_i=0,_len=files.length;_i<_len;_i++)(file=files[_i]).status=Dropzone.ERROR,this.emit("error",file,message,xhr),this.emit("complete",file);if(this.options.uploadMultiple&&(this.emit("errormultiple",files,message,xhr),this.emit("completemultiple",files)),this.options.autoProcessQueue)return this.processQueue()},Dropzone}(Emitter)).version="4.1.0",Dropzone.options={},Dropzone.optionsForElement=function(element){return element.getAttribute("id")?Dropzone.options[camelize(element.getAttribute("id"))]:void 0},Dropzone.instances=[],Dropzone.forElement=function(element){if("string"==typeof element&&(element=document.querySelector(element)),null==(null!=element?element.dropzone:void 0))throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");return element.dropzone},Dropzone.autoDiscover=!0,Dropzone.discover=function(){var checkElements,dropzone,dropzones,_i,_len,_results;for(document.querySelectorAll?dropzones=document.querySelectorAll(".dropzone"):(dropzones=[],(checkElements=function(elements){var el,_i,_len,_results;for(_results=[],_i=0,_len=elements.length;_i<_len;_i++)el=elements[_i],/(^| )dropzone($| )/.test(el.className)?_results.push(dropzones.push(el)):_results.push(void 0);return _results})(document.getElementsByTagName("div")),checkElements(document.getElementsByTagName("form"))),_results=[],_i=0,_len=dropzones.length;_i<_len;_i++)dropzone=dropzones[_i],!1!==Dropzone.optionsForElement(dropzone)?_results.push(new Dropzone(dropzone)):_results.push(void 0);return _results},Dropzone.blacklistedBrowsers=[/opera.*Macintosh.*version\/12/i],Dropzone.isBrowserSupported=function(){var capableBrowser,regex,_i,_len,_ref;if(capableBrowser=!0,window.File&&window.FileReader&&window.FileList&&window.Blob&&window.FormData&&document.querySelector)if("classList"in document.createElement("a"))for(_i=0,_len=(_ref=Dropzone.blacklistedBrowsers).length;_i<_len;_i++)(regex=_ref[_i]).test(navigator.userAgent)&&(capableBrowser=!1);else capableBrowser=!1;else capableBrowser=!1;return capableBrowser},without=function(list,rejectedItem){var item,_i,_len,_results;for(_results=[],_i=0,_len=list.length;_i<_len;_i++)(item=list[_i])!==rejectedItem&&_results.push(item);return _results},camelize=function(str){return str.replace(/[\-_](\w)/g,(function(match){return match.charAt(1).toUpperCase()}))},Dropzone.createElement=function(string){var div;return(div=document.createElement("div")).innerHTML=string,div.childNodes[0]},Dropzone.elementInside=function(element,container){if(element===container)return!0;for(;element=element.parentNode;)if(element===container)return!0;return!1},Dropzone.getElement=function(el,name){var element;if("string"==typeof el?element=document.querySelector(el):null!=el.nodeType&&(element=el),null==element)throw new Error("Invalid `"+name+"` option provided. Please provide a CSS selector or a plain HTML element.");return element},Dropzone.getElements=function(els,name){var e,el,elements,_i,_j,_len,_len1,_ref;if(els instanceof Array){elements=[];try{for(_i=0,_len=els.length;_i<_len;_i++)el=els[_i],elements.push(this.getElement(el,name))}catch(_error){e=_error,elements=null}}else if("string"==typeof els)for(elements=[],_j=0,_len1=(_ref=document.querySelectorAll(els)).length;_j<_len1;_j++)el=_ref[_j],elements.push(el);else null!=els.nodeType&&(elements=[els]);if(null==elements||!elements.length)throw new Error("Invalid `"+name+"` option provided. Please provide a CSS selector, a plain HTML element or a list of those.");return elements},Dropzone.confirm=function(question,accepted,rejected){return window.confirm(question)?accepted():null!=rejected?rejected():void 0},Dropzone.isValidFile=function(file,acceptedFiles){var baseMimeType,mimeType,validType,_i,_len;if(!acceptedFiles)return!0;for(acceptedFiles=acceptedFiles.split(","),baseMimeType=(mimeType=file.type).replace(/\/.*$/,""),_i=0,_len=acceptedFiles.length;_i<_len;_i++)if("."===(validType=(validType=acceptedFiles[_i]).trim()).charAt(0)){if(-1!==file.name.toLowerCase().indexOf(validType.toLowerCase(),file.name.length-validType.length))return!0}else if(/\/\*$/.test(validType)){if(baseMimeType===validType.replace(/\/.*$/,""))return!0}else if(mimeType===validType)return!0;return!1},"undefined"!=typeof jQuery&&null!==jQuery&&(jQuery.fn.dropzone=function(options){return this.each((function(){return new Dropzone(this,options)}))}),"undefined"!=typeof module&&null!==module?module.exports=Dropzone:window.Dropzone=Dropzone,Dropzone.ADDED="added",Dropzone.QUEUED="queued",Dropzone.ACCEPTED=Dropzone.QUEUED,Dropzone.UPLOADING="uploading",Dropzone.PROCESSING=Dropzone.UPLOADING,Dropzone.CANCELED="canceled",Dropzone.ERROR="error",Dropzone.SUCCESS="success",detectVerticalSquash=function(img){var alpha,canvas,ctx,data,ey,ih,iw,py,ratio,sy;for(iw=img.naturalWidth,ih=img.naturalHeight,(canvas=document.createElement("canvas")).width=1,canvas.height=ih,(ctx=canvas.getContext("2d")).drawImage(img,0,0),data=ctx.getImageData(0,0,1,ih).data,sy=0,ey=ih,py=ih;py>sy;)0===(alpha=data[4*(py-1)+3])?ey=py:sy=py,py=ey+sy>>1;return 0===(ratio=py/ih)?1:ratio},drawImageIOSFix=function(ctx,img,sx,sy,sw,sh,dx,dy,dw,dh){var vertSquashRatio;return vertSquashRatio=detectVerticalSquash(img),ctx.drawImage(img,sx,sy,sw,sh,dx,dy,dw,dh/vertSquashRatio)},contentLoaded=function(win,fn){var add,doc,done,init,poll,pre,rem,root,top;if(done=!1,top=!0,doc=win.document,root=doc.documentElement,add=doc.addEventListener?"addEventListener":"attachEvent",rem=doc.addEventListener?"removeEventListener":"detachEvent",pre=doc.addEventListener?"":"on",init=function(e){if("readystatechange"!==e.type||"complete"===doc.readyState)return("load"===e.type?win:doc)[rem](pre+e.type,init,!1),!done&&(done=!0)?fn.call(win,e.type||e):void 0},poll=function(){var e;try{root.doScroll("left")}catch(_error){return e=_error,void setTimeout(poll,50)}return init("poll")},"complete"!==doc.readyState){if(doc.createEventObject&&root.doScroll){try{top=!win.frameElement}catch(_error){}top&&poll()}return doc[add](pre+"DOMContentLoaded",init,!1),doc[add](pre+"readystatechange",init,!1),win[add](pre+"load",init,!1)}},Dropzone._autoDiscoverFunction=function(){if(Dropzone.autoDiscover)return Dropzone.discover()},contentLoaded(window,Dropzone._autoDiscoverFunction)}).call(this);
|
|
//# sourceMappingURL=dropzone.min.js.map
|