UNPKG

ax5ui-calendar

Version:

A calendar plugin that works with Bootstrap & jQuery

3 lines (2 loc) 20 kB
"use strict";!function(){var e=ax5.ui,t=ax5.util,a=void 0;e.addClass({className:"calendar"},function(){return function(){var n=this,l=void 0,i=1;this.instanceId=ax5.getGuid(),this.target=null,this.selection=[],this.selectionMap={},this.selectableMap={},this.markerMap={},this.printedDay={start:"",end:""},this.config={clickEventName:"click",theme:"default",startOfWeek:0,mode:"day",dateFormat:"yyyy-MM-dd",displayDate:new Date,animateTime:100,dimensions:{controlHeight:"40",controlButtonWidth:"40",colHeadHeight:"30",itemPadding:2},lang:{yearHeading:"Choose the year",monthHeading:"Choose the month",yearTmpl:"%s",months:ax5.info.months||["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"],dayTmpl:"%s"},multipleSelect:!1,selectMode:"day",defaultMarkerTheme:"holiday",defaultPeriodTheme:"period"},l=this.config;var r=function(e,t){e&&e.onStateChanged?e.onStateChanged.call(t,t):this.onStateChanged&&this.onStateChanged.call(t,t),t=null},s=function(){var e=jQuery.extend(!0,{},l,{controlCSS:{},controlButtonCSS:{}});e.controlButtonCSS.height=e.controlCSS.height=t.cssNumber(l.dimensions.controlHeight),e.controlButtonCSS["line-height"]=e.controlCSS["line-height"]=t.cssNumber(l.dimensions.controlHeight),e.controlButtonCSS.width=t.cssNumber(l.dimensions.controlHeight),e.controlCSS=t.css(e.controlCSS),e.controlButtonCSS=t.css(e.controlButtonCSS);try{return a.tmpl.get.call(this,"frameTmpl",e)}finally{e=null}},d=function(){var e,a,n=t.date(l.displayDate),i="",r="";return l.control&&("day"==l.mode||"d"==l.mode?(i=l.control.yearTmpl?l.control.yearTmpl.replace("%s",n.getFullYear()):n.getFullYear(),r=l.control.monthTmpl?l.control.monthTmpl.replace("%s",l.lang.months[n.getMonth()]):l.lang.months[n.getMonth()],this.$["control-display"].html(function(){return l.control.yearFirst?'<span data-calendar-display="year">'+i+'</span><span data-calendar-display="month">'+r+"</span>":'<span data-calendar-display="month">'+r+'</span><span data-calendar-display="year">'+i+"</span>"}())):"month"==l.mode||"m"==l.mode?(i=l.control.yearTmpl?l.control.yearTmpl.replace("%s",n.getFullYear()):n.getFullYear(),this.$["control-display"].html('<span data-calendar-display="year">'+i+"</span>")):"year"!=l.mode&&"y"!=l.mode||(e=l.control.yearTmpl?l.control.yearTmpl.replace("%s",n.getFullYear()-10):n.getFullYear()-10,a=l.control.yearTmpl?l.control.yearTmpl.replace("%s",Number(n.getFullYear())+9):Number(n.getFullYear())+9,this.$["control-display"].html(e+" ~ "+a)),this.$["control-display"].find("[data-calendar-display]").on(l.clickEventName,function(e){var a,n=t.findParentNode(e.target,function(e){if(e.getAttribute("data-calendar-display"))return!0});n&&(a=n.getAttribute("data-calendar-display"),this.changeMode(a)),n=null,a=null}.bind(this))),n=null,i=null,r=null,e=null,a=null,this},o=function(e){var i,s,o,c,h,u,f=t.date(e),y=new Date(f.getFullYear(),f.getMonth(),1,12),p=l.displayDate,g=function(){var e=y.getDay();0==e&&(e=7),e-=l.startOfWeek;try{return t.date(y,{add:{d:-e}})}finally{e=null}}(),b=f.getMonth(),v={},M=this.$.body.width(),D=Math.floor(M*(6/7));for(l.dimensions.height&&(D=t.number(l.dimensions.height)-t.number(l.dimensions.colHeadHeight)),v.height=Math.floor(D/6)-2*t.number(l.dimensions.itemPadding)+"px",v["line-height"]=v.height,v.padding=t.cssNumber(l.dimensions.itemPadding),h={weekNames:[].concat(ax5.info.weekNames),list:[]},l.startOfWeek&&(h.weekNames=h.weekNames.concat(h.weekNames.slice(0,l.startOfWeek)).splice(l.startOfWeek)),h.weekNames.forEach(function(e){e.colHeadHeight=t.cssNumber(l.dimensions.colHeadHeight)}),i=g,s=0;s<6;){for(o=0;o<7;){c=(7+(o-l.startOfWeek))%7;var S=""+t.date(i,{"return":l.dateFormat}),C={row:s,col:o,isStartOfWeek:0==o,thisDate:""+S,thisDataLabel:l.lang.dayTmpl.replace("%s",i.getDate()),itemStyles:t.css(v),addClass:function(){var e="";return l.selectable?e+=n.selectableMap[S]?i.getMonth()==b?" live":"":" disable":i.getMonth()==b&&(e+=S==t.date(p,{"return":"yyyyMMdd"})?" focus":" live",0==i.getDay()&&(e+=" sunday"),6==i.getDay()&&(e+=" saturday")),e}()+" "+function(){return n.markerMap[S]?n.markerMap[S].theme||l.defaultMarkerTheme:""}()+" "+function(){return n.selectionMap[S]?"selected-day":""}()};h.list.push(C),o++,i=t.date(i,{add:{d:1}}),S=null,C=null}s++}u=a.tmpl.get.call(this,"dayTmpl",h),this.$.body.html(u),this.$.body.find("[data-calendar-item-date]").on(l.clickEventName,function(e){e=e||window.event,m.call(n,e,"date"),t.stopEvent(e)}),this.printedDay={start:g,end:i},r.call(this,null,{self:this,action:"printDay",printedDay:this.printedDay}),d.call(this),f=null,y=null,p=null,g=null,i=null,b=null,v=null,s=null,o=null,M=null,D=null,h=null,u=null},c=function(e){var i,s,o,c,h,u,f=t.date(e),y=f.getMonth(),p={},g=this.$.body.width(),b=Math.floor(g*(6/7));for(l.dimensions.height&&(b=t.number(l.dimensions.height)-t.number(l.dimensions.colHeadHeight)),p.height=Math.floor(b/4)-2*t.number(l.dimensions.itemPadding)+"px",p["line-height"]=p.height,p.padding=t.cssNumber(l.dimensions.itemPadding),h={colHeadHeight:t.cssNumber(l.dimensions.colHeadHeight),colHeadLabel:l.lang.monthHeading,list:[]},c=0,o=0,i=0;i<4;){for(s=0;s<3;){var v={row:i,col:s,isStartOfRow:0==s,thisMonth:f.getFullYear()+"-"+t.setDigit(o+1,2)+"-01",thisMonthLabel:l.lang.months[o],itemStyles:t.css(p),addClass:function(){return l.selectable?n.selectableMap[o]?"live":"disable":"live"}()+" "+function(){return o==y?"focus":""}()+" "+function(){return n.markerMap[o]?n.markerMap[o].theme||l.defaultMarkerTheme:""}()};h.list.push(v),o++,s++,v=null}i++}u=a.tmpl.get.call(this,"monthTmpl",h),this.$.body.html(u),this.$.body.find("[data-calendar-item-month]").on(l.clickEventName,function(e){e=e||window.event,m.call(n,e,"month"),t.stopEvent(e)}),this.printedDay={start:f.getFullYear()+"-"+t.setDigit(c+1,2),end:f.getFullYear()+"-"+t.setDigit(o,2)},r.call(this,null,{self:this,action:"printMonth",printedDay:this.printedDay}),d.call(this),f=null,y=null,p=null,i=null,s=null,o=null,c=null,g=null,b=null,h=null,u=null},h=function(e){var i,s,o,c,h,u,f=t.date(e),y=f.getFullYear(),p={},g=this.$.body.width(),b=Math.floor(g*(6/7));for(l.dimensions.height&&(b=t.number(l.dimensions.height)-t.number(l.dimensions.colHeadHeight)),p.height=Math.floor(b/5)-2*t.number(l.dimensions.itemPadding)+"px",p["line-height"]=p.height,p.padding=t.cssNumber(l.dimensions.itemPadding),h={colHeadHeight:t.cssNumber(l.dimensions.colHeadHeight),colHeadLabel:l.lang.yearHeading,list:[]},c=y-10,o=y-10,i=0;i<5;){for(s=0;s<4;){var v={row:i,col:s,isStartOfRow:0==s,thisYear:o+"-"+t.setDigit(f.getMonth()+1,2)+"-01",thisYearLabel:l.lang.yearTmpl.replace("%s",o),itemStyles:t.css(p),addClass:function(){return l.selectable?n.selectableMap[o]?"live":"disable":"live"}()+" "+function(){return o==y?"focus":""}()+" "+function(){return n.selectableMap[o]?n.selectableMap[o].theme||l.defaultMarkerTheme:""}()};h.list.push(v),o++,s++,v=null}i++}u=a.tmpl.get.call(this,"yearTmpl",h),this.$.body.html(u),this.$.body.find("[data-calendar-item-year]").on(l.clickEventName,function(e){e=e||window.event,m.call(this,e,"year"),t.stopEvent(e)}),this.printedDay={start:c,end:o-1},r.call(this,null,{self:this,action:"printYear",printedDay:this.printedDay}),d.call(this),f=null,y=null,p=null,i=null,s=null,o=null,c=null,g=null,b=null,h=null,u=null},m=function(e,a,r,s){var d,o,c;a=a||"date",r=t.findParentNode(e.target,function(e){if(e.getAttribute("data-calendar-item-"+a))return!0}),r&&(s=r.getAttribute("data-calendar-item-"+a),o=t.date(s,{"return":l.dateFormat}),c=!0,i=l.multipleSelect?t.isNumber(l.multipleSelect)?l.multipleSelect:2:1,l.selectable&&(n.selectableMap[o]||(c=!1)),"date"==a?c&&(n.selection.length>=i&&(d=n.selection.splice(0,n.selection.length-(i-1)),d.forEach(function(e){n.$.body.find('[data-calendar-item-date="'+t.date(e,{"return":l.dateFormat})+'"]').removeClass("selected-day")})),jQuery(r).addClass("selected-day"),n.selection.push(s),n.onClick&&n.onClick.call({self:this,date:s,target:this.target,dateElement:r})):"month"==a?"month"==l.selectMode?c&&(n.selection.length>=i&&(d=n.selection.splice(0,n.selection.length-(i-1)),d.forEach(function(e){n.$.body.find('[data-calendar-item-month="'+t.date(e,{"return":"yyyy-MM-dd"})+'"]').removeClass("selected-month")})),jQuery(r).addClass("selected-month"),n.selection.push(s),n.onClick&&n.onClick.call({self:this,date:s,target:this.target,dateElement:r})):n.changeMode("day",s):"year"==a&&("year"==l.selectMode?c&&(n.selection.length>=i&&(d=n.selection.splice(0,n.selection.length-(i-1)),d.forEach(function(e){n.$.body.find('[data-calendar-item-year="'+t.date(e,{"return":"yyyy-MM-dd"})+'"]').removeClass("selected-year")})),jQuery(r).addClass("selected-year"),n.selection.push(s),n.onClick&&n.onClick.call({self:this,date:s,target:this.target,dateElement:r})):n.changeMode("month",s))),a=null,r=null,s=null,d=null,o=null,c=null},u=function(e,a,n){a=t.findParentNode(e.target,function(e){if(e.getAttribute("data-calendar-move"))return!0}),a&&(n=a.getAttribute("data-calendar-move"),"day"==l.mode||"d"==l.mode?("left"==n?l.displayDate=t.date(l.displayDate,{add:{m:-1}}):l.displayDate=t.date(l.displayDate,{add:{m:1}}),o.call(this,l.displayDate)):"month"==l.mode||"m"==l.mode?("left"==n?l.displayDate=t.date(l.displayDate,{add:{y:-1}}):l.displayDate=t.date(l.displayDate,{add:{y:1}}),c.call(this,l.displayDate)):"year"!=l.mode&&"y"!=l.mode||("left"==n?l.displayDate=t.date(l.displayDate,{add:{y:-10}}):l.displayDate=t.date(l.displayDate,{add:{y:10}}),h.call(this,l.displayDate))),a=null,n=null},f=function(){setTimeout(function(){if("day"===l.mode||"d"===l.mode)for(var e in this.markerMap)this.$.body.find('[data-calendar-item-date="'+e+'"]').addClass(this.markerMap[e].theme||l.defaultMarkerTheme)}.bind(this))},y=function(){setTimeout(function(){for(var e in this.selectionMap)this.$.body.find('[data-calendar-item-date="'+e+'"]').addClass("selected-day")}.bind(this))},p=function(){setTimeout(function(){if("day"===l.mode||"d"===l.mode)for(var e in this.periodMap)this.periodMap[e].label&&this.$.body.find('[data-calendar-item-date="'+e+'"]').find(".addon-footer").html(this.periodMap[e].label),this.$.body.find('[data-calendar-item-date="'+e+'"]').addClass(this.periodMap[e].theme)}.bind(this))},g=function(){if("day"===l.mode||"d"===l.mode)for(var e in this.periodMap)this.$.body.find('[data-calendar-item-date="'+e+'"]').find(".addon-footer").empty(),this.$.body.find('[data-calendar-item-date="'+e+'"]').removeClass(this.periodMap[e].theme)};this.init=function(){this.onStateChanged=l.onStateChanged,this.onClick=l.onClick,l.target||console.log(ax5.info.getError("ax5calendar","401","setConfig")),this.target=jQuery(l.target),l.displayDate=t.date(l.displayDate),this.target.html(s.call(this)),this.$={root:this.target.find('[data-calendar-els="root"]'),control:this.target.find('[data-calendar-els="control"]'),"control-display":this.target.find('[data-calendar-els="control-display"]'),body:this.target.find('[data-calendar-els="body"]')},l.control&&this.$.root.on(l.clickEventName,"[data-calendar-move]",function(e){u.call(this,e||window.event)}.bind(this)),l.selection&&this.setSelection(l.selection,!1),l.selectable&&this.setSelectable(l.selectable,!1),l.marker&&this.setMarker(l.marker,!1),setTimeout(function(){"day"===l.mode||"d"===l.mode?o.call(this,l.displayDate):"month"===l.mode||"m"===l.mode?c.call(this,l.displayDate):"year"!==l.mode&&"y"!==l.mode||h.call(this,l.displayDate)}.bind(this))},this.changeMode=function(e,t){return"undefined"!=typeof t&&(l.displayDate=t),e&&(l.mode=e),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==l.mode||"d"==l.mode?o.call(this,l.displayDate):"month"==l.mode||"m"==l.mode?c.call(this,l.displayDate):"year"!=l.mode&&"y"!=l.mode||h.call(this,l.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),l.animateTime),this},this.setSelection=function(){n.selectionMap={};var e={arr:function(e,a,i){return a={},t.isArray(e)?(n.selection=e=e.splice(0,i),e.forEach(function(e){t.isDate(e)&&(e=t.date(e,{"return":l.dateFormat})),a[e]=!0}),a):a}};return function(a,n){var r={};if(i=l.multipleSelect?t.isNumber(l.multipleSelect)?l.multipleSelect:2:1,l.selection=a){if(!t.isArray(a))return this;r=e.arr(a,{},i)}return this.selectionMap=jQuery.extend({},r),n!==!1&&y.call(this),r=null,this}}(),this.getSelection=function(){return this.selection},this.setSelectable=function(){n.selectableMap={};var e={arr:function(e,a){return a={},t.isArray(e)?(e.forEach(function(e){t.isDate(e)&&(e=t.date(e,{"return":l.dateFormat})),a[e]=!0}),a):a},obj:function(e,a){if(a={},t.isArray(e))return a;if(e.range)return a;for(var n in e)a[n]=e[n];return a},range:function(e,a){return a={},t.isArray(e)?a:e.range?(e.range.forEach(function(e){if(t.isDateFormat(e.from)&&t.isDateFormat(e.to))for(var n=t.date(e.from);n<=t.date(e.to);n.setDate(n.getDate()+1))a[t.date(n,{"return":l.dateFormat})]=!0;else for(var i=e.from;i<=e.to;i++)a[i]=!0}),a):a}};return function(a,n){var i,r={};if(l.selectable=a)if(t.isArray(a))r=e.arr(a);else{for(i in e)if(a[i]){r=e[i](a);break}0===Object.keys(r).length&&(r=e.obj(a))}return this.selectableMap=r,n!==!1&&this.changeMode(),this}}(),this.setMarker=function(){n.markerMap={};var e={obj:function(e,a){if(a={},t.isArray(e))return a;if(e.range)return a;for(var n in e)a[n]=e[n];return e=null,a},range:function(e,a){return a={},t.isArray(e)?a:e.range?(e.range.forEach(function(e){if(t.isDateFormat(e.from)&&t.isDateFormat(e.to))for(var n=t.date(e.from);n<=t.date(e.to);n.setDate(n.getDate()+1))a[t.date(n,{"return":l.dateFormat})]={theme:e.theme,label:e.label};else for(var i=e.from;i<=e.to;i++)a[i]={theme:e.theme,label:e.label}}),e=null,a):a}};return function(t,a){var n,i={};if(l.marker=t){for(n in e)if(t[n]){i=e[n](t);break}0===Object.keys(i).length&&(i=e.obj(t))}return this.markerMap=i,a!==!1&&f.call(this),this}}(),this.setPeriod=function(){n.periodMap={};var e={range:function(e,a){return a={},t.isArray(e)?a:e.range?(e.range.forEach(function(e){if(t.isDateFormat(e.from)&&t.isDateFormat(e.to))for(var n=new Date(t.date(e.from));n<=t.date(e.to);n.setDate(n.getDate()+1))n.getTime()==t.date(e.from).getTime()?a[t.date(n,{"return":l.dateFormat})]={theme:e.theme||l.defaultPeriodTheme,label:e.fromLabel}:n.getTime()==t.date(e.to).getTime()?a[t.date(n,{"return":l.dateFormat})]={theme:e.theme||l.defaultPeriodTheme,label:e.toLabel}:a[t.date(n,{"return":l.dateFormat})]={theme:e.theme||l.defaultPeriodTheme}}),e=null,a):a}};return function(t,a){var n={};return a!==!1&&g.call(this),(l.period=t)&&(n=e.range(t)),this.periodMap=n,a!==!1&&p.call(this),this}}(),this.main=function(){e.calendar_instance=e.calendar_instance||[],e.calendar_instance.push(this),arguments&&t.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)}}()),a=ax5.ui.calendar}(),function(){var e=ax5.ui.calendar,t=function(e){return'\n <div class="ax5-ui-calendar {{theme}}" data-calendar-els="root" onselectstart="return false;">\n {{#control}}\n <div class="calendar-control" data-calendar-els="control" style="{{controlCSS}}">\n <a class="date-move-left" data-calendar-move="left" style="{{controlButtonCSS}}">{{{left}}}</a>\n <div class="date-display" data-calendar-els="control-display" style="{{controlCSS}}"></div>\n <a class="date-move-right" data-calendar-move="right" style="{{controlButtonCSS}}">{{{right}}}</a>\n </div>\n {{/control}}\n <div class="calendar-body" data-calendar-els="body"></div>\n </div>\n '},a=function(e){return'\n <table data-calendar-table="day" cellpadding="0" cellspacing="0" style="width:100%;">\n <thead>\n <tr>\n {{#weekNames}}\n <td class="calendar-col-{{col}}" style="height: {{colHeadHeight}}">\n {{label}}\n </td>\n {{/weekNames}}\n </tr>\n </thead>\n <tbody>\n <tr>\n {{#list}} \n {{#isStartOfWeek}}\n {{^@first}}\n </tr>\n <tr>\n {{/@first}}\n {{/isStartOfWeek}}\n <td class="calendar-col-{{col}}" style="{{itemStyles}}">\n <a class="calendar-item-day {{addClass}}" data-calendar-item-date="{{thisDate}}">\n <span class="addon addon-header"></span>\n {{thisDataLabel}}\n <span class="addon addon-footer"></span>\n </a>\n </td>\n {{/list}}\n </tr>\n </tbody>\n </table>\n '},n=function(e){return'\n <table data-calendar-table="month" cellpadding="0" cellspacing="0" style="width:100%;">\n <thead>\n <tr>\n <td class="calendar-col-0" colspan="3" style="height: {{colHeadHeight}}">\n {{colHeadLabel}}\n </td>\n </tr>\n </thead>\n <tbody>\n <tr>\n {{#list}} \n {{#isStartOfRow}}\n {{^@first}}\n </tr>\n <tr>\n {{/@first}}\n {{/isStartOfRow}}\n <td class="calendar-col-{{col}}" style="{{itemStyles}}">\n <a class="calendar-item-month {{addClass}}" data-calendar-item-month="{{thisMonth}}">\n <span class="addon"></span>\n {{thisMonthLabel}}\n <span class="lunar"></span>\n </a>\n </td>\n {{/list}}\n </tr>\n </tbody>\n </table>\n '},l=function(e){return'\n <table data-calendar-table="year" cellpadding="0" cellspacing="0" style="width:100%;">\n <thead>\n <tr>\n <td class="calendar-col-0" colspan="4" style="height: {{colHeadHeight}}">\n {{colHeadLabel}}\n </td>\n </tr>\n </thead>\n <tbody>\n <tr>\n {{#list}} \n {{#isStartOfRow}}\n {{^@first}}\n </tr>\n <tr>\n {{/@first}}\n {{/isStartOfRow}}\n <td class="calendar-col-{{col}}" style="{{itemStyles}}">\n <a class="calendar-item-year {{addClass}}" data-calendar-item-year="{{thisYear}}">\n <span class="addon"></span>\n {{thisYearLabel}}\n <span class="lunar"></span>\n </a>\n </td>\n {{/list}}\n </tr>\n </tbody>\n </table>\n '};e.tmpl={frameTmpl:t,dayTmpl:a,monthTmpl:n,yearTmpl:l,get:function(t,a,n){return ax5.mustache.render(e.tmpl[t].call(this,n),a)}}}(); //# sourceMappingURL=ax5calendar.min.js.map