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.

0 lines
6.9 KiB

  1. !function(t){t.add("module","upload",{init:function(t,i){this.app=t,this.utils=t.utils,this.animate=t.animate,this.response=t.response,this.progress=t.progress;var e={size:120,url:!1,urlRemove:!1,param:!1,type:!1,multiple:!1,placeholder:"Drop files here or click to upload",progress:!1,target:!1,append:!1};this.context=i,this.params=i.getParams(e),this.$element=i.getElement(),this.$target=i.getTarget(),this.statusMap=["hover","error","success","drop"]},start:function(){this._buildBox(),this._buildInput(),this._buildCount(),this._buildType(),this._buildPlaceholder(),this._buildSize(),this._buildMultiple(),this._buildItems(),this._buildEvents()},stop:function(){this.$box.remove(),this.$element.off(".kube.upload")},_buildBox:function(){"image"===this.params.type?this.$box=this.$element.find(".upload-item"):this.$box=this.$element},_buildInput:function(){this.$input=t.dom("<input>"),this.$input.attr("type","file"),this.$input.attr("name",this._getParamName()),this.$input.hide(),this.$element.before(this.$input)},_buildCount:function(){this.$inputCount=t.dom("<input>"),this.$inputCount.attr("type","hidden"),this.$inputCount.attr("name",this._getParamName()+"-count"),this.$inputCount.val(0),this.$element.before(this.$inputCount)},_buildType:function(){this.isBox=this.$element.hasClass("upload")},_buildPlaceholder:function(){if(this.isBox){var i=t.dom("<span>");i.addClass("upload-placeholder"),i.html(this.params.placeholder),this.$element.append(i)}},_buildSize:function(){this.isBox?this.$box.css({height:this.params.size+"px"}):"image"===this.params.type&&this.$box.css({width:this.params.size+"px",height:this.params.size+"px"})},_buildMultiple:function(){this.isMultiple=this.params.multiple,this.isMultiple&&this.$input.attr("multiple","true")},_buildItems:function(){if(this.params.type){var t="file"===this.params.type,i=t?this.$target:this.$element,e=t?"_removeFile":"_removeImage",s=i.find(".close");s.on("click",this[e].bind(this)),t||s.closest(".upload-item").addClass("is-uploaded"),this.$inputCount.val(s.length)}},_buildEvents:function(){this.$input.on("change.redactor.upload",this._change.bind(this)),this.$box.on("click.redactor.upload",this._click.bind(this)),this.$box.on("drop.redactor.upload",this._drop.bind(this)),this.$box.on("dragover.redactor.upload",this._dragover.bind(this)),this.$box.on("dragleave.redactor.upload",this._dragleave.bind(this))},_click:function(i){i.preventDefault();var e=t.dom(i.target);e.hasClass("close")||this.$input.click()},_change:function(t){this.app.broadcast("upload.start",this),this._send(t,this.$input.get().files)},_drop:function(t){t.preventDefault(),this._clearStatuses(),this._setStatus("drop"),this.app.broadcast("upload.start",this),this._send(t)},_dragover:function(t){return t.preventDefault(),this._setStatus("hover"),!1},_dragleave:function(t){return t.preventDefault(),this._removeStatus("hover"),!1},_upCount:function(){var t=this.$inputCount.val();t++,this.$inputCount.val(t)},_downCount:function(){var t=this.$inputCount.val();t--,t=0>t?0:t,this.$inputCount.val(t)},_clearCount:function(){this.$inputCount.val(0)},_getParamName:function(){return this.params.param?this.params.param:"file"},_getHiddenName:function(){var t=this._getParamName();return this.isMultiple?t+"-uploaded[]":t+"-uploaded"},_clearStatuses:function(){this.$box.removeClass("is-upload-"+this.statusMap.join(" is-upload-"))},_setStatus:function(t){this.$box.addClass("is-upload-"+t)},_removeStatus:function(t){this.$box.removeClass("is-upload-"+t)},_clearTarget:function(){var i=this.$target.find(".upload-item");i.each(function(i){var e=t.dom(i);this._removeFileRequest(e.attr("data-id"))}.bind(this)),this._clearCount(),this.$target.html("")},_clearBox:function(){var i=this.$target.find(".upload-item");i.each(function(i){var e=t.dom(i);this._removeFileRequest(e.attr("data-id"))}.bind(this)),this._clearCount(),this.$target.html("")},_removeFile:function(i){i.preventDefault();var e=t.dom(i.target),s=e.closest(".upload-item"),a=s.attr("data-id");this.animate.run(s,"fadeOut",function(){s.remove(),this._downCount(),this._removeFile