|
|
- !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 a={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(a),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 a={day:i.attr("data-day"),month:i.attr("data-month"),year:i.attr("data-year")},s=this._convertDateToFormat(a);if(this.params.embed===!1){var n=0!==this.$target.length?this.$target:this.$element;"INPUT"===n.get().tagName?n.val(s):n.text(s),this._close()}this.app.broadcast("datepicker.set",this,s,a)},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(),a=this.$datepicker.innerWidth(),s=this.$datepicker.innerHeight(),n=this.$win.width(),r=this.$doc.height(),h=0,d=t.left,o=t.top+e+1;this.position.type="left",d+a>n&&(this.position.type="right",h=n-(d+i)),o+s>r
|