You cannot 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
38 KiB
JavaScript

(function(e,j,i,b){var h="asDatepicker",c={firstDayOfWeek:0,mode:"single",displayMode:"dropdown",calendars:1,date:"today",keyboard:true,rangeSeparator:"--",multipleSeparator:",",multipleSize:5,container:"body",position:"bottom",alwaysShow:false,onceClick:false,min:null,max:null,selectableDate:[],selectableYear:[],selectableMonth:[],selectableDay:[],selectableDayOfWeek:[],lang:"zh",views:["days"],outputFormat:"yyyy-mm-dd",mobileMode:false,namespace:"calendar",tplInputWrapper:function(){return'<div class="namespace-inputWrap"></div>'},tplWrapper:function(){return'<div class="namespace-wrap"></div>'},tplContent:function(){return'<div class="namespace-content"><div class="namespace-header"><div class="namespace-prev"><</div><div class="namespace-caption"></div><div class="namespace-next">></div></div><div class="namespace-days"></div><div class="namespace-months"></div><div class="namespace-years"></div><div class="namespace-buttons"><div class="namespace-button-cancel"></div><div class="namespace-button-save"></div></div></div>'},tplTitle:function(){return'<div class="namespace-title">test</div>'},onInit:null,onReady:null,onRender:null,onChange:null,onBeforeShow:null,onShow:null,onBeforeHide:null,onHide:null};var d=e(j);var a=e(i);var f={};var g=0;var k=e[h]=function(n,m){var l=this,o=e(n).data();this.$el=e(n);this.defaultOptions=e.extend(true,{},c,m,o);this.options=e.extend(true,{},c,m,o);e.each(o,function(p,q){l.options[p]=l._parseHtmlString(p,q);l.defaultOptions[p]=l._parseHtmlString(p,q)});this.namespace=this.options.namespace;this.$inputWrap=this.$el.addClass(this.namespace+"-input").wrap(this.options.tplInputWrapper().replace(/namespace/g,this.namespace)).parent();this.$inputIcon=e('<i class="'+this.namespace+'-icon"></i>');this.$inputIcon.appendTo(this.$inputWrap);this.$container=e(this.options.container);this._trigger("init");this._init()};k.LABEL=f;k.localize=function(m,l){f[m]=l};k.localize("en",{days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Su","Mo","Tu","We","Th","Fr","Sa","Su"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],buttons:["Cancel","Save"]});k.localize("zh",{days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],daysShort:["日","一","二","三","四","五","六"],months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],monthsShort:["一","二","三","四","五","六","七","八","九","十","十一","十二"],buttons:["取消","确定"]});k.prototype={constructor:k,_init:function(){this.mode=this.options.mode;this.format=this._parseFormat("yyyy-mm-dd");this.outputFormat=this._parseFormat(this.options.outputFormat||"yyyy/mm/dd");this.focused=0;this.flag=g++;this.pickerHide=false;this.selected=false;this.showed=false;this.bound=false;this.hasKeyboard=this.options.keyboard;this.map={};this.views=[];this.isMobile=this.options.mobileMode;var m=this.options.tplWrapper().replace(/namespace/g,this.namespace),q=this.options.tplContent().replace(/namespace/g,this.namespace),t=this.options.tplTitle().replace(/namespace/g,this.namespace),r=f[this.options.lang].buttons;this.$picker=e(m);switch(this.mode){case"single":this.calendarsNum=1;break;case"range":this.calendarsNum=2;break;case"multiple":this.calendarsNum=this.isMobile?1:this.options.calendars;this.options.views=["days"];break}for(var p=0;p<this.calendarsNum;p++){this.$picker.append(q);this.views[p]=this.options.views[p]||"days"}if(this.isMobile){var s=i.innerWidth;var l=i.innerHeight;var o=Math.min(s,l);this.$el.attr("readonly","readonly");this.$cover=e('<div class="'+this.namespace+'-cover"></div>');this.$picker.append(t).addClass(this.namespace+"_isMobile");this.$picker.css({"font-size":Math.round(o*0.04)+"px"})}this.$picker.attr("tabindex","0");this._initStatus(this.options.displayMode);this._initSections();this._initDate();for(var n=0;n<this.calendarsNum;n++){this._manageViews(n);if(this.isMobile){this.buttonCancels.eq(n).html(r[0]);this.buttonSaves.eq(n).html(r[1])}}this._initShowHide(this.options.alwaysShow);this._setValue();this._trigger("ready")},_initStatus:function(l){if(l==="inline"){this.options.alwaysShow=true;this.$picker.addClass(this.namespace+"_show");this.$picker.on({focus:e.proxy(this._focus,this),blur:e.proxy(this._blur,this)})}else{if(l==="dropdown"){this.$el.on({focus:e.proxy(this._focus,this),blur:e.proxy(this._blur,this)});this.$inputIcon.on("click.inputIcon",e.proxy(this._toggle,this));this.$picker.appendTo(this.options.container)}}},_initSections:function(){this.calendars=this.$picker.find("."+this.namespace+"-content");this.calendarPrevs=this.calendars.find("."+this.namespace+"-prev");this.calendarCaptions=this.calendars.find("."+this.namespace+"-caption");this.calendarNexts=this.calendars.find("."+this.namespace+"-next");this.daypickers=this.calendars.find("."+this.namespace+"-days");this.monthpickers=this.calendars.find("."+this.namespace+"-months");this.yearpickers=this.calendars.find("."+this.namespace+"-years");this.buttonCancels=this.calendars.find("."+this.namespace+"-button-cancel");this.buttonSaves=this.calendars.find("."+this.namespace+"-button-save")},_initShowHide:function(l){if(l===true){this.show()}},_initDate:function(){var l=this.options.date==="today"?new Date():this._parseDate(this.options.date,this.format);this._date={};if(this.options.date==="today"){this._date.currentDate=[new Date(l)]}else{if(this.options.mode=="range"){var n=this.options.date.split(" "+this.options.rangeSeparator+" ");n[0]=this._parseDate(n[0],this.format);n[1]=this._parseDate(n[1],this.format);this._date.currentDate=[new Date(n[0]),new Date(n[1])]}}if(this.options.mode=="range"){this._date.selectedDate=[this._date.currentDate[0],this._date.currentDate[1]];this._date.focusDate=this._date.currentDate[0];this._date.focusDate.setHours(0,0,0,0)}else{if(this.mode==="multiple"){this._date.selectedDate=[];this._date.focusDate=new Date(l);this._date.focusDate.setHours(0,0,0,0)}else{this._date.selectedDate=[new Date(l)];this._date.focusDate=[new Date(l)]}}this._date.currentDay=[];this._date.currentMonth=[];this._date.currentYear=[];this._date.currentMonthDate=[];this._date.currentYearDate=[];this._date.selectedDay=[];this._date.selectedMonth=[];this._date.selectedYear=[];this._date.selectedMonthDate=[];this._date.selectedYearDate=[];this._date.cache={};this._date.cache.currentDate=[];this._date.cache.selectedDate=[];for(var m=0;m<this.calendarsNum;m++){this._date.currentDate[m]=this._date.currentDate[m]||new Date(l);if(this.mode==="multiple"){this._setDate(this._date.currentDate[m],"month",this._date.currentDate[m].getMonth()+m)}else{this._date.selectedDate[m]=this._date.selectedDate[m]||new Date(l);this._date.selectedDate[m].setHours(0,0,0,0);this._date.focusDate[m]=this._date.focusDate[m]||new Date(l);this._date.focusDate[m].setHours(0,0,0,0)}this._updateDate(m)}},_manageViews:function(l){switch(this.views[l]){case"days":this._generateDaypicker(l);this.calendars.eq(l).addClass(this.namespace+"_days").removeClass(this.namespace+"_months").removeClass(this.namespace+"_years");break;case"months":this._generateMonthpicker(l);this.calendars.eq(l).removeClass(this.namespace+"_days").addClass(this.namespace+"_months").removeClass(this.namespace+"_years");break;case"years":this._generateYearpicker(l);this.calendars.eq(l).removeClass(this.namespace+"_days").removeClass(this.namespace+"_months").addClass(this.namespace+"_years");break}},_generateDaypicker:function(l){this._generateHeader(l,f[this.options.lang].months[this._date.currentMonth[l]]+" "+this._date.currentYear[l]);this.daypickers.eq(l).html(this._generateDays(l))},_generateMonthpicker:function(l){this._generateHeader(l,this._date.currentYear[l]);this.monthpickers.eq(l).html(this._generateMonths(l))},_generateYearpicker:function(l){this._generateHeader(l,this._date.currentYear[l]-7+" "+this.options.rangeSeparator+" "+(this._date.currentYear[l]+4));this.yearpickers.eq(l).html(this._generateYears(l))},_generateHeader:function(m,l){this.calendarCaptions.eq(m).html(l);this._judgeLock(m)},_generateDays:function(q){var t=this._date.currentYear[q],D=this._date.currentMonth[q],C,m=new Date(t,D+1,0).getDate(),s=new Date(t,D,1).getDay(),w=new Date(t,D,0).getDate(),E=s-this.options.firstDayOfWeek,r='<div class="'+this.namespace+'-head">',o,B,l,v,y,n,x=[],u=[];E=E<0?7+E:E;for(var A=0;A<7;A++){var p=this.options.firstDayOfWeek+A>6?this.options.firstDayOfWeek+A-7:this.options.firstDayOfWeek+A;r+="<span>"+f[this.options.lang].daysShort[p]+"</span>"}r+='</div><div class="'+this.namespace+'-body"><div class="'+this.namespace+'-row">';for(var z=0;z<42;z++){C=(z-E+1);B=false;l=false;o=false;v=false;x=[o,B,l,v];y=0;n="";if(z>0&&z%7===0){r+='</div><div class="'+this.namespace+'-row">'}if(z<E){n=this.namespace+"_otherMonth";y=(w-E+z+1);u[z]=new Date(t,D-1,y,0,0,0,0)}else{if(z>(m+E-1)){n=this.namespace+"_otherMonth";y=(C-m);u[z]=new Date(t,(D+1),y,0,0,0,0)}else{u[z]=new Date(t,D,C,0,0,0,0);y=C;if(this.hasKeyboard){if(this.mode==="multiple"){if(Date.parse(u[z])===Date.parse(this._date.focusDate)){n+=" "+this.namespace+"_focus"}}else{if(Date.parse(u[z])===Date.parse(this._date.focusDate[q])){n+=" "+this.namespace+"_focus"}}}}}x=this._judgeStatus(q,"days",this.mode,x,u[z],this._date.selectedDate);n+=this._renderStatus(x);r+='<span class="'+n+'">'+y+"</span>"}r+="</div></div>";return r},_generateMonths:function(s){var v=this._date.currentYear[s],r="",u,t=f[this.options.lang].monthsShort,m=[],x=this._date.focusDate[s],w,n,l,q,o=[];r+='<div class="'+this.namespace+'-row">';for(var p=0;p<12;p++){w=false;n=false;l=false;q=false;o=[l,w,n,q];u="";if(p>0&&p%3===0){r+='</div><div class="'+this.namespace+'-row">'}m[p]=new Date(v,p,1,0,0,0,0);if(this.hasKeyboard){if(Date.parse(m[p])===Date.parse(new Date(x.getFullYear(),x.getMonth(),1,0,0,0,0))){u+=" "+this.namespace+"_focus"}}o=this._judgeStatus(s,"months",this.mode,o,m[p],this._date.selectedMonthDate);u+=this._renderStatus(o);r+='<span class="month-'+p+" "+u+'">'+t[p]+"</span>"}r+="</div>";return r},_generateYears:function(t){var w=this._date.currentYear[t],s="",v,u=0,n=[],y=this._date.focusDate[t],x,p,l,r,q=[];s+='<div class="'+this.namespace+'-row">';for(var o=0;o<12;o++){x=false;p=false;l=false;r=false;q=[l,x,p,r];v="";u=w-7+o;if(o>0&&o%3===0){s+='</div><div class="'+this.namespace+'-row">'}n[o]=new Date(u,0,1,0,0,0,0);if(this.hasKeyboard){if(Date.parse(n[o])===Date.parse(new Date(y.getFullYear(),0,1,0,0,0,0))){v+=" "+this.namespace+"_focus"}}q=this._judgeStatus(t,"years",this.mode,q,n[o],this._date.selectedYearDate);v+=this._renderStatus(q);s+='<span class="'+v+'">'+u+"</span>"}s+="</div>";return s},_judgeLock:function(l){var p=false,o=false,n,m;switch(this.mode){case"range":if(l===0){switch(this.views[l]){case"days":n=Date.parse(this._date.currentDate[l]);m=Date.parse(this._date.selectedMonthDate[1]);break;case"months":n=Date.parse(this._date.currentYearDate[l]);m=Date.parse(this._date.selectedYearDate[1]);break;case"years":n=new Date(this._date.currentYearDate[l]).setFullYear(this._date.currentYear[l]+4);m=Date.parse(this._date.selectedYearDate[1]);break}o=!this._setPoint("<",o,n,m)}else{switch(this.views[l]){case"days":n=Date.parse(this._date.currentDate[l]);m=Date.parse(this._date.selectedMonthDate[0]);break;case"months":n=Date.parse(this._date.currentYearDate[l]);m=Date.parse(this._date.selectedYearDate[0]);break;case"years":n=new Date(this._date.currentYearDate[l]).setFullYear(this._date.currentYear[l]-7);m=Date.parse(this._date.selectedYearDate[0]);break}p=!this._setPoint(">",p,n,m)}break;case"multiple":if(this.calendarsNum>1){if(l===0){o=true}else{if(l===this.calendarsNum-1){p=true}else{p=o=true}}}break}if(p===true){this.calendarPrevs.eq(l).addClass(this.namespace+"_blocked")}else{this.calendarPrevs.eq(l).removeClass(this.namespace+"_blocked")}if(o===true){this.calendarNexts.eq(l).addClass(this.namespace+"_blocked")}else{this.calendarNexts.eq(l).removeClass(this.namespace+"_blocked")}},_judgeSection:function(n,l,o){var m=true;if(n<l||n>o){m=false}return m},_judgeSections:function(q,m,l,p){var s=this,o=false;switch(q){case"date":if(p){m=Date.parse(m);e.each(l,function(v,u){if(!o){switch(u.length){case b:if(m===Date.parse(u)){o=true}break;case 2:o=s._judgeSection(m,Date.parse(u[0]),Date.parse(u[1]));break}}})}else{var n=Date.parse(m[0]),r=Date.parse(m[1]);e.each(l,function(v,u){if(!o){switch(u.length){case b:if(Date.parse(u)>=n&&Date.parse(u)<=r){o=true}break;case 2:o=true;if(r<Date.parse(u[0])||n>Date.parse(u[1])){o=false}break}}})}break;case"block":e.each(l,function(v,u){if(!o){switch(u.length){case b:if(m===u){o=true}break;case 2:o=s._judgeSection(m,u[0],u[1]);break}}});break;case"dayOfWeek":var t=m.getDay();e.each(l,function(v,u){if(!o){switch(u.length){case b:if(t===u){o=true}break;case 2:o=s._judgeSection(t,u[0],u[1]);break}}});break}return o},_judgeStatus:function(r,t,p,n,l,q){var s=n[0],m=n[1],u=n[2];s=!this._isSelectable(t,l.getFullYear(),l.getMonth(),l.getDate());switch(p){case"single":m=this._setPoint("=",m,Date.parse(l),Date.parse(q[r]));break;case"range":m=this._setPoint("=",m,Date.parse(l),Date.parse(q[r]));u=this._setSection(u,l,q[0],q[1]);if(r===0){s=this._setPoint(">",s,Date.parse(l),Date.parse(q[1]))}else{if(r===1){s=this._setPoint("<",s,Date.parse(l),Date.parse(q[0]))}}break;case"multiple":for(var o=0;o<this._date.selectedDate.length;o++){if(Date.parse(l)===q[o]){m=true}}break}return n=[s,m,u]},_setPoint:function(p,m,l,n){var o=m;switch(p){case"=":if(l===n){o=true}break;case"<":if(l<n){o=true}break;case">":if(l>n){o=true}break}return o},_setSection:function(n,m,l,s){var r=n,q=Date.parse(m),p=Date.parse(l),o=Date.parse(s);if(q>=p&&q<=o){r=true}return r},_isSelectable:function(x,w,o,u){var s=true,r=this._parseDate(this.options.min,this.format),z=this._parseDate(this.options.max,this.format),t=this._parseDateArr(this.options.selectableDate,this.format),B=this._parseDateSection(this.options.selectableYear),n=this._parseDateSection(this.options.selectableMonth),q=this._parseDateSection(this.options.selectableDay),l=this._parseDateSection(this.options.selectableDayOfWeek);var p,C,v,A;switch(x){case"years":p=new Date(w,0,1);C=new Date(w+1,0,0);v=[p,C];A=false;break;case"months":p=new Date(w,o,1);C=new Date(w,o+1,0);v=[p,C];A=false;break;case"days":p=C=v=new Date(w,o,u);A=true;break}if(r&&r>C){s=false}if(z&&z<p){s=false}if(s&&t.length>0){s=this._judgeSections("date",v,t,A)}if(s&&B.length>0){s=this._judgeSections("block",w,B)}if(x==="months"||x==="days"){if(s&&n.length>0){s=this._judgeSections("block",o,n)}}if(x==="days"){if(s&&q.length>0){s=this._judgeSections("block",u,q)}if(s&&l.length>0){s=this._judgeSections("dayOfWeek",new Date(w,o,u),l)}}return s},_renderStatus:function(m){var l=m[0],p=m[1],q=m[2],n=m[3],o="";if(n===true){o=" "+this.namespace+"_untouchable"}else{if(l===true){o=" "+this.namespace+"_untouchable"}if(q===true){o+=" "+this.namespace+"_inRange"}}if(p===true){o+=" "+this.namespace+"_active"}return o},_changeView:function(m,l){switch(m){case"caption":if(this.options.mode!=="multiple"){if(this.views[l]==="days"){this.views[l]="months"}else{if(this.views[l]==="months"){this.views[l]="years"}}}break;case"content":if(this.views[l]==="years"){this.views[l]="months"}else{if(this.views[l]==="months"){this.views[l]="days"}}break;case"higher":if(this.options.mode!=="multiple"){if(this.views[l]==="days"){this.views[l]="months"}else{if(this.views[l]==="months"){this.views[l]="years"}}}break;case"lower":if(this.options.mode!=="multiple"){if(this.views[l]==="years"){this.views[l]="months"}else{if(this.views[l]==="months"){this.views[l]="days"}}}break}},_setDate:function(o,n,l){if(typeof n==="object"){for(var m in n){switch(m){case"day":o.setDate(n[m]);break;case"month":o.setMonth(n[m]);break;case"year":o.setYear(n[m]);break}}}else{switch(n){case"day":o.setDate(l);break;case"month":o.setMonth(l);break;case"year":o.setYear(l);break}}},_formatDate:function(l,o){l=new Date(l);var p={d:l.getDate(),m:l.getMonth()+1,yy:l.getFullYear().toString().substring(2),yyyy:l.getFullYear()};p.dd=(p.d<10?"0":"")+p.d;p.mm=(p.m<10?"0":"")+p.m;l=[];for(var m=0,n=o.parts.length;m<n;m++){l.push(p[o.parts[m]])}return l.join(o.separator)},_stringSeparate:function(o,n){var l=new RegExp("[.\\"+n+"\\s].*?"),p=o.match(l),m=o.split(p);return m},_parseHtmlString:function(o,p){var r=[],m=k.defaults;if(typeof m[o]==="object"){var q=this._stringSeparate(p,","),l;for(var n=0;n<q.length;n++){l=this._stringSeparate(q[n],">");if(l.length>1){l={from:l[0],to:l[1]}}else{l=l[0]}r.push(l)}return r}else{return p}},_parseFormat:function(n){var m=n.match(/[.\/\-\s].*?/),l=n.split(/\W+/)||l;if(!l||l.length===0){throw new Error("Invalid date format.")}return{separator:m,parts:l}},_parseDate:function(p,r){if(p!==null){var m=new Date(),l=m.getDate();switch(typeof(p)){case"string":if(p.length<5){m.setHours(0,0,0,0);m.setDate(l+Number(p))}else{var q=p.split(r.separator)||q,s;m.setHours(0,0,0,0);if(q.length===r.parts.length){for(var n=0,o=r.parts.length;n<o;n++){s=parseInt(q[n],10)||1;if(s==="1"){return}switch(r.parts[n]){case"dd":case"d":m.setDate(s);break;case"mm":case"m":m.setMonth((s-1),1);break;case"yy":m.setFullYear(2000+s);break;case"yyyy":m.setFullYear(s);break}}}}break;case"number":m.setHours(0,0,0,0);m.setDate(l+p);break}return m}else{return null}},_parseDateArr:function(n,s){var p=[],o=0;for(var m=0;m<n.length;m++){if(typeof(n[m])==="string"){p[o++]=this._parseDate(n[m],s)}else{if(typeof(n[m])==="object"){var l=n[m],q,r;for(var t in l){switch(t){case"from":q=l[t];break;case"to":r=l[t];break}}p[o++]=[this._parseDate(q,s),this._parseDate(r,s)]}}}return p},_parseDateSection:function(l){var s=[],o=0;for(var n=0;n<l.length;n++){if(typeof(l[n])==="number"){s[o++]=l[n]}else{if(typeof(l[n])==="string"){s[o++]=Number(l[n])}else{if(typeof(l[n])==="object"){var p=l[n],r,q;for(var m in p){switch(m){case"from":r=Number(p[m]);break;case"to":q=Number(p[m]);break}}s[o++]=[r,q]}}}}return s},_updateDate:function(l){this._date.currentDate[l].setHours(0,0,0,0);this._date.currentDay[l]=this._date.currentDate[l].getDate();this._date.currentMonth[l]=this._date.currentDate[l].getMonth();this._date.currentYear[l]=this._date.currentDate[l].getFullYear();this._date.currentMonthDate[l]=new Date(this._date.currentYear[l],this._date.currentMonth[l],1,0,0,0,0);this._date.currentYearDate[l]=new Date(this._date.currentYear[l],0,1,0,0,0,0);if(this.mode!=="multiple"){this._date.selectedDay[l]=this._date.selectedDate[l].getDate();this._date.selectedMonth[l]=this._date.selectedDate[l].getMonth();this._date.selectedYear[l]=this._date.selectedDate[l].getFullYear();this._date.selectedMonthDate[l]=new Date(this._date.selectedYear[l],this._date.selectedMonth[l],1,0,0,0,0);this._date.selectedYearDate[l]=new Date(this._date.selectedYear[l],0,1,0,0,0,0)}},_position:function(){var x=this.$picker.outerHeight(),v=this.$picker.outerWidth(),n=this.$container.height()||i.innerHeight,l=this.$el.offset().top,u=this.$el.offset().left,q=this.$el.outerHeight(),s=this.$el.outerWidth(),o=i.innerWidth,p=i.innerHeight,t=this.$container.scrollLeft()||0,m,w,r=this.options.position;if(this.isMobile){m=(o-v)/2;w=(p-x)/2}else{switch(r){case"bottom":case"right":case"left":if((l+q+x)>(n)){if(r==="bottom"){r="top"}else{if(r="left"){r="leftTop"}else{if(r="right"){r="rightTop"}}}}break;case"top":case"rightTop":case"leftTop":if(l-x<0){if(r==="top"){r="bottom"}else{if(r="leftTop"){r="left"}else{if(r="rightTop"){r="right"}}}}break}switch(r){case"top":m=u+t;w=l-x;break;case"right":m=u+s+t;w=l;break;case"bottom":m=u+t;w=l+q;break;case"left":m=u-v+t;w=l;break;case"rightTop":m=u+s+t;w=l-x+q;break;case"leftTop":m=u-v+t;w=l-x+q;break}}this.$picker.css({left:m,top:w})},_toggle:function(){if(this.showed){this.pickerHide=true;this._blur()}else{this._focus()}},_focus:function(){if(this.options.displayMode==="dropdown"&&this.showed===false){this.show()}if(this.hasKeyboard){this._keyboard.init(this)}},_blur:function(){if(this.options.displayMode==="dropdown"){if(this.pickerHide===true){this.hide();this.pickerHide=false}}if(this.hasKeyboard){this._keyboard.destroy(this)}},_trigger:function(m){var o=arguments.length>1?Array.prototype.slice.call(arguments,1).push(this):this;this.$el.trigger(h+"::"+m,o);m=m.replace(/\b\w+\b/g,function(p){return p.substring(0,1).toUpperCase()+p.substring(1)});var n="on"+m;var l=arguments.length>1?Array.prototype.slice.call(arguments,1):b;if(typeof this.options[n]==="function"){this.options[n].apply(this,l)}},_click:function(s){var l=e(s.target);if(l.closest(this.$inputIcon).length===0&&l.closest(this.$picker).length===0&&l.closest(this.$el).length===0&&this.options.alwaysShow===false){if(this.isMobile){this.mobileCancel(0)}else{this.hide()}}else{if(l.closest(this.$el).length!==1&&l.closest(this.$picker).length===1){var n=e(s.target).closest("div");var q=e(s.target).closest("span");if(n.parent("."+this.namespace+"-header").length===1){var r=n.parents("."+this.namespace+"-content").index();switch(n[0].className){case this.namespace+"-caption":this._changeView("caption",r);this._manageViews(r);break;case this.namespace+"-prev":this.prev(r);break;case this.namespace+"-next":this.next(r);break}}if(q.length===1){var p=q.parents("."+this.namespace+"-content").index();if(!q.hasClass(this.namespace+"_otherMonth")&&!q.hasClass(this.namespace+"_untouchable")&&q.parent("."+this.namespace+"-head").length!==1){this._changeValue(q,p);this._changeView("content",p);this._updateDate(p);switch(this.mode){case"single":if(this.views[p]==="days"){this.selected=true}this._manageViews(p);break;case"range":this._manageViews(0);this._manageViews(1);break;case"multiple":this._manageViews(p-1);this._manageViews(p);this._manageViews(p+1);break}if(!this.isMobile){this._setValue()}}}if(n.parent("."+this.namespace+"-buttons").length===1){var o=n.parents("."+this.namespace+"-content").index(),m=n[0].className===this.namespace+"-button-save"?true:false;if(m){this.mobileEnter(o)}else{this.mobileCancel(o)}}if(!this.isMobile){if(this.selected===true&&this.options.alwaysShow===false&&this.options.onceClick===true){this.hide()}else{if(this.options.displayMode==="dropdown"){this.$el.focus()}}}}}s.preventDefault()},_changeValue:function(q,p){var o="",l="",m=this;switch(this.views[p]){case"years":o=parseInt(q.text(),10);this._date.currentDate[p].setYear(o);break;case"months":o=Number(q.attr("class").match(/month\-([0-9]+)/)[1]);this._date.currentDate[p].setMonth(o);break;case"days":o=parseInt(q.text(),10);l=new Date(this._date.currentYear[p],this._date.currentMonth[p],o,0,0,0,0);switch(this.options.mode){case"single":case"range":this._date.selectedDate[p]=l;break;case"multiple":var n=Date.parse(l);if(e.inArray(n,this._date.selectedDate)>-1){e.each(this._date.selectedDate,function(r,s){if(s===n){m._date.selectedDate.splice(r,1)}})}else{if(this._date.selectedDate.length<this.options.multipleSize){this._date.selectedDate.push(n)}}break}break}},_setValue:function(){switch(this.mode){case"single":var q=this._formatDate(this._date.selectedDate[0],this.outputFormat);this.$el.val(q);break;case"range":var p=this._formatDate(this._date.selectedDate[0],this.outputFormat),n=this._formatDate(this._date.selectedDate[1],this.outputFormat);this.$el.val(p+" "+this.options.rangeSeparator+" "+n);break;case"multiple":var o="",l;for(var m=0;m<this._date.selectedDate.length;m++){l=this._formatDate(this._date.selectedDate[m],this.outputFormat);if(o.length===0){o+=l}else{o+=(this.options.multipleSeparator+l)}}this.$el.val(o);break}this._trigger("change",this.getDate("yyyy-mm-dd"),this.options.name,h);this.oldValue=this.$el.val()},_prevent:function(l){if(l.preventDefault){l.preventDefault()}else{l.returnvalue=false}},_removeEvents:function(){if(this.options.displayMode==="inline"){this.picker.off("click.picke")}else{d.off("click."+this.flag)}this.$el.off("focus");this.$el.off("blur")},prev:function(q,p){this.touchflag=false;var o=this._date.currentDate[q];switch(this.views[q]){case"days":var m;if(this.mode==="multiple"){if(p){if(this.focused===0){for(var n=0;n<this.calendarsNum;n++){this._date.currentDate[n].setMonth(this._date.currentMonth[n]-1);this._updateDate(n);this._manageViews(n)}}else{--this.focused;this._manageViews(q);this._manageViews(q-1)}}else{m=new Date(o.getFullYear(),o.getMonth(),0).getDate();if(this._date.focusDate.getDate()>m){this._date.focusDate.setDate(m)}this._date.focusDate.setMonth(this._date.focusDate.getMonth()-1);for(var l=0;l<this.calendarsNum;l++){this._date.currentDate[l].setMonth(this._date.currentMonth[l]-1);this._updateDate(l);this._manageViews(l)}}}else{o.setMonth(this._date.currentMonth[q]-1);if(this.hasKeyboard){m=new Date(o.getFullYear(),o.getMonth(),0).getDate();if(this._date.focusDate[q].getDate()>m){this._date.focusDate[q].setDate(m)}this._date.focusDate[q]=new Date(o.getFullYear(),o.getMonth(),this._date.focusDate[q].getDate(),0,0,0,0)}}break;case"months":o.setYear(this._date.currentYear[q]-1);if(this.hasKeyboard){this._date.focusDate[q]=new Date(o.getFullYear(),this._date.focusDate[q].getMonth(),this._date.focusDate[q].getDate(),0,0,0,0)}break;case"years":o.setYear(this._date.currentYear[q]-12);if(this.hasKeyboard&&p){this._date.focusDate[q]=new Date(this._date.focusDate[q].getFullYear()-12,this._date.focusDate[q].getMonth(),this._date.focusDate[q].getDate(),0,0,0,0)}break}this._updateDate(q);this._manageViews(q)},next:function(p,o){this.touchflag=false;var n=this._date.currentDate[p];switch(this.views[p]){case"days":var q;if(this.mode==="multiple"){if(o){if(this.focused===this.calendarsNum-1){for(var m=0;m<this.calendarsNum;m++){this._date.currentDate[m].setMonth(this._date.currentMonth[m]+1);this._updateDate(m);this._manageViews(m)}}else{++this.focused;this._manageViews(p);this._manageViews(p+1)}}else{q=new Date(n.getFullYear(),n.getMonth()+2,0).getDate();if(this._date.focusDate.getDate()>q){this._date.focusDate.setDate(q)}this._date.focusDate.setMonth(this._date.focusDate.getMonth()+1);for(var l=0;l<this.calendarsNum;l++){this._date.currentDate[l].setMonth(this._date.currentMonth[l]+1);this._updateDate(l);this._manageViews(l)}}}else{n.setMonth(this._date.currentMonth[p]+1);if(this.hasKeyboard){q=new Date(n.getFullYear(),n.getMonth()+1,0).getDate();if(this._date.focusDate[p].getDate()>q){this._date.focusDate[p].setDate(q)}this._date.focusDate[p]=new Date(n.getFullYear(),n.getMonth(),this._date.focusDate[p].getDate(),0,0,0,0)}}break;case"months":n.setYear(this._date.currentYear[p]+1);if(this.hasKeyboard){this._date.focusDate[p]=new Date(n.getFullYear(),this._date.focusDate[p].getMonth(),this._date.focusDate[p].getDate(),0,0,0,0)}break;case"years":n.setYear(this._date.currentYear[p]+12);if(this.hasKeyboard&&o){this._date.focusDate[p]=new Date(this._date.focusDate[p].getFullYear()+12,this._date.focusDate[p].getMonth(),this._date.focusDate[p].getDate(),0,0,0,0)}break}this._updateDate(p);this._manageViews(p)},mobilePrev:function(l){this.calendars.eq(l).removeClass(this.namespace+"_show");this.calendars.eq(l-1).addClass(this.namespace+"_show")},mobileNext:function(l){this.calendars.eq(l).removeClass(this.namespace+"_show");this.calendars.eq(l+1).addClass(this.namespace+"_show")},mobileInteDate:function(m){var l=this;if(this.mode==="multiple"){if(this._date.selectedDate.length>0){l._date.currentDate[0]=new Date(this._date.selectedDate[0])}}else{this._date.currentDate[m]=new Date(this._date.selectedDate[m])}this.views[m]="days";this._updateDate(m)},mobileEnter:function(l){if(this.mode==="range"&&l===0){this.mobileNext(l);this.views[l]="days"}else{this.mobileInteDate(l);this._setValue();this.hide()}this._manageViews(l)},mobileCancel:function(l){if(l===1){this.mobilePrev(l);this.views[l]="days"}else{this.dateTransform(this._date.cache,this._date);this.mobileInteDate(l);this.hide()}this._manageViews(l)},dateTransform:function(n,m){var l=this;m.currentDate=[];m.selectedDate=[];e.each(n.currentDate,function(p,o){m.currentDate[p]=new Date(o)});e.each(n.selectedDate,function(q,o){var p=new Date(o);m.selectedDate[q]=l.mode==="multiple"?Date.parse(p):p})},show:function(){var l=this;if(this.isMobile){this.dateTransform(this._date,this._date.cache)}if(this.options.displayMode==="inline"){this._trigger("beforeShow");this.$picker.on("mouseDown."+this.flag,function(n){l._prevent(n)});this.$picker.on("click."+this.flag,function(n){l._click.call(l,n)})}else{if(this.showed===false){this._trigger("beforeShow");this.$inputWrap.addClass(this.namespace+"_active");this.$picker.addClass(this.namespace+"_show");if(this.isMobile){this.calendars.eq(0).addClass(this.namespace+"_show");if(this.mode==="range"){this.calendars.eq(1).removeClass(this.namespace+"_show")}e("body").append(this.$cover).css("overflow","hidden");d.on("scrollstart."+this.flag,function(n){n.preventDefault()});d.on("tap."+this.flag,function(n){l._click.call(l,n)});var m=function(p){var o=p.swipestart.coords[0],n=p.swipestop.coords[0];if(n>o){l.prev.call(l,0)}else{if(n<o){l.next.call(l,0)}}d.one("swipe."+l.flag,m)};d.one("swipe."+this.flag,m)}else{d.on("click."+this.flag,function(n){l._click.call(l,n)})}this._position();this.showed=true;a.on("resize."+this.flag,function(){l._position()});this.$picker.on("mousedown."+this.flag,function(n){l._prevent(n)})}}this._trigger("show");return this},hide:function(){if(this.showed===true){this._trigger("beforeHide");this.selected=false;this.$inputWrap.removeClass(this.namespace+"_active");this.$picker.removeClass(this.namespace+"_show");this.showed=false;this.$picker.off("mousedown."+this.flag);d.off("click."+this.flag);a.off("resize."+this.flag);if(this.isMobile){e("body").css("overflow","auto");this.$cover.remove();d.off("click."+this.flag+" tap."+this.flag+" scrollstart."+this.flag+" swipe."+this.flag)}this.$el.blur();this._trigger("hide")}return this},getWrap:function(){return this.picker},getInput:function(){return this.$el},getDate:function(n){if(n===b){return this._date.selectedDate}else{var l=this._parseFormat(n),o=[];for(var m=0;m<this._date.selectedDate.length;
m++){o[m]=this._formatDate(this._date.selectedDate[m],l)}return o}},multipleClear:function(){this._date.selectedDate=[];for(var l=0;l<this.calendarsNum;l++){this._manageViews(l)}this._setValue()},destroy:function(){this.$el.removeData("asDatepicker");this._removeEvents();this.$picker.remove()},update:function(n){if(typeof n!=="undefined"){for(var l in n){this.options[l]=n[l]}}this._removeEvents();this.$picker.remove();this._init()},reset:function(o){for(var l in this.defaultOptions){this.options[l]=this.defaultOptions[l]}if(typeof o!=="undefined"){for(var p in o){this.options[p]=o[p]}}this._removeEvents();this.$picker.remove();this._init()},_keyboard:{init:function(l){this.attach(l,this.gather(l))},destroy:function(l){if(l.options.displayMode==="dropdown"){l.$el.off("keydown.dropdown")}else{l.$picker.off("keydown.inline")}l.bound=false},keys:function(){return{LEFT:37,UP:38,RIGHT:39,DOWN:40,ENTER:13,ESC:27,CTRL:17,ALT:18}},prevDate:function(){var m=this.focused,l=this.mode==="multiple"?this._date.focusDate:this._date.focusDate[m],n=this.mode==="multiple"?false:this.calendarPrevs.eq(this.focused).hasClass(this.namespace+"_blocked");switch(this.views[m]){case"days":if(Date.parse(l)===Date.parse(this._date.currentDate[m])){if(!n){l.setDate(l.getDate()-1);this.prev(m,true)}}else{l.setDate(l.getDate()-1);this._manageViews(m)}break;case"months":if(l.getMonth()===0){if(!n){l.setMonth(l.getMonth()-1);this.prev(m)}}else{l.setMonth(l.getMonth()-1);this._manageViews(m)}break;case"years":if(l.getFullYear()===this._date.currentYear[m]-7){if(!n){l.setFullYear(l.getFullYear()-1);this.prev(m)}}else{l.setFullYear(l.getFullYear()-1);this._manageViews(m)}break}},nextDate:function(){var m=this.focused,l=this.mode==="multiple"?this._date.focusDate:this._date.focusDate[m],n=this.mode==="multiple"?false:this.calendarNexts.eq(this.focused).hasClass(this.namespace+"_blocked");switch(this.views[m]){case"days":if(Date.parse(l)===Date.parse(new Date(this._date.currentYear[m],this._date.currentMonth[m]+1,0))){if(!n){l.setDate(l.getDate()+1);this.next(m,true)}}else{l.setDate(l.getDate()+1);this._manageViews(m)}break;case"months":if(l.getMonth()===11){if(!n){l.setMonth(l.getMonth()+1);this.next(m)}}else{l.setMonth(l.getMonth()+1);this._manageViews(m)}break;case"years":if(l.getFullYear()===this._date.currentYear[m]+4){if(!n){l.setFullYear(l.getFullYear()+1);this.next(m)}}else{l.setFullYear(l.getFullYear()+1);this._manageViews(m)}break}},upLine:function(){var m=this.focused,l=this.mode==="multiple"?this._date.focusDate:this._date.focusDate[m],n=this.mode==="multiple"?false:this.calendarPrevs.eq(this.focused).hasClass(this.namespace+"_blocked");switch(this.views[m]){case"days":if(new Date(l.getFullYear(),l.getMonth(),l.getDate()-7).setDate(1)===new Date(this._date.currentDate[m]).setMonth(this._date.currentMonth[m]-1)){if(!n){l.setDate(l.getDate()-7);this.prev(m,true)}}else{l.setDate(l.getDate()-7);this._manageViews(m)}break;case"months":if(l.getMonth()===0||l.getMonth()===1||l.getMonth()===2){if(!n){l.setMonth(l.getMonth()-3);this.prev(m)}}else{l.setMonth(l.getMonth()-3);this._manageViews(m)}break;case"years":if(l.getFullYear()<this._date.currentYear[m]-4){if(!n){l.setFullYear(l.getFullYear()-3);this.prev(m)}}else{l.setFullYear(l.getFullYear()-3);this._manageViews(m)}break}},downLine:function(){var m=this.focused,l=this.mode==="multiple"?this._date.focusDate:this._date.focusDate[m],n=this.mode==="multiple"?false:this.calendarNexts.eq(this.focused).hasClass(this.namespace+"_blocked");switch(this.views[m]){case"days":if(new Date(l.getFullYear(),l.getMonth(),l.getDate()+7).setDate(1)===new Date(this._date.currentDate[m]).setMonth(this._date.currentMonth[m]+1)){if(!n){l.setDate(l.getDate()+7);this.next(m,true)}}else{l.setDate(l.getDate()+7);this._manageViews(m)}break;case"months":if(l.getMonth()===9||l.getMonth()===10||l.getMonth()===11){if(!n){l.setMonth(l.getMonth()+3);this.next(m)}}else{l.setMonth(l.getMonth()+3);this._manageViews(m)}break;case"years":if(l.getFullYear()>this._date.currentYear[m]+1){if(!n){l.setFullYear(l.getFullYear()+3);this.next(m)}}else{l.setFullYear(l.getFullYear()+3);this._manageViews(m)}break}},prevPage:function(){if(this.mode==="multiple"){this.prev(this.focused)}else{if(!this.calendarPrevs.eq(this.focused).hasClass(this.namespace+"_blocked")){this.prev(this.focused,true)}}},nextPage:function(){if(this.mode==="multiple"){this.next(this.focused)}else{if(!this.calendarNexts.eq(this.focused).hasClass(this.namespace+"_blocked")){this.next(this.focused,true)}}},higherView:function(){if(this.mode!=="multiple"){var l=this.focused;this._changeView("higher",l);this._manageViews(l)}},prevCalendar:function(){if(this.mode!=="multiple"){var l=this.calendars.length;if(--this.focused<0){this.focused=l}}},nextCalendar:function(){if(this.mode!=="multiple"){var l=this.calendars.length;if(++this.focused>=l){this.focused=0}}},updateValue:function(m){var o=m.focused,n=m.mode==="multiple"?m._date.focusDate:m._date.focusDate[o];if(!m.calendars.eq(o).find("."+m.namespace+"_focus").hasClass(m.namespace+"_untouchable")){switch(m.views[o]){case"days":switch(m.options.mode){case"single":case"range":m._date.selectedDate[o]=new Date(n);break;case"multiple":var l=Date.parse(new Date(n));if(e.inArray(l,m._date.selectedDate)>-1){e.each(m._date.selectedDate,function(p,q){if(q===l){m._date.selectedDate.splice(p,1);return false}})}else{m._date.selectedDate.push(l)}break}break;case"months":m._date.currentDate[o].setMonth(n.getMonth());m.views[o]="days";break;case"years":m._date.currentDate[o].setFullYear(n.getFullYear());m.views[o]="months";break}m._updateDate(o);if(m.mode==="range"){m._manageViews(0);m._manageViews(1)}else{if(m.mode==="multiple"){m._manageViews(o-1);m._manageViews(o);m._manageViews(o+1)}else{m._manageViews(o)}}m._setValue()}},enter:function(){var n=this.$el.val(),w=this,t;if(n===this.oldValue||this.oldValue===""){this._keyboard.updateValue(this)}else{var q;switch(this.mode){case"single":var x=Date.parse(n);if(x){this._date.selectedDate[0]=new Date(x);this._date.currentDate[0]=new Date(this._date.selectedDate[0]);this._updateDate(0);this._manageViews(0)}break;case"range":q=this._stringSeparate(n,this.options.rangeSeparator);var u=Date.parse(q[0]),v=Date.parse(q[1]);if(q.length===2){t=true;if(u&&v){if(u>v){t=false}}else{t=false}}else{t=false}if(t===true){this._date.selectedDate[0]=new Date(u);this._date.selectedDate[1]=new Date(v);for(var r=0;r<2;r++){this._date.currentDate[r]=new Date(this._date.selectedDate[r]);this._updateDate(r);this._manageViews(r)}}else{this._keyboard.updateValue(this)}break;case"multiple":q=this._stringSeparate(n,this.options.multipleSeparator);var s=[];t=true;for(var p=0;p<q.length;p++){s.push(Date.parse(q[p]));if(!Date.parse(q[p])){t=false}}if(t===true){this._date.selectedDate=[];for(var o=0;o<s.length;o++){if(e.inArray(s[o],this._date.selectedDate)>-1){e.each(this._date.selectedDate,function(m,y){if(y===s[o]){w._date.selectedDate.splice(m,1)}})}else{this._date.selectedDate.push(s[o])}}for(var l=0;l<this.calendarsNum;l++){this._updateDate(l);this._manageViews(l)}}else{this._keyboard.updateValue(this)}break}}this._setValue()},esc:function(){this.$el.blur();this.hide()},tab:function(){this.pickerHide=true},gather:function(l){return{left:e.proxy(this.prevDate,l),up:e.proxy(this.upLine,l),right:e.proxy(this.nextDate,l),down:e.proxy(this.downLine,l),ctrl_left:e.proxy(this.prevPage,l),ctrl_up:e.proxy(this.higherView,l),ctrl_right:e.proxy(this.nextPage,l),alt_left:e.proxy(this.prevCalendar,l),alt_right:e.proxy(this.nextCalendar,l),enter:e.proxy(this.enter,l),esc:e.proxy(this.esc,l)}},press:function(n){var l=n.keyCode||n.which,m;if(n.ctrlKey){n.preventDefault();m=this.map[17]}else{if(n.altKey){n.preventDefault();m=this.map[18]}else{m=this.map}}if(l===9){this._keyboard.tab.call(this)}if(l in m&&typeof m[l]==="function"){n.preventDefault();m[l].call(this)}},attach:function(n,s){var q,m=this;for(q in s){if(s.hasOwnProperty(q)){var o=[],r=n._stringSeparate(q,"_"),l=r.length;if(l===1){o[0]=r[0].toUpperCase();n.map[this.keys()[o[0]]]=s[q]}else{for(var p=0;p<r.length;p++){o[p]=r[p].toUpperCase();if(p===0){if(n.map[this.keys()[o[0]]]===b){n.map[this.keys()[o[0]]]={}}}else{n.map[this.keys()[o[0]]][this.keys()[o[p]]]=s[q]}}}}}if(!n.bound){n.bound=true;if(n.options.displayMode==="dropdown"){n.$el.on("keydown.dropdown",function(t){m.press.call(n,t)})}else{n.$picker.on("keydown.inline",function(t){m.press.call(n,t)})}}}}};k.defaults=c;e.fn[h]=function(l){if(typeof l==="string"){var o=l;var m=Array.prototype.slice.call(arguments,1);if(/^\_/.test(o)){return false}else{if(/^(getWrap|getInput|getDate)$/.test(o)){var n=this.first().data(h);if(n&&typeof n[o]==="function"){return n[o].apply(n,m)}}else{return this.each(function(){var p=e.data(this,h);if(p&&typeof p[o]==="function"){p[o].apply(p,m)}})}}}else{return this.each(function(){if(!e.data(this,h)){e.data(this,h,new k(this,l))}})}}})(jQuery,document,window);