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.
 
 
 
 

2 lines
37 KiB

!function(t){t.add("module","autocomplete",{init:function(t,e){this.app=t,this.$doc=t.$doc,this.$win=t.$win,this.$body=t.$body,this.animate=t.animate;var i={url:!1,min:2,labelClass:!1,target:!1,param:!1};this.context=e,this.params=e.getParams(i),this.$element=e.getElement(),this.$target=e.getTarget()},start:function(){this._build(),this.timeout=null,this.$element.on("keyup.kube.autocomplete",this._open.bind(this))},stop:function(){this.$box.remove(),this.$element.off(".kube.autocomplete"),this.$doc.off(".kube.autocomplete"),this.$win.off(".kube.autocomplete")},_build:function(){if(this.$box=t.dom("<div />"),this.$box.addClass("autocomplete"),this.$box.addClass("is-hidden"),this.$body.append(this.$box),this.$target&&!this._isInputTarget()){this.$target.addClass("autocomplete-labels");var e=this.$target.find(".close");e.on("click",this._removeLabel.bind(this))}},_open:function(t){t&&t.preventDefault(),clearTimeout(this.timeout);var e=this.$element.val();e.length>=this.params.min?(this._resize(),this.$win.on("resize.kube.autocomplete",this._resize.bind(this)),this.$doc.on("click.kube.autocomplete",this._close.bind(this)),this.$box.addClass("is-open"),this._listen(t)):this._close(t)},_close:function(t){t&&t.preventDefault(),this.$box.removeClass("is-open"),this.$box.addClass("is-hidden"),this.$doc.off(".kube.autocomplete"),this.$win.off(".kube.autocomplete")},_getPlacement:function(t,e){return this.$doc.height()-(t.top+e)<this.$box.height()?"top":"bottom"},_resize:function(){this.$box.width(this.$element.width())},_getParamName:function(){return this.params.param?this.params.param:this.$element.attr("name")},_getTargetName:function(){var t=this.$target.attr("data-name");return t?t:this.$target.attr("id")},_lookup:function(){var e=this._getParamName()+"="+this.$element.val();t.ajax.post({url:this.params.url,data:e,success:this._complete.bind(this)})},_complete:function(e){if(this.$box.html(""),0===e.length)return this._close();for(var i=0;i<e.length;i++){var s=t.dom("<a>");s.attr("href","#"),s.attr("rel",e[i].id),s.html(e[i].name),s.on("click",this._set.bind(this)),this.$box.append(s)}var a=this.$element.offset(),n=this.$element.height(),h=this.$element.width(),r=this._getPlacement(a,n),o="top"===r?a.top-this.$box.height()-n:a.top+n;this.$box.css({width:h+"px",top:o+"px",left:a.left+"px"}),this.$box.removeClass("is-hidden")},_listen:function(t){switch(t.which){case 40:t.preventDefault(),this._select("next");break;case 38:t.preventDefault(),this._select("prev");break;case 13:t.preventDefault(),this._set();break;case 27:this._close(t);break;default:this.timeout=setTimeout(this._lookup.bind(this),300)}},_select:function(t){var e=this.$box.find("a"),i=this.$box.find(".is-active");e.removeClass("is-active");var s=this._selectItem(i,e,t);s.addClass("is-active")},_selectItem:function(t,e,i){var s,a=0!==t.length,n="next"===i?0:e.length-1;return a&&(s=t[i]()),a&&s&&0!==s.length||(s=e.eq(n)),s},_set:function(e){var i=this.$box.find(".is-active");e&&(e.preventDefault(),i=t.dom(e.target));var s=i.attr("rel"),a=i.html();if(0!==this.$target.length){if(this._isInputTarget())this.$target.val(a);else{var n=this.$target.find('[data-id="'+s+'"]');0===n.length&&this._addLabel(s,a)}this.$element.val("")}else this.$element.val(a);this.$element.focus(),this.app.broadcast("autocomplete.set",this,a),this._close()},_addLabel:function(e,i){var s=t.dom("<span>");s.addClass("label"),s.attr("data-id",e),s.text(i+" "),this.params.labelClass&&s.addClass(this.params.labelClass);var a=t.dom("<span>");a.addClass("close"),a.on("click",this._removeLabel.bind(this));var n=t.dom("<input>");n.attr("type","hidden"),n.attr("name",this._getTargetName()+"[]"),n.val(i),s.append(a),s.append(n),this.$target.append(s)},_isInputTarget:function(){return"INPUT"===this.$target.get().tagName},_removeLabel:function(e){e.preventDefault();var i=t.dom(e.target),s=i.closest(".label");this.animate.run(s,"fadeOut",function(){s.remove()}.bind(this))}})}(Kube),function(t){t.add("module","combobox",{init:function(t,e){this.app=t,this.$win=t.$win;var i={placeholder:""};this.context=e,this.params=e.getParams(i),this.$element=e.getElement()},start:function(){this._buildSource(),this._buildCaret(),this._buildEvent()},stop:function(){this.$sourceBox.after(this.$element),this.$sourceBox.remove(),this.$element.off(".kube.combobox"),this.$win.off(".kube.combobox")},_buildSource:function(){this.$sourceBox=t.dom("<div>"),this.$sourceBox.addClass("combobox"),this.$source=t.dom("<input>"),this.$source.attr("type","text"),this.$source.attr("placeholder",this.params.placeholder),this.$sourceBox.width(this.$element.width()),this.$sourceBox.append(this.$source),this.$element.after(this.$sourceBox),this.$element.attr("class",""),this.$element.attr("style",""),this.$sourceBox.append(this.$element),this.$win.on("resize.kube.combobox",this._resize.bind(this))},_buildCaret:function(){this.$sourceCaret=t.dom("<span>"),this.$sourceCaret.addClass("combobox-caret"),this.$sourceBox.append(this.$sourceCaret)},_buildEvent:function(){this.$element.on("change.kube.combobox",this._select.bind(this)),this.$source.on("keyup.kube.combobox",this._type.bind(this))},_resize:function(){this.$sourceBox.width(this.$element.width())},_type:function(e){var i=this.$source.val();this.app.broadcast("combobox.set",this,i),this.$sourceValue&&this.$sourceValue.remove(),""!==i.trim()&&(this.$sourceValue=t.dom("<option>"),this.$sourceValue.attr("value",i),this.$sourceValue.attr("selected",!0),this.$sourceValue.text(i),this.$sourceValue.addClass("is-hidden"),this.$element.append(this.$sourceValue))},_select:function(t){var e=t.target,i=e.options[e.selectedIndex].text;this.$sourceValue&&this.$sourceValue.remove(),this.$source.val(i),this.app.broadcast("combobox.set",this,i)}})}(Kube),function(t){var e=0;t.add("module","datepicker",{translations:{en:{days:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],months:["","January","February","March","April","May","June","July","August","September","October","November","December"],"months-short":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}},init:function(t,i){this.app=t,this.$doc=t.$doc,this.$win=t.$win,this.$body=t.$body,this.lang=t.lang,this.animate=t.animate;var s={year:!1,month:!1,day:!1,format:"%d.%m.%Y",embed:!1,target:!1,selectYear:!1,sundayFirst:!1,startDate:!1,endDate:!1,animationOpen:"slideDown",animationClose:"slideUp"};this.context=i,this.params=i.getParams(s),this.$element=i.getElement(),this.$target=i.getTarget(),this.uuid=e++,this.namespace=".kube.datepicker-"+this.uuid,this.dateRegexp=/^(.*?)(\/|\.|,|\s|\-)(.*?)(?:\/|\.|,|\s|\-)(.*?)$/,this.value="",this.today={},this.current={},this.next={},this.prev={},this.selected={}},start:function(){this.$element.attr("uuid",this.uuid),this._buildStartEndDate(),this.$datepicker=t.create("class.datepicker.box",this.app,this),this.$datepicker.build(),this.params.embed?(this.build(),this.update(),this.$datepicker.addClass("is-embed"),this.$element.append(this.$datepicker)):(this.$datepicker.addClass("is-hidden"),this.$body.append(this.$datepicker),this.$element.on("click"+this.namespace,this._open.bind(this)))},stop:function(){this._disableEvents(),this.$datepicker.remove(),this.$element.off(this.namespace),this.$element.removeClass("datepicker-in")},build:function(){this._buildValue(),this._buildTodayDate(),this._buildSelectedDate(),this._buildCurrentDate()},update:function(){this._buildPrevNextDate(),this.$grid=t.create("class.datepicker.grid",this.app,this),this.$grid.build(),this.$datepicker.setControls(this.prev,this.next),this.$datepicker.setMonth(this.lang.get("months")[this.current.month]),this.$datepicker.setYear(this.current.year),this.$datepicker.setGrid(this.$grid)},setDate:function(e){e.preventDefault();var i=t.dom(e.target);if(i.attr("data-disabled")===!0)return this._close();var s={day:i.attr("data-day"),month:i.attr("data-month"),year:i.attr("data-year")},a=this._convertDateToFormat(s);if(this.params.embed===!1){var n=0!==this.$target.length?this.$target:this.$element;"INPUT"===n.get().tagName?n.val(a):n.text(a),this._close()}this.app.broadcast("datepicker.set",this,a,s)},setNextMonth:function(t){t.preventDefault(),this.current=this.next,this.update()},setPrevMonth:function(t){t.preventDefault(),this.current=this.prev,this.update()},setYear:function(){this.current.year=this.$datepicker.getYearFromSelect(),this.selected.day=!1,this.$datepicker.setYear(this.current.year),this.update()},_buildValue:function(){var t=0!==this.$target.length?this.$target:this.$element;this.value="INPUT"===t.get().tagName?t.val():t.text().trim()},_buildTodayDate:function(){var t=new Date;this.today={year:t.getFullYear(),month:parseInt(t.getMonth()+1),day:parseInt(t.getDate())}},_buildSelectedDate:function(){this.selected=this._parseDateString(this.value),""===this.value&&(this.selected.year=this.params.year?this.params.year:this.selected.year,this.selected.month=this.params.month?parseInt(this.params.month):this.selected.month,this.selected.day=!1)},_buildCurrentDate:function(){this.current=this.selected},_buildPrevNextDate:function(){var t=this._getPrevYearAndMonth(this.current.year,this.current.month);this.prev={year:t.year,month:t.month};var t=this._getNextYearAndMonth(this.current.year,this.current.month);this.next={year:t.year,month:t.month}},_buildStartEndDate:function(){this.params.startDate=this.params.startDate?this._parseDateString(this.params.startDate):!1,this.params.endDate=this.params.endDate?this._parseDateString(this.params.endDate):!1},_buildPosition:function(){this.position={};var t=this.$element.offset(),e=this.$element.innerHeight(),i=this.$element.innerWidth(),s=this.$datepicker.innerWidth(),a=this.$datepicker.innerHeight(),n=this.$win.width(),h=this.$doc.height(),r=0,o=t.left,d=t.top+e+1;this.position.type="left",o+s>n&&(this.position.type="right",r=n-(o+i)),d+a>h&&(this.params.animationOpen="show",this.params.animationClose="hide",d=d-a-e-2),this.position.top=d,this.position.left=o,this.position.right=r},_open:function(t){t&&t.preventDefault(),this._isOpened()||(this._closeAll(),this.app.broadcast("datepicker.open",this),this.build(),this.update(),this._buildPosition(),this._setPosition(),this.animate.run(this.$datepicker,this.params.animationOpen,this._opened.bind(this)))},_opened:function(){this._enableEvents(),this.$element.addClass("datepicker-in"),this.$datepicker.addClass("is-open"),this.app.broadcast("datepicker.opened",this)},_isOpened:function(){return this.$datepicker.hasClass("is-open")},_close:function(e){e&&0!==t.dom(e.target).closest(".datepicker").length||this._isOpened()&&(this.app.broadcast("datepicker.close",this),this.animate.run(this.$datepicker,this.params.animationClose,this._closed.bind(this)))},_closed:function(){this._disableEvents(),this.$datepicker.removeClass("is-open"),this.$element.removeClass("datepicker-in"),this.app.broadcast("datepicker.closed",this)},_closeAll:function(){t.dom(".datepicker.is-open").each(function(e){var i=t.dom(e),s=i.attr("data-uuid");this.$doc.off(".kube.datepicker-"+s),this.$win.off(".kube.datepicker-"+s),i.removeClass("is-open"),i.addClass("is-hidden")}.bind(this)),t.dom(".datepicker-in").removeClass("datepicker-in")},_handleKeyboard:function(t){27===t.which&&this._close()},_enableEvents:function(){this.$doc.on("keyup"+this.namespace,this._handleKeyboard.bind(this)),this.$doc.on("click"+this.namespace+" touchstart"+this.namespace,this._close.bind(this)),this.$win.on("resize"+this.namespace,this._resizePosition.bind(this))},_disableEvents:function(){this.$doc.off(this.namespace),this.$win.off(this.namespace)},_resizePosition:function(){this._buildPosition(),this._setPosition()},_setPosition:function(){var t="auto",e=this.position.right+"px";"left"===this.position.type&&(t=this.position.left+"px",e="auto"),this.$datepicker.css({top:this.position.top+"px",left:t,right:e})},_parseDateString:function(t){var e={},i=t.match(this.dateRegexp),s=this.params.format.match(this.dateRegexp);return e.year=null===i?this.today.year:parseInt(i[4]),"%m"===s[1]||"%M"===s[1]||"%F"===s[1]?(e.month=null===i?this.today.month:this._parseMonth(s[1],i[1]),e.day=null===i?!1:parseInt(i[3])):(e.month=null===i?this.today.month:this._parseMonth(s[3],i[3]),e.day=null===i?!1:parseInt(i[1])),e.splitter=null===i?".":i[2],e},_parseMonth:function(t,e){var i=parseInt(e);return"%M"===t?i=this.lang.get("months-short").indexOf(e):"%F"===t&&(i=this.lang.get("months").indexOf(e)),i},_convertDateToFormat:function(t){var e=this.params.format.replace("%d",t.day);return e=e.replace("%F",this.lang.get("months")[t.month]),e=e.replace("%m",this._addZero(t.month)),e=e.replace("%M",this.lang.get("months-short")[t.month]),e=e.replace("%Y",t.year)},_addZero:function(t){return t=Number(t),10>t?"0"+t:t},_getPrevYearAndMonth:function(t,e){var i={year:t,month:parseInt(e)-1};return i.month<=0&&(i.month=12,i.year--),i},_getNextYearAndMonth:function(t,e){var i={year:t,month:parseInt(e)+1};return i.month>12&&(i.month=1,i.year++),i}})}(Kube),function(t){t.add("class","datepicker.box",{"extends":["dom"],init:function(t,e){this.app=t,this.lang=t.lang,this.datepicker=e,this.params=e.params,this.namespace=e.namespace,this.selected=e.selected},build:function(){this._buildBox(),this._buildHead(),this._buildControlPrev(),this._buildMonthBox(),this._buildControlNext(),this._buildWeekdays(),this._buildBody()},getYearFromSelect:function(){return Number(this.$yearSelect.val())},setMonth:function(t){this.$month.html(t)},setYear:function(t){this.$yearValue.html(t),this.params.selectYear&&this.$yearSelect&&this.$yearSelect.val(t)},setGrid:function(t){this.$dbody.html(""),this.$dbody.append(t)},setControls:function(t,e){var i=function(t,e){return e=e?e:t.day,new Date(t.year+"/"+t.month+"/"+e)};if(this.params.startDate){var s=i(t,31),a=i(this.params.startDate),n=a.getTime()>s.getTime()?"hide":"show";this.$prev[n]()}if(this.params.endDate){var h=i(e,1),r=i(this.params.endDate),n=r.getTime()<h.getTime()?"hide":"show";this.$next[n]()}},_buildBox:function(){this.parse("<div>"),this.addClass("datepicker")},_buildHead:function(){this.$head=t.dom('<div class="datepicker-head">'),this.append(this.$head)},_buildControlPrev:function(){this.$prev=t.dom('<span class="datepicker-control datepicker-control-prev" />').html("&lt;"),this.$prev.on("click"+this.namespace,this.datepicker.setPrevMonth.bind(this.datepicker)),this.$head.append(this.$prev)},_buildControlNext:function(){this.$next=t.dom('<span class="datepicker-control datepicker-control-next" />').html("&gt;"),this.$next.on("click"+this.namespace,this.datepicker.setNextMonth.bind(this.datepicker)),this.$head.append(this.$next)},_buildMonthBox:function(){this.$monthBox=t.dom('<div class="datepicker-month-box">'),this.$head.append(this.$monthBox),this._buildMonth(),this._buildYear(),this._buildYearSelect()},_buildMonth:function(){this.$month=t.dom("<span />"),this.$monthBox.append(this.$month)},_buildYear:function(){this.$year=t.dom("<span />"),this.$yearValue=t.dom("<span />"),this.$year.append(this.$yearValue),this.$monthBox.append(this.$year)},_buildYearSelect:function(){if(this.params.selectYear){var e=new Date,i=this.params.startDate?this.params.startDate.year:e.getFullYear()-99,s=this.params.endDate?this.params.endDate.year:e.getFullYear();if(!(2>s-i)){this.$yearSelect=t.dom("<select />"),this.$year.append(this.$yearSelect),this.$year.append('<span class="datepicker-select-year-caret" />'),this.$year.addClass("datepicker-select-year");for(var a=i;s>=a;a++){var n=t.dom('<option value="'+a+'">'+a+"</option>");this.$yearSelect.append(n)}this.$yearSelect.on("change"+this.namespace,this.datepicker.setYear.bind(this.datepicker))}}},_buildWeekdays:function(){this.$weekdays=t.dom('<div class="datepicker-weekdays">');var e=[];if(this.params.sundayFirst){var i=this.lang.get("days").slice(6);e=this.lang.get("days").slice(0,6),e.unshift(i[0])}else e=this.lang.get("days");for(var s=0;s<e.length;s++){var a=t.dom("<span>").html(e[s]);this.$weekdays.append(a)}this.append(this.$weekdays)},_buildBody:function(){this.$dbody=t.dom('<div class="datepicker-body">'),this.append(this.$dbody)}})}(Kube),function(t){t.add("class","datepicker.grid",{"extends":["dom"],init:function(t,e){this.app=t,this.lang=t.lang,this.datepicker=e,this.params=e.params,this.namespace=e.namespace,this.today=e.today,this.selected=e.selected,this.current=e.current,this.prev=e.prev,this.next=e.next,this.daysInMonth=[0,31,28,31,30,31,30,31,31,30,31,30,31]},build:function(){this.parse('<div class="datepicker-grid">');for(var e,i=this._getDaysInCurrentMonth(),s=this._getDaysInPrevMonth(),a=(this._getDaysInNextMonth(),new Date(this.current.year,this.current.month-1,1)),n=this.params.sundayFirst?a.getDay()+1:a.getDay()?a.getDay():7,h=s-n+2,r=1,o=1,d=0;6>d;d++){for(var l=t.dom('<div class="datepicker-row">'),u=0;7>u;u++){if(0===d){var c=h+u;c>s?(e=this._buildGridObj(u,r,this.current,!1,!1),r++):e=this._buildGridObj(u,c,this.prev,!1,!0)}else r>i?(e=this._buildGridObj(u,o,this.next,!0,!1),o++):(e=this._buildGridObj(u,r,this.current,!1,!1),r++);l.append(this._buildGridDay(e))}this.append(l)}},_buildGridObj:function(t,e,i,s,a){return{day:e,next:s,prev:a,year:i.year,month:i.month,date:this._getGridDay(i.year,i.month,e),selected:this._isSelectedDate(i.year,i.month,e),today:this._isTodayDate(i.year,i.month,e),weekend:t>4,disabled:this._isDisabledDate(i.year,i.month,e)}},_buildGridDay:function(e){var i=t.dom('<div class="datepicker-cell">');(e.next||e.prev)&&i.addClass("is-out"),e.selected&&i.addClass("is-selected"),e.today&&i.addClass("is-today"),e.weekend&&this.params.weekend&&i.addClass("is-weekend"),e.disabled&&i.addClass("is-disabled");var s=t.dom("<a>");return s.html(e.day),s.attr("href","#"),s.attr("data-disabled",e.disabled),s.attr("data-date",e.date),s.attr("data-day",e.day),s.attr("data-month",e.month),s.attr("data-year",e.year),s.on("click",this.datepicker.setDate.bind(this.datepicker)),i.append(s)},_isSelectedDate:function(t,e,i){return this.selected.year===t&&this.selected.month===e&&this.selected.day===i},_isTodayDate:function(t,e,i){return this.today.year===t&&this.today.month===e&&this.today.day===i},_isDisabledDate:function(t,e,i){var s=new Date(t+"/"+e+"/"+i);if(this.params.startDate){var a=new Date(this.params.startDate.year+"/"+this.params.startDate.month+"/"+this.params.startDate.day);if(s.getTime()<a.getTime())return!0}if(this.params.endDate){var n=new Date(this.params.endDate.year+"/"+this.params.endDate.month+"/"+this.params.endDate.day);if(s.getTime()>n.getTime())return!0}return!1},_getGridDay:function(t,e,i){return t+"-"+e+"-"+i},_getDaysInCurrentMonth:function(){return this._getDaysInMonth(this.current.year,this.current.month)},_getDaysInPrevMonth:function(){return this._getDaysInMonth(this.prev.year,this.prev.month)},_getDaysInNextMonth:function(){return this._getDaysInMonth(this.next.year,this.next.month)},_getDaysInMonth:function(t,e){return 0!==t%4||0===t%100&&0!==t%400||1!==e?this.daysInMonth[e]:29}})}(Kube),function(t){t.add("module","editable",{init:function(t,e){this.app=t;var i={classname:"editable",focus:!1};this.context=e,this.params=e.getParams(i),this.$element=e.getElement()},start:function(){this.$element.addClass(this.params.classname).attr("contenteditable",!0),this._setFocus(),this._setEvents()},stop:function(){this.$element.removeClass(this.params.classname).removeAttr("contenteditable"),this.$element.off(".kube.editable")},_setEvents:function(){this.$element.on("keydown.kube.editable",this._keydown.bind(this)),this.$element.on("paste.kube.editable",this._paste.bind(this)),this.$element.on("blur.kube.editable",this._blur.bind(this))},_setFocus:function(){this.params.focus&&this.$element.focus()},_checkEmpty:function(){this.$element.text().replace(" ","").length||this.$element.empty()},_paste:function(t){t.preventDefault();var e=t.originalEvent||t,i="";e.clipboardData?(i=e.clipboardData.getData("text/plain"),document.execCommand("insertText",!1,i)):window.clipboardData&&(i=window.clipboardData.getData("Text"),document.selection.createRange().pasteHTML(i))},_blur:function(t){this._checkEmpty()},_keydown:function(t){13===t.which&&t.preventDefault()}})}(Kube),function(t){t.add("module","magicquery",{init:function(t,e){this.app=t,this.response=t.response;var i={url:!1};this.context=e,this.params=e.getParams(i),this.$element=e.getElement()},start:function(){this.$element.on("click.kube.magicquery",this._send.bind(this))},stop:function(){this._enable(),this.$element.off(".kube.magicquery")},_disable:function(){this.$element.attr("disabled",!0)},_enable:function(){this.$element.removeAttr("disabled")},_send:function(e){e.preventDefault(),this._disable(),t.ajax.post({url:this.params.url,success:this._parse.bind(this)})},_parse:function(t){this._enable();var e=this.response.parse(t);e&&this.app.broadcast("magicquery.success",this,e)}})}(Kube),function(t){t.add("module","number",{init:function(t,e){this.app=t,this.context=e,this.$element=e.getElement()},start:function(){this.$input=this.$element.find('input[type="number"]'),this.$btnUp=this.$element.find(".is-up"),this.$btnDown=this.$element.find(".is-down"),this._buildStep(),this._buildMin(),this._buildMax(),this._isDisabled()||(this.$btnUp.on("click.kube.number",this._increase.bind(this)),this.$btnDown.on("click.kube.number",this._decrease.bind(this)))},stop:function(){this.$btnUp.off(".kube.number"),this.$btnDown.off(".kube.number")},_buildStep:function(){var t=this.$input.attr("step");this.step=t?parseFloat(t):1},_buildMin:function(){var t=this.$input.attr("min");this.min=t?parseFloat(t):!1},_buildMax:function(){var t=this.$input.attr("max");this.max=t?parseFloat(t):!1},_isDisabled:function(){return this.$input.attr("disabled")},_getValue:function(){var t=parseFloat(this.$input.val()),e=this.min===!1?0:this.min;return isNaN(t)?e:t},_increase:function(t){t&&(t.preventDefault(),t.stopPropagation());var e=this._getValue(),i=this.max!==!1&&e>=this.max?e:e+this.step;this.$input.val(i)},_decrease:function(t){t&&(t.preventDefault(),t.stopPropagation());var e=this._getValue(),i=this.min!==!1&&e<=this.min?e:e-this.step;this.$input.val(i)}})}(Kube),function(t){t.add("module","selector",{init:function(t,e){this.app=t,this.context=e,this.$element=e.getElement()},start:function(){this.$selector=this._buildSelector(),this.$selector.on("change.kube.selector",this._toggle.bind(this))},stop:function(){this.$selector.off(".kube.selector")},_isSelect:function(){return"SELECT"===this.$element.get().tagName},_isHashValue:function(t){return 0===t.search(/^#/)},_buildSelector:function(){return this._isSelect()?this.$element:this.$element.find('input[type="radio"]')},_getValue:function(){return this._isSelect()?this.$selector.val():this.$selector.filter(":checked").val()},_getBoxes:function(){var e=t.dom([]),i=this._isSelect()?this.$selector.find("option"):this.$selector;return i.each(function(i){this._isHashValue(i.value)&&e.add(t.dom(i.value))}.bind(this)),e},_toggle:function(){var e=this._getValue(),i=this._getBoxes(),s=t.dom(e);i.addClass("is-hidden"),s.removeClass("is-hidden"),this.app.broadcast("selector.opened",this,s)}})}(Kube),function(t){t.add("module","slider",{init:function(t,e){this.app=t,this.$win=t.$win,this.$doc=t.$doc;var i={min:0,max:100,step:1,value:0,target:!1};this.context=e,this.params=e.getParams(i),this.$element=e.getElement(),this.$target=e.getTarget(),this.isTicks=!1},start:function(){this._buildTrack(),this._buildFill(),this._buildHandle(),this._buildTicks(),this.update(),this.$win.on("resize.kube.slider",this._resize.bind(this)),this.$element.on("mousedown.kube.slider touchstart.kube.slider",this._handleDown.bind(this))},stop:function(){this.$win.off(".kube.slider"),this.$doc.off(".kube.slider"),this.$element.off(".kube.slider")},update:function(t){this.value=t?t:this.params.value,this.value=this.value<this.params.min?this.params.min:this.value,this.handleWidth=this.$handle.width(),this.trackWidth=this.$track.width(),this.maxHandlePosition=this.trackWidth-this.handleWidth,this.fixPosition=this.handleWidth/2,this.position=this._getPositionFromValue(this.value),this._setPosition(this.position),this._setTarget()},_resize:function(){this._buildTicks(),this.update(this.value)},_isDisabled:function(){return this.$element.hasClass("is-disabled")||this.$element.attr("disabled")},_buildTrack:function(){this.$track=t.dom("<div />"),this.$track.addClass("slider-track"),this.$element.prepend(this.$track)},_buildFill:function(){this.$fill=t.dom("<div />"),this.$fill.addClass("slider-fill"),this.$track.append(this.$fill)},_buildHandle:function(){this.$handle=t.dom("<div />"),this.$handle.addClass("slider-handle"),this.$track.append(this.$handle)},_buildTicks:function(){this.$ticks=this.$element.find(".slider-ticks span");var e=this.$ticks.length;if(this.isTicks=0!==e,this.isTicks){var i=this.$handle.width(),s=this.$element.width()-i,a=i/2,n=s/(e-1),h=a;this.$ticks.each(function(e,i){var s=t.dom(e),r=h+n*i;s.css({left:r+"px",width:n+"px","text-indent":"-"+(n-a)+"px"})})}},_handleDown:function(t){if(t.preventDefault(),!this._isDisabled()){this.$doc.on("mousemove.kube.slider touchmove.kube.slider",this._handleMove.bind(this)),this.$doc.on("mouseup.kube.slider touchend.kube.slider",this._handleEnd.bind(this));var e=t.touches&&t.touches.length>0?t.changedTouches[0].clientX:t.clientX,i=this.$track.offset().left,s=e-i-this.fixPosition;this._setPosition(s),this._setTarget()}},_handleMove:function(t){t.preventDefault();var e=t.touches&&t.touches.length>0?t.changedTouches[0].clientX:t.clientX,i=this.$track.offset().left,s=e-i-this.fixPosition;this._setPosition(s),this._setTarget()},_handleEnd:function(t){t.preventDefault(),this.$doc.off(".kube.slider")},_setPosition:function(t){t=this._getEdge(t,0,this.maxHandlePosition);var e=this._getValueFromPosition(t),i=this._getPositionFromValue(e);this.$fill.css("width",i+this.fixPosition+"px"),this.$handle.css("left",i+"px"),this.position=i,this.value=e},_setTarget:function(){if(this.app.broadcast("slider.set",this,this.value),0!==this.$target.length){var t=this.$target.get().tagName;"INPUT"===t||"SELECT"===t?this.$target.val(this.value):this.$target.text(this.value)}},_getPositionFromValue:function(t){var e=(t-this.params.min)/(this.params.max-this.params.min);return pos=Number.isNaN(e)?0:e*this.maxHandlePosition},_getValueFromPosition:function(t){var e=t/(this.maxHandlePosition||1),i=this.params.step*Math.round(e*(this.params.max-this.params.min)/this.params.step)+this.params.min;return Number(i.toFixed((this.params.step+"").replace(".","").length-1))},_getEdge:function(t,e,i){return e>t?e:t>i?i:t}})}(Kube),function(t){t.add("module","upload",{init:function(t,e){this.app=t,this.utils=t.utils,this.animate=t.animate,this.response=t.response,this.progress=t.progress;var i={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=e,this.params=e.getParams(i),this.$element=e.getElement(),this.$target=e.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 e=t.dom("<span>");e.addClass("upload-placeholder"),e.html(this.params.placeholder),this.$element.append(e)}},_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,e=t?this.$target:this.$element,i=t?"_removeFile":"_removeImage",s=e.find(".close");s.on("click",this[i].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(e){e.preventDefault();var i=t.dom(e.target);i.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 e=this.$target.find(".upload-item");e.each(function(e){var i=t.dom(e);this._removeFileRequest(i.attr("data-id"))}.bind(this)),this._clearCount(),this.$target.html("")},_clearBox:function(){var e=this.$target.find(".upload-item");e.each(function(e){var i=t.dom(e);this._removeFileRequest(i.attr("data-id"))}.bind(this)),this._clearCount(),this.$target.html("")},_removeFile:function(e){e.preventDefault();var i=t.dom(e.target),s=i.closest(".upload-item"),a=s.attr("data-id");this.animate.run(s,"fadeOut",function(){s.remove(),this._downCount(),this._removeFileRequest(a),0===this.$target.find(".upload-item").length&&this.$target.html("")}.bind(this))},_removeImage:function(e){e.preventDefault();var i=t.dom(e.target),s=i.closest(".upload-item"),a=s.attr("data-id");if(this.isMultiple)this.animate.run(s,"fadeOut",function(){s.remove(),this._downCount(),this._removeFileRequest(a)}.bind(this));else{var n=s.find("img");i.hide(),this.animate.run(n,"fadeOut",function(){this.$box.html(""),this.$box.removeClass("is-uploaded"),this._clearCount(),this._removeFileRequest(a)}.bind(this))}},_removeFileRequest:function(e){this.params.urlRemove&&t.ajax.post({url:this.params.urlRemove,data:{id:e}})},_send:function(t,e){t=t.originalEvent||t,e=e?e:t.dataTransfer.files;var i=new FormData,s=this._getParamName();i=this._buildData(s,e,i),this.params.append&&(i=this.utils.extendData(i,this.params.append)),this._sendData(i,e,t)},_sendData:function(e,i,s){this.params.progress&&this.progress.show(),t.ajax.post({url:this.params.url,data:e,before:function(t){return this.app.broadcast("upload.beforeSend",this,t)}.bind(this),success:function(t){this._complete(t,s)}.bind(this)})},_buildData:function(t,e,i){for(var s=0;s<e.length;s++)i.append(t+"[]",e[s]);return i},_complete:function(t,e){this._clearStatuses(),this.params.progress&&this.progress.hide();var i=Array.isArray(t)?t[0]:t;
if("undefined"!=typeof i.type&&"error"===i.type)this._setStatus("error"),this.response.parse(t),this.app.broadcast("upload.error",this,t);else{switch(this._setStatus("success"),this.params.type){case"image":this._completeBoxImage(t);break;case"file":this._completeBoxFile(t);break;default:this._completeBoxUpload(t)}this.app.broadcast("upload.complete",this,t),setTimeout(this._clearStatuses.bind(this),500)}},_completeBoxUpload:function(t){this.response.parse(t)},_completeBoxImage:function(e){for(var i in e){var s=t.dom("<img>");s.attr("src",e[i].url);var a=t.dom("<span>");a.addClass("close"),a.on("click",this._removeImage.bind(this));var n=t.dom("<input>");n.attr("type","hidden"),n.attr("name",this._getHiddenName()),n.val(e[i].id);var h=t.dom("<div>");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("<div>");s.addClass("upload-item"),s.attr("data-id",e[i].id);var a=t.dom("<span>");a.html(e[i].name);var n=t.dom("<span>");n.addClass("close"),n.on("click",this._removeFile.bind(this));var h=t.dom("<input>");if(h.attr("type","hidden"),h.attr("name",this._getHiddenName()),h.val(e[i].id),"undefined"!=typeof e[i].size){var r=t.dom("<em>");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);