"use strict";Date.prototype.getWeek=function(){var onejan=new Date(this.getFullYear(),0,1);return Math.ceil((((this.getTime()-onejan.getTime())/86400000)+onejan.getDay()+1)/7);};Date.prototype.getMonthFormatted=function(){var month=this.getMonth()+1;return month<10?'0'+month:month;};Date.prototype.getDateFormatted=function(){var date=this.getDate();return date<10?'0'+date:date;};if(!String.prototype.format){String.prototype.format=function(){var args=arguments;return this.replace(/{(\d+)}/g,function(match,number){return typeof args[number]!='undefined'?args[number]:match;});};} if(!String.prototype.formatNum){String.prototype.formatNum=function(decimal){var r=""+this;while(r.length'),function(i,chunk){var m,date=null;if(m=/^(\d\d)-(\d\d)$/.exec(chunk)){date=new Date(year,parseInt(m[2],10)-1,parseInt(m[1],10));} else if(m=/^(\d\d)-(\d\d)-(\d\d\d\d)$/.exec(chunk)){if(parseInt(m[3],10)==year){date=new Date(year,parseInt(m[2],10)-1,parseInt(m[1],10));}} else if(m=/^easter(([+\-])(\d+))?$/.exec(chunk)){date=getEasterDate(year,m[1]?parseInt(m[1],10):0);} else if(m=/^(\d\d)([+\-])([1-5])\*([0-6])$/.exec(chunk)){var month=parseInt(m[1],10)-1;var direction=m[2];var offset=parseInt(m[3]);var weekday=parseInt(m[4]);switch(direction){case'+':var d=new Date(year,month,1-7);while(d.getDay()!=weekday){d=new Date(d.getFullYear(),d.getMonth(),d.getDate()+1);} date=new Date(d.getFullYear(),d.getMonth(),d.getDate()+7*offset);break;case'-':var d=new Date(year,month+1,0+7);while(d.getDay()!=weekday){d=new Date(d.getFullYear(),d.getMonth(),d.getDate()-1);} date=new Date(d.getFullYear(),d.getMonth(),d.getDate()-7*offset);break;}} if(!date){warn('Unknown holiday: '+key);failed=true;return false;} switch(i){case 0:firstDay=date;break;case 1:if(date.getTime()<=firstDay.getTime()){warn('Unknown holiday: '+key);failed=true;return false;} lastDay=date;break;default:warn('Unknown holiday: '+key);failed=true;return false;}});if(!failed){var days=[];if(lastDay){for(var date=new Date(firstDay.getTime());date.getTime()<=lastDay.getTime();date.setDate(date.getDate()+1)){days.push(new Date(date.getTime()));}} else{days.push(firstDay);} holidays.push({name:name,days:days});}});getHolidays.cache[hash]=holidays;return getHolidays.cache[hash];} getHolidays.cache={};function warn(message){if($.type(window.console)=='object'&&$.type(window.console.warn)=='function'){window.console.warn('[Bootstrap-Calendar] '+message);}} function Calendar(params,context){this.options=$.extend(true,{position:{start:new Date(),end:new Date()}},defaults,params);this.setLanguage(this.options.language);this.context=context;context.css('width',this.options.width).addClass('cal-context');this.view();return this;} Calendar.prototype.setOptions=function(object){$.extend(this.options,object);if('language'in object){this.setLanguage(object.language);} if('modal'in object){this._update_modal();}} Calendar.prototype.setLanguage=function(lang){if(window.calendar_languages&&(lang in window.calendar_languages)){this.locale=$.extend(true,{},strings,calendar_languages[lang]);this.options.language=lang;}else{this.locale=strings;delete this.options.language;}} Calendar.prototype._render=function(){this.context.html('');this._loadTemplate(this.options.view);this.stop_cycling=false;var data={};data.cal=this;data.day=1;if(getExtentedOption(this,'first_day')==1){data.months=[this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6,this.locale.d0]}else{data.months=[this.locale.d0,this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6]} var start=parseInt(this.options.position.start.getTime());var end=parseInt(this.options.position.end.getTime());data.events=this.getEventsBetween(start,end);switch(this.options.view){case'month':break;case'week':this._calculate_hour_minutes(data);break;case'day':this._calculate_hour_minutes(data);break;} data.start=new Date(this.options.position.start.getTime());data.lang=this.locale;this.context.append(this.options.templates[this.options.view](data));this._update();};Calendar.prototype._calculate_hour_minutes=function(data){var $self=this;var time_split=parseInt(this.options.time_split);var time_split_count=60/time_split;var time_split_hour=Math.min(time_split_count,1);if(((time_split_count>=1)&&(time_split_count%1!=0))||((time_split_count<1)&&(1440/time_split%1!=0))){$.error(this.locale.error_timedevide);} var time_start=this.options.time_start.split(":");var time_end=this.options.time_end.split(":");data.hours=(parseInt(time_end[0])-parseInt(time_start[0]))*time_split_hour;var lines=data.hours*time_split_count-parseInt(time_start[1])/time_split;var ms_per_line=(60000*time_split);var start=new Date(this.options.position.start.getTime());start.setHours(time_start[0]);start.setMinutes(time_start[1]);var end=new Date(this.options.position.end.getTime());end.setHours(time_end[0]);end.setMinutes(time_end[1]);data.all_day=[];data.by_hour=[];data.after_time=[];data.before_time=[];$.each(data.events,function(k,e){var s=new Date(parseInt(e.start));var f=new Date(parseInt(e.end));e.start_hour=s.getHours().toString().formatNum(2)+':'+s.getMinutes().toString().formatNum(2);e.end_hour=f.getHours().toString().formatNum(2)+':'+f.getMinutes().toString().formatNum(2);if(e.startend.getTime()){e.start_hour=s.getDate()+' '+$self.locale['ms'+s.getMonth()]+' '+e.start_hour;e.end_hour=f.getDate()+' '+$self.locale['ms'+f.getMonth()]+' '+e.end_hour;} if(e.start=end.getTime()){data.all_day.push(e);return;} if(e.endend.getTime()){data.after_time.push(e);return;} var event_start=start.getTime()-e.start;if(event_start>=0){e.top=0;}else{e.top=Math.abs(event_start)/ms_per_line;} var lines_left=Math.abs(lines-e.top);var lines_in_event=(e.end-e.start)/ms_per_line;if(event_start>=0){lines_in_event=(e.end-start.getTime())/ms_per_line;} e.lines=lines_in_event;if(lines_in_event>lines_left){e.lines=lines_left;} data.by_hour.push(e);});};Calendar.prototype._hour_min=function(hour){var time_start=this.options.time_start.split(":");var time_split=parseInt(this.options.time_split);var in_hour=60/time_split;return(hour==0)?(in_hour-(parseInt(time_start[1])/time_split)):in_hour;};Calendar.prototype._hour=function(hour,part){var time_start=this.options.time_start.split(":");var time_split=parseInt(this.options.time_split);var h=""+(parseInt(time_start[0])+hour*Math.max(time_split/60,1));var m=""+(time_split*part+((hour==0)?parseInt(time_start[1]):0));return h.formatNum(2)+":"+m.formatNum(2);};Calendar.prototype._week=function(event){this._loadTemplate('week-days');var t={};var start=parseInt(this.options.position.start.getTime());var end=parseInt(this.options.position.end.getTime());var events=[];var self=this;var first_day=getExtentedOption(this,'first_day');$.each(this.getEventsBetween(start,end),function(k,event){event.start_day=new Date(parseInt(event.start)).getDay();if(first_day==1){event.start_day=(event.start_day+6)%7;} if((event.end-event.start)<=86400000){event.days=1;}else{event.days=((event.end-event.start)/86400000);} if(event.start7){event.days=7-(event.start_day);} events.push(event);});t.events=events;t.cal=this;return self.options.templates['week-days'](t);} Calendar.prototype._month=function(month){this._loadTemplate('year-month');var t={cal:this};var newmonth=month+1;t.data_day=this.options.position.start.getFullYear()+'-'+(newmonth<10?'0'+newmonth:newmonth)+'-'+'01';t.month_name=this.locale['m'+month];var curdate=new Date(this.options.position.start.getFullYear(),month,1,0,0,0);t.start=parseInt(curdate.getTime());t.end=parseInt(new Date(this.options.position.start.getFullYear(),month+1,1,0,0,0).getTime());t.events=this.getEventsBetween(t.start,t.end);return this.options.templates['year-month'](t);} Calendar.prototype._day=function(week,day){this._loadTemplate('month-day');var t={tooltip:'',cal:this};var cls=this.options.classes.months.outmonth;var firstday=this.options.position.start.getDay();if(getExtentedOption(this,'first_day')==2){firstday++;}else{firstday=(firstday==0?7:firstday);} day=(day-firstday)+1;var curdate=new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),day,0,0,0);if(day>0){cls=this.options.classes.months.inmonth;} var daysinmonth=(new Date(this.options.position.end.getTime()-1)).getDate();if((day+1)>daysinmonth){this.stop_cycling=true;} if(day>daysinmonth){day=day-daysinmonth;cls=this.options.classes.months.outmonth;} cls=$.trim(cls+" "+this._getDayClass("months",curdate));if(day<=0){var daysinprevmonth=(new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),0)).getDate();day=daysinprevmonth-Math.abs(day);cls+=' cal-month-first-row';} var holiday=this._getHoliday(curdate);if(holiday!==false){t.tooltip=holiday;} t.data_day=curdate.getFullYear()+'-'+curdate.getMonthFormatted()+'-'+(day<10?'0'+day:day);t.cls=cls;t.day=day;t.start=parseInt(curdate.getTime());t.end=parseInt(t.start+86400000);t.events=this.getEventsBetween(t.start,t.end);return this.options.templates['month-day'](t);} Calendar.prototype._getHoliday=function(date){var result=false;$.each(getHolidays(this,date.getFullYear()),function(){var found=false;$.each(this.days,function(){if(this.toDateString()==date.toDateString()){found=true;return false;}});if(found){result=this.name;return false;}});return result;};Calendar.prototype._getHolidayName=function(date){var holiday=this._getHoliday(date);return(holiday===false)?"":holiday;};Calendar.prototype._getDayClass=function(class_group,date){var self=this;var addClass=function(which,to){var cls;cls=(self.options.classes&&(class_group in self.options.classes)&&(which in self.options.classes[class_group]))?self.options.classes[class_group][which]:"";if((typeof(cls)=="string")&&cls.length){to.push(cls);}};var classes=[];if(date.toDateString()==(new Date()).toDateString()){addClass("today",classes);} var holiday=this._getHoliday(date);if(holiday!==false){addClass("holidays",classes);} switch(date.getDay()){case 0:addClass("sunday",classes);break;case 6:addClass("saturday",classes);break;} addClass(date.toDateString(),classes);return classes.join(" ");};Calendar.prototype.view=function(view){if(view){if(!this.options.views[view].enable){return;} this.options.view=view;} this._init_position();this._loadEvents();this._render();this.options.onAfterViewLoad.call(this,this.options.view);};Calendar.prototype.navigate=function(where,next){var to=$.extend({},this.options.position);if(where=='next'){switch(this.options.view){case'year':to.start.setFullYear(this.options.position.start.getFullYear()+1);break;case'month':to.start.setMonth(this.options.position.start.getMonth()+1);break;case'week':to.start.setDate(this.options.position.start.getDate()+7);break;case'day':to.start.setDate(this.options.position.start.getDate()+1);break;}}else if(where=='prev'){switch(this.options.view){case'year':to.start.setFullYear(this.options.position.start.getFullYear()-1);break;case'month':to.start.setMonth(this.options.position.start.getMonth()-1);break;case'week':to.start.setDate(this.options.position.start.getDate()-7);break;case'day':to.start.setDate(this.options.position.start.getDate()-1);break;}}else if(where=='today'){to.start.setTime(new Date().getTime());} else{$.error(this.locale.error_where.format(where))} this.options.day=to.start.getFullYear()+'-'+to.start.getMonthFormatted()+'-'+to.start.getDateFormatted();this.view();if(_.isFunction(next)){next();}};Calendar.prototype._init_position=function(){var year,month,day;if(this.options.day=='now'){var date=new Date();year=date.getFullYear();month=date.getMonth();day=date.getDate();}else if(this.options.day.match(/^\d{4}-\d{2}-\d{2}$/g)){var list=this.options.day.split('-');year=parseInt(list[0],10);month=parseInt(list[1],10)-1;day=parseInt(list[2],10);} else{$.error(this.locale.error_dateformat.format(this.options.day));} switch(this.options.view){case'year':this.options.position.start.setTime(new Date(year,0,1).getTime());this.options.position.end.setTime(new Date(year+1,0,1).getTime());break;case'month':this.options.position.start.setTime(new Date(year,month,1).getTime());this.options.position.end.setTime(new Date(year,month+1,1).getTime());break;case'day':this.options.position.start.setTime(new Date(year,month,day).getTime());this.options.position.end.setTime(new Date(year,month,day+1).getTime());break;case'week':var curr=new Date(year,month,day);var first;if(getExtentedOption(this,'first_day')==1){first=curr.getDate()-((curr.getDay()+6)%7);} else{first=curr.getDate()-curr.getDay();} this.options.position.start.setTime(new Date(year,month,first).getTime());this.options.position.end.setTime(new Date(year,month,first+7).getTime());break;default:$.error(this.locale.error_noview.format(this.options.view))} return this;};Calendar.prototype.getTitle=function(){var p=this.options.position.start;switch(this.options.view){case'year':return this.locale.title_year.format(p.getFullYear());break;case'month':return this.locale.title_month.format(this.locale['m'+p.getMonth()],p.getFullYear());break;case'week':return this.locale.title_week.format(p.getWeek(),p.getFullYear());break;case'day':return this.locale.title_day.format(this.locale['d'+p.getDay()],p.getDate(),this.locale['m'+p.getMonth()],p.getFullYear());break;} return;};Calendar.prototype.isToday=function(){var now=new Date().getTime();return((now>this.options.position.start)&&(now');$('.cal-month-day, .cal-year-box .span3').on('mouseenter',function(){if($('.events-list',this).length==0)return;if($(this).children('[data-cal-date]').text()==self.activecell)return;downbox.show().appendTo(this);}).on('mouseleave',function(){downbox.hide();}).on('click',function(event){if($('.events-list',this).length==0)return;if($(this).children('[data-cal-date]').text()==self.activecell)return;showEventsList(event,downbox,slider,self);});var slider=$(document.createElement('div')).attr('id','cal-slide-box');slider.hide().click(function(event){event.stopPropagation();});this._loadTemplate('events-list');downbox.click(function(event){showEventsList(event,$(this),slider,self);});};Calendar.prototype.getEventsBetween=function(start,end){var events=[];$.each(this.options.events,function(){if(this.start==null){return true;} var event_end=this.end||this.start;if((parseInt(this.start)=start)){events.push(this);}});return events;};function showEventsList(event,that,slider,self){event.stopPropagation();var that=$(that);var cell=that.closest('.cal-cell');var row=cell.closest('.cal-before-eventlist');var tick_position=cell.data('cal-row');that.fadeOut('fast');slider.slideUp('fast',function(){var event_list=$('.events-list',cell);slider.html(self.options.templates['events-list']({cal:self,events:self.getEventsBetween(parseInt(event_list.data('cal-start')),parseInt(event_list.data('cal-end')))}));row.after(slider);self.activecell=$('[data-cal-date]',cell).text();$('#cal-slide-tick').addClass('tick'+tick_position).show();slider.slideDown('fast',function(){$('body').one('click',function(){slider.slideUp('fast');self.activecell=0;});});});setTimeout(function(){$('a.event-item').mouseenter(function(){$('a[data-event-id="'+$(this).data('event-id')+'"]').closest('.cal-cell1').addClass('day-highlight dh-'+$(this).data('event-class'));});$('a.event-item').mouseleave(function(){$('div.cal-cell1').removeClass('day-highlight dh-'+$(this).data('event-class'));});self._update_modal();},400);} function getEasterDate(year,offsetDays){var a=year%19;var b=Math.floor(year/100);var c=year%100;var d=Math.floor(b/4);var e=b%4;var f=Math.floor((b+8)/25);var g=Math.floor((b-f+1)/3);var h=(19*a+b-d-g+15)%30;var i=Math.floor(c/4);var k=c%4;var l=(32+2*e+2*i-h-k)%7;var m=Math.floor((a+11*h+22*l)/451);var n0=(h+l+7*m+114) var n=Math.floor(n0/31)-1;var p=n0%31+1;return new Date(year,n,p+(offsetDays?offsetDays:0),0,0,0);} $.fn.calendar=function(params){return new Calendar(params,this);}}(jQuery));