");if(h.addClass("upload-item is-uploaded"),h.attr("data-id",e[i].id),!this.isMultiple){var r=this.$box.find("img");return 0!==r.length&&this._removeFileRequest(this.$box.attr("data-id")),this.$box.html(""),this.$box.attr("data-id",e[i].id),this.$box.append(a),this.$box.append(s),void this.$box.append(n)}h.append(a),h.append(s),h.append(n),this.$box.last().before(h)}},_completeBoxFile:function(e){this.isMultiple||this._clearTarget();for(var i in e){var s=t.dom("
");s.addClass("upload-item"),s.attr("data-id",e[i].id);var a=t.dom("");a.html(e[i].name);var n=t.dom("");n.addClass("close"),n.on("click",this._removeFile.bind(this));var h=t.dom("");if(h.attr("type","hidden"),h.attr("name",this._getHiddenName()),h.val(e[i].id),"undefined"!=typeof e[i].size){var r=t.dom("");r.html(e[i].size),a.append(r)}s.append(n),s.append(a),s.append(h),this.$target.append(s),this._upCount()}}})}(Kube),function(t){t.add("module","validate",{init:function(t,e){this.app=t,this.$win=t.$win,this.progress=t.progress,this.response=t.response;var i={errorClass:"is-error",send:!0,trigger:!1,shortcut:!1,progress:!1};this.context=e,this.params=e.getParams(i),this.$element=e.getElement()},start:function(){this._disableDefaultValidation(),this._enableShortcut(),this.params.trigger?this._startTrigger():this._startSubmit()},stop:function(){this.enableButtons(),this.clear(),this.$element.off(".kube.validate"),this.$win.off(".kube.validate"),this.$trigger&&this.$trigger.off(".")},clear:function(){this.$element.find("."+this.params.errorClass).each(this._clearError.bind(this))},disableButtons:function(){this.$element.find("button").attr("disabled",!0)},enableButtons:function(){this.$element.find("button").removeAttr("disabled")},_build:function(t){return t.preventDefault(),this.params.send?this._send():this.app.broadcast("validate.send",this),!1},_send:function(){return this.params.progress&&this.progress.show(),this.disableButtons(),this._saveCodeMirror(),this.app.broadcast("validate.send",this),t.ajax.post({url:this.$element.attr("action"),data:this.$element.serialize(),success:this._parse.bind(this)}),!1},_parse:function(t){this.enableButtons(),this.clear(),this.params.progress&&this.progress.hide();var e=this.response.parse(t);e?"undefined"!=typeof e.type&&"error"===e.type?(this._setErrors(e.errors),this.app.broadcast("validate.error",this,e.errors)):this.app.broadcast("validate.success",this,e):this.app.broadcast("validate.error",this,e)},_setErrors:function(t){for(var e in t){var i=t[e],s=this.$element.find("[name="+e+"]");0!==s.length&&(s.addClass(this.params.errorClass),this._setFieldEvent(s,e),""!==i&&this._showErrorText(e,i))}},_setFieldEvent:function(t,e){var i=this._getFieldEventName(t);t.on(i+".kube.validate",function(){this._clearError(t)}.bind(this))},_showErrorText:function(t,e){var i=this.$element.find("#"+t+"-validation-error");i.addClass(this.params.errorClass),i.html(e),i.removeClass("is-hidden")},_getFieldEventName:function(t){return"SELECT"===t.get().tagName||"checkbox"===t.attr("type")||"radio"===t.attr("type")?"change":"keyup"},_clearError:function(e){var i=t.dom(e),s=this.$element.find("#"+i.attr("name")+"-validation-error");s.removeClass(this.params.errorClass),s.html(""),s.addClass("is-hidden"),i.removeClass(this.params.errorClass).off(".kube.validate")},_saveCodeMirror:function(){t.dom(".CodeMirror").each(function(t){t.CodeMirror.save()})},_disableDefaultValidation:function(){this.$element.attr("novalidate","novalidate")},_enableShortcut:function(){this.params.shortcut&&this.$win.on("keydown.kube.validate",this._handleShortcut.bind(this))},_handleShortcut:function(t){return(t.ctrlKey||t.metaKey)&&83===t.which?(t.preventDefault(),this._send()):!0},_startTrigger:function(){this.$trigger=$(this.opts.trigger),this.$element.on("submit",function(){return!1}),this.$trigger.off(".kube.validate"),this.$trigger.on("click.kube.validate",this._build.bind(this))},_startSubmit:function(){this.$element.on("submit.kube.validate",this._build.bind(this))}})}(Kube),function(t){t.add("module","visibility",{init:function(t,e){this.app=t,this.$win=t.$win;var i={tolerance:15};this.context=e,this.params=e.getParams(i),this.$element=e.getElement()},start:function(){this.$win.on("scroll.kube.visibility resize.kube.visibility",this._check.bind(this)),this._check()},stop:function(){this.$win.off(".kube.visibility")},_check:function(){var t=this.$win.scrollTop(),e=t+this.$win.height(),i=this.$element.offset().top,s=i+this.$element.height(),a=s>=t&&e>=i&&s<=e+this.params.tolerance&&i>=t;a?this.app.broadcast("visibility.visible",this,this.$element):this.app.broadcast("visibility.invisible",this,this.$element)}})}(Kube);