forked from kylestetz/CLNDR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclndr.min.js
2 lines (2 loc) · 25.1 KB
/
clndr.min.js
1
2
/*! clndr.min.js v1.2.15 2015-07-21 */
!function(a){"function"==typeof define&&define.amd?define(["jquery","moment"],a):"object"==typeof exports?a(require("jquery"),require("moment")):a(jQuery,moment)}(function(a,b){function c(c,d){if(this.element=c,this.options=a.extend(!0,{},f,d),this.options.events.length&&(this.options.multiDayEvents?this.options.events=this.addMultiDayMomentObjectsToEvents(this.options.events):this.options.events=this.addMomentObjectToEvents(this.options.events)),this.options.lengthOfTime.months||this.options.lengthOfTime.days?this.options.lengthOfTime.months?(this.options.lengthOfTime.days=null,this.options.lengthOfTime.startDate?this.intervalStart=b(this.options.lengthOfTime.startDate).startOf("month"):this.options.startWithMonth?this.intervalStart=b(this.options.startWithMonth).startOf("month"):this.intervalStart=b().startOf("month"),this.intervalEnd=b(this.intervalStart).add(this.options.lengthOfTime.months,"months").subtract(1,"days"),this.month=this.intervalStart.clone()):this.options.lengthOfTime.days&&(this.options.lengthOfTime.startDate?this.intervalStart=b(this.options.lengthOfTime.startDate).startOf("day"):this.intervalStart=b().weekday(0).startOf("day"),this.intervalEnd=b(this.intervalStart).add(this.options.lengthOfTime.days-1,"days").endOf("day"),this.month=this.intervalStart.clone()):(this.month=b().startOf("month"),this.intervalStart=b(this.month),this.intervalEnd=b(this.month).endOf("month")),this.options.startWithMonth&&(this.month=b(this.options.startWithMonth).startOf("month"),this.intervalStart=b(this.month),this.intervalEnd=b(this.month).endOf("month")),this.options.constraints){if(this.options.constraints.startDate){var g=b(this.options.constraints.startDate);this.intervalStart.isBefore(g,"month")&&(this.intervalStart.set("month",g.month()).set("year",g.year()),this.month.set("month",g.month()).set("year",g.year()))}if(this.options.constraints.endDate){var h=b(this.options.constraints.endDate);this.intervalEnd.isAfter(h,"month")&&(this.intervalEnd.set("month",h.month()).set("year",h.year()),this.month.set("month",h.month()).set("year",h.year()))}}this._defaults=f,this._name=e,this.init()}var d="<div class='clndr-controls'><div class='clndr-control-button'><span class='clndr-previous-button'>previous</span></div><div class='month'><%= month %> <%= year %></div><div class='clndr-control-button rightalign'><span class='clndr-next-button'>next</span></div></div><table class='clndr-table' border='0' cellspacing='0' cellpadding='0'><thead><tr class='header-days'><% for(var i = 0; i < daysOfTheWeek.length; i++) { %><td class='header-day'><%= daysOfTheWeek[i] %></td><% } %></tr></thead><tbody><% for(var i = 0; i < numberOfRows; i++){ %><tr><% for(var j = 0; j < 7; j++){ %><% var d = j + i * 7; %><td class='<%= days[d].classes %>'><div class='day-contents'><%= days[d].day %></div></td><% } %></tr><% } %></tbody></table>",e="clndr",f={template:d,weekOffset:0,startWithMonth:null,clickEvents:{click:null,nextMonth:null,previousMonth:null,nextYear:null,previousYear:null,today:null,onMonthChange:null,onYearChange:null},targets:{nextButton:"clndr-next-button",previousButton:"clndr-previous-button",nextYearButton:"clndr-next-year-button",previousYearButton:"clndr-previous-year-button",todayButton:"clndr-today-button",day:"day",empty:"empty"},classes:{today:"today",event:"event",past:"past",lastMonth:"last-month",nextMonth:"next-month",adjacentMonth:"adjacent-month",inactive:"inactive",selected:"selected"},events:[],extras:null,dateParameter:"date",multiDayEvents:null,doneRendering:null,render:null,daysOfTheWeek:null,showAdjacentMonths:!0,adjacentDaysChangeMonth:!1,ready:null,constraints:null,forceSixRows:null,trackSelectedDate:!1,selectedDate:null,lengthOfTime:{months:null,days:null,interval:1}};c.prototype.init=function(){if(this.daysOfTheWeek=this.options.daysOfTheWeek||[],!this.options.daysOfTheWeek){this.daysOfTheWeek=[];for(var c=0;7>c;c++)this.daysOfTheWeek.push(b().weekday(c).format("dd").charAt(0))}if(this.options.weekOffset&&(this.daysOfTheWeek=this.shiftWeekdayLabels(this.options.weekOffset)),!a.isFunction(this.options.render)){if(this.options.render=null,"undefined"==typeof _)throw new Error("Underscore was not found. Please include underscore.js OR provide a custom render function.");this.compiledClndrTemplate=_.template(this.options.template)}a(this.element).html("<div class='clndr'></div>"),this.calendarContainer=a(".clndr",this.element),this.bindEvents(),this.render(),this.options.ready&&this.options.ready.apply(this,[])},c.prototype.shiftWeekdayLabels=function(a){for(var b=this.daysOfTheWeek,c=0;a>c;c++)b.push(b.shift());return b},c.prototype.createDaysObject=function(c,d){var e=[],f=c.clone();d.diff(c,"days");if(this._currentIntervalStart=c.clone(),this.eventsLastMonth=[],this.eventsThisInterval=[],this.eventsNextMonth=[],this.options.events.length&&(this.eventsThisInterval=a(this.options.events).filter(function(){return this._clndrEndDateObject.isBefore(c)||this._clndrStartDateObject.isAfter(d)?!1:!0}).toArray(),this.options.showAdjacentMonths)){var g=c.clone().subtract(1,"months").startOf("month"),h=g.clone().endOf("month"),i=d.clone().add(1,"months").startOf("month"),j=i.clone().endOf("month");this.eventsLastMonth=a(this.options.events).filter(function(){return this._clndrEndDateObject.isBefore(g)||this._clndrStartDateObject.isAfter(h)?!1:!0}).toArray(),this.eventsNextMonth=a(this.options.events).filter(function(){return this._clndrEndDateObject.isBefore(i)||this._clndrStartDateObject.isAfter(j)?!1:!0}).toArray()}if(!this.options.lengthOfTime.days){var k=f.weekday()-this.options.weekOffset;if(0>k&&(k+=7),this.options.showAdjacentMonths)for(var l=0;k>l;l++){var m=b([c.year(),c.month(),l-k+1]);e.push(this.createDayObject(m,this.eventsLastMonth))}else for(var l=0;k>l;l++)e.push(this.calendarDay({classes:this.options.targets.empty+" "+this.options.classes.lastMonth}))}for(var n=c.clone();n.isBefore(d)||n.isSame(d,"day");)e.push(this.createDayObject(n.clone(),this.eventsThisInterval)),n.add(1,"days");if(!this.options.lengthOfTime.days)for(;e.length%7!==0;)this.options.showAdjacentMonths?e.push(this.createDayObject(n.clone(),this.eventsNextMonth)):e.push(this.calendarDay({classes:this.options.targets.empty+" "+this.options.classes.nextMonth})),n.add(1,"days");if(this.options.forceSixRows&&42!==e.length)for(;e.length<42;)this.options.showAdjacentMonths?(e.push(this.createDayObject(n.clone(),this.eventsNextMonth)),n.add(1,"days")):e.push(this.calendarDay({classes:this.options.targets.empty+" "+this.options.classes.nextMonth}));return e},c.prototype.createDayObject=function(a,c){var d=[],e=b();!a.isValid()&&a.hasOwnProperty("_d")&&void 0!=a._d&&(a=b(a._d));var f=0,g=c.length;for(f;g>f;f++){var h=c[f]._clndrStartDateObject,i=c[f]._clndrEndDateObject;(a.isSame(h,"day")||a.isAfter(h,"day"))&&(a.isSame(i,"day")||a.isBefore(i,"day"))&&d.push(c[f])}var j={isInactive:!1,isAdjacentMonth:!1,isToday:!1},k="";return e.format("YYYY-MM-DD")==a.format("YYYY-MM-DD")&&(k+=" "+this.options.classes.today,j.isToday=!0),a.isBefore(e,"day")&&(k+=" "+this.options.classes.past),d.length&&(k+=" "+this.options.classes.event),this.options.lengthOfTime.days||(this._currentIntervalStart.month()>a.month()?(k+=" "+this.options.classes.adjacentMonth,j.isAdjacentMonth=!0,k+=this._currentIntervalStart.year()===a.year()?" "+this.options.classes.lastMonth:" "+this.options.classes.nextMonth):this._currentIntervalStart.month()<a.month()&&(k+=" "+this.options.classes.adjacentMonth,j.isAdjacentMonth=!0,k+=this._currentIntervalStart.year()===a.year()?" "+this.options.classes.nextMonth:" "+this.options.classes.lastMonth)),this.options.constraints&&(this.options.constraints.startDate&&a.isBefore(b(this.options.constraints.startDate))&&(k+=" "+this.options.classes.inactive,j.isInactive=!0),this.options.constraints.endDate&&a.isAfter(b(this.options.constraints.endDate))&&(k+=" "+this.options.classes.inactive,j.isInactive=!0)),!a.isValid()&&a.hasOwnProperty("_d")&&void 0!=a._d&&(a=b(a._d)),this.options.selectedDate&&a.isSame(b(this.options.selectedDate),"day")&&(k+=" "+this.options.classes.selected),k+=" calendar-day-"+a.format("YYYY-MM-DD"),k+=" calendar-dow-"+a.weekday(),this.calendarDay({day:a.date(),classes:this.options.targets.day+k,events:d,date:a,properties:j})},c.prototype.render=function(){this.calendarContainer.children().remove();var a={};if(this.options.lengthOfTime.days){var c=this.createDaysObject(this.intervalStart.clone(),this.intervalEnd.clone());a={daysOfTheWeek:this.daysOfTheWeek,numberOfRows:Math.ceil(c.length/7),months:[],days:c,month:null,year:null,intervalStart:this.intervalStart.clone(),intervalEnd:this.intervalEnd.clone(),eventsThisInterval:this.eventsThisInterval,eventsLastMonth:[],eventsNextMonth:[],extras:this.options.extras}}else if(this.options.lengthOfTime.months){var d=[],e=[];for(i=0;i<this.options.lengthOfTime.months;i++){var f=this.intervalStart.clone().add(i,"months"),g=f.clone().endOf("month"),c=this.createDaysObject(f,g);e.push(this.eventsThisInterval),d.push({month:f,days:c})}a={daysOfTheWeek:this.daysOfTheWeek,numberOfRows:_.reduce(d,function(a,b){return a+Math.ceil(b.days.length/7)},0),months:d,days:[],month:null,year:null,intervalStart:this.intervalStart,intervalEnd:this.intervalEnd,eventsThisInterval:e,eventsLastMonth:this.eventsLastMonth,eventsNextMonth:this.eventsNextMonth,extras:this.options.extras}}else var c=this.createDaysObject(this.month.clone().startOf("month"),this.month.clone().endOf("month")),a=(this.month,{daysOfTheWeek:this.daysOfTheWeek,numberOfRows:Math.ceil(c.length/7),months:[],days:c,month:this.month.format("MMMM"),year:this.month.year(),eventsThisMonth:this.eventsThisInterval,eventsLastMonth:this.eventsLastMonth,eventsNextMonth:this.eventsNextMonth,extras:this.options.extras});if(this.options.render?this.calendarContainer.html(this.options.render.apply(this,[a])):this.calendarContainer.html(this.compiledClndrTemplate(a)),this.options.constraints){for(var h in this.options.targets)h!=this.options.targets.day&&this.element.find("."+this.options.targets[h]).toggleClass(this.options.classes.inactive,!1);var j=null,k=null;this.options.constraints.startDate&&(j=b(this.options.constraints.startDate)),this.options.constraints.endDate&&(k=b(this.options.constraints.endDate)),j&&(j.isAfter(this.intervalStart)||j.isSame(this.intervalStart,"day"))&&this.element.find("."+this.options.targets.previousButton).toggleClass(this.options.classes.inactive,!0),k&&(k.isBefore(this.intervalEnd)||k.isSame(this.intervalEnd,"day"))&&this.element.find("."+this.options.targets.nextButton).toggleClass(this.options.classes.inactive,!0),j&&j.isAfter(this.intervalStart.clone().subtract(1,"years"))&&this.element.find("."+this.options.targets.previousYearButton).toggleClass(this.options.classes.inactive,!0),k&&k.isBefore(this.intervalEnd.clone().add(1,"years"))&&this.element.find("."+this.options.targets.nextYearButton).toggleClass(this.options.classes.inactive,!0),(j&&j.isAfter(b(),"month")||k&&k.isBefore(b(),"month"))&&this.element.find("."+this.options.targets.today).toggleClass(this.options.classes.inactive,!0)}this.options.doneRendering&&this.options.doneRendering.apply(this,[])},c.prototype.bindEvents=function(){var b=a(this.element),c=this,d="click";c.options.useTouchEvents===!0&&(d="touchstart"),b.on(d+".clndr","."+this.options.targets.day,function(b){if(c.options.clickEvents.click){var d=c.buildTargetObject(b.currentTarget,!0);c.options.clickEvents.click.apply(c,[d])}c.options.adjacentDaysChangeMonth&&(a(b.currentTarget).is("."+c.options.classes.lastMonth)?c.backActionWithContext(c):a(b.currentTarget).is("."+c.options.classes.nextMonth)&&c.forwardActionWithContext(c)),c.options.trackSelectedDate&&(c.options.selectedDate=c.getTargetDateString(b.currentTarget),a(b.currentTarget).siblings().removeClass(c.options.classes.selected).end().addClass(c.options.classes.selected))}),b.on(d+".clndr","."+this.options.targets.empty,function(b){if(c.options.clickEvents.click){var d=c.buildTargetObject(b.currentTarget,!1);c.options.clickEvents.click.apply(c,[d])}c.options.adjacentDaysChangeMonth&&(a(b.currentTarget).is("."+c.options.classes.lastMonth)?c.backActionWithContext(c):a(b.currentTarget).is("."+c.options.classes.nextMonth)&&c.forwardActionWithContext(c))}),b.on(d+".clndr","."+this.options.targets.previousButton,{context:this},this.backAction).on(d+".clndr","."+this.options.targets.nextButton,{context:this},this.forwardAction).on(d+".clndr","."+this.options.targets.todayButton,{context:this},this.todayAction).on(d+".clndr","."+this.options.targets.nextYearButton,{context:this},this.nextYearAction).on(d+".clndr","."+this.options.targets.previousYearButton,{context:this},this.previousYearAction)},c.prototype.buildTargetObject=function(c,d){var e={element:c,events:[],date:null};if(d){var f=this.getTargetDateString(c);e.date=f?b(f):null,this.options.events&&(this.options.multiDayEvents?e.events=a.makeArray(a(this.options.events).filter(function(){return(e.date.isSame(this._clndrStartDateObject,"day")||e.date.isAfter(this._clndrStartDateObject,"day"))&&(e.date.isSame(this._clndrEndDateObject,"day")||e.date.isBefore(this._clndrEndDateObject,"day"))})):e.events=a.makeArray(a(this.options.events).filter(function(){return this._clndrStartDateObject.format("YYYY-MM-DD")==f})))}return e},c.prototype.getTargetDateString=function(a){var b=a.className.indexOf("calendar-day-");return-1!==b?a.className.substring(b+13,b+23):null},c.prototype.forwardAction=function(a){var b=a.data.context;b.forwardActionWithContext(b)},c.prototype.backAction=function(a){var b=a.data.context;b.backActionWithContext(b)},c.prototype.backActionWithContext=function(a){if(!a.element.find("."+a.options.targets.previousButton).hasClass("inactive")){var c=null;a.options.lengthOfTime.days?(a.intervalStart.subtract(a.options.lengthOfTime.interval,"days").startOf("day"),a.intervalEnd=a.intervalStart.clone().add(a.options.lengthOfTime.days-1,"days").endOf("day"),a.month=a.intervalStart.clone()):(a.intervalStart.subtract(a.options.lengthOfTime.interval,"months").startOf("month"),a.intervalEnd=a.intervalStart.clone().add(a.options.lengthOfTime.months||a.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month"),a.options.lengthOfTime.months||(c=!a.month.isSame(b(a.month).subtract(1,"months"),"year")),a.month=a.intervalStart.clone()),a.render(),a.options.lengthOfTime.days||a.options.lengthOfTime.months?(a.options.clickEvents.previousInterval&&a.options.clickEvents.previousInterval.apply(a,[b(a.intervalStart),b(a.intervalEnd)]),a.options.clickEvents.onIntervalChange&&a.options.clickEvents.onIntervalChange.apply(a,[b(a.intervalStart),b(a.intervalEnd)])):(a.options.clickEvents.previousMonth&&a.options.clickEvents.previousMonth.apply(a,[b(a.month)]),a.options.clickEvents.onMonthChange&&a.options.clickEvents.onMonthChange.apply(a,[b(a.month)]),c&&a.options.clickEvents.onYearChange&&a.options.clickEvents.onYearChange.apply(a,[b(a.month)]))}},c.prototype.forwardActionWithContext=function(a){if(!a.element.find("."+a.options.targets.nextButton).hasClass("inactive")){var c=null;a.options.lengthOfTime.days?(a.intervalStart.add(a.options.lengthOfTime.interval,"days").startOf("day"),a.intervalEnd=a.intervalStart.clone().add(a.options.lengthOfTime.days-1,"days").endOf("day"),a.month=a.intervalStart.clone()):(a.intervalStart.add(a.options.lengthOfTime.interval,"months").startOf("month"),a.intervalEnd=a.intervalStart.clone().add(a.options.lengthOfTime.months||a.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month"),a.options.lengthOfTime.months||(c=!a.month.isSame(b(a.month).add(1,"months"),"year")),a.month=a.intervalStart.clone()),a.render(),a.options.lengthOfTime.days||a.options.lengthOfTime.months?(a.options.clickEvents.nextInterval&&a.options.clickEvents.nextInterval.apply(a,[b(a.intervalStart),b(a.intervalEnd)]),a.options.clickEvents.onIntervalChange&&a.options.clickEvents.onIntervalChange.apply(a,[b(a.intervalStart),b(a.intervalEnd)])):(a.options.clickEvents.previousMonth&&a.options.clickEvents.previousMonth.apply(a,[b(a.month)]),a.options.clickEvents.onMonthChange&&a.options.clickEvents.onMonthChange.apply(a,[b(a.month)]),c&&a.options.clickEvents.onYearChange&&a.options.clickEvents.onYearChange.apply(a,[b(a.month)]))}},c.prototype.todayAction=function(a){var c=a.data.context,d=!c.month.isSame(b(),"month"),e=!c.month.isSame(b(),"year");c.month=b().startOf("month"),c.options.lengthOfTime.days?(c.options.lengthOfTime.startDate?c.intervalStart=b().weekday(c.options.lengthOfTime.startDate.weekday()).startOf("day"):c.intervalStart=b().weekday(0).startOf("day"),c.intervalEnd=c.intervalStart.clone().add(c.options.lengthOfTime.days-1,"days").endOf("day")):c.options.lengthOfTime.months?(c.intervalStart=b().startOf("month"),c.intervalEnd=c.intervalStart.clone().add(c.options.lengthOfTime.months||c.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month")):d&&(c.intervalStart=b().startOf("month"),c.render(),c.options.clickEvents.today&&c.options.clickEvents.today.apply(c,[b(c.month)]),c.options.clickEvents.onMonthChange&&c.options.clickEvents.onMonthChange.apply(c,[b(c.month)]),e&&c.options.clickEvents.onYearChange&&c.options.clickEvents.onYearChange.apply(c,[b(c.month)])),(c.options.lengthOfTime.days||c.options.lengthOfTime.months)&&(c.render(),c.options.clickEvents.today&&c.options.clickEvents.today.apply(c,[b(c.month)]),c.options.clickEvents.onIntervalChange&&c.options.clickEvents.onIntervalChange.apply(c,[b(c.intervalStart),b(c.intervalEnd)]))},c.prototype.nextYearAction=function(a){var c=a.data.context;c.element.find("."+c.options.targets.nextYearButton).hasClass("inactive")||(c.month.add(1,"years"),c.intervalStart.add(1,"years"),c.intervalEnd.add(1,"years"),c.render(),c.options.clickEvents.nextYear&&c.options.clickEvents.nextYear.apply(c,[b(c.month)]),c.options.lengthOfTime.days||c.options.lengthOfTime.months?c.options.clickEvents.onIntervalChange&&c.options.clickEvents.onIntervalChange.apply(c,[b(c.intervalStart),b(c.intervalEnd)]):(c.options.clickEvents.onMonthChange&&c.options.clickEvents.onMonthChange.apply(c,[b(c.month)]),c.options.clickEvents.onYearChange&&c.options.clickEvents.onYearChange.apply(c,[b(c.month)])))},c.prototype.previousYearAction=function(a){var c=a.data.context;console.log(c.element.find("."+c.options.targets.previousYear)),c.element.find("."+c.options.targets.previousYearButton).hasClass("inactive")||(c.month.subtract(1,"years"),c.intervalStart.subtract(1,"years"),c.intervalEnd.subtract(1,"years"),c.render(),c.options.clickEvents.previousYear&&c.options.clickEvents.previousYear.apply(c,[b(c.month)]),c.options.lengthOfTime.days||c.options.lengthOfTime.months?c.options.clickEvents.onIntervalChange&&c.options.clickEvents.onIntervalChange.apply(c,[b(c.intervalStart),b(c.intervalEnd)]):(c.options.clickEvents.onMonthChange&&c.options.clickEvents.onMonthChange.apply(c,[b(c.month)]),c.options.clickEvents.onYearChange&&c.options.clickEvents.onYearChange.apply(c,[b(c.month)])))},c.prototype.forward=function(a){return this.options.lengthOfTime.days?(this.intervalStart.add(this.options.lengthOfTime.interval,"days").startOf("day"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.days-1,"days").endOf("day"),this.month=this.intervalStart.clone()):(this.intervalStart.add(this.options.lengthOfTime.interval,"months").startOf("month"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.months||this.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month"),this.month=this.intervalStart.clone()),this.render(),a&&a.withCallbacks&&(this.options.lengthOfTime.days||this.options.lengthOfTime.months?this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)]):(this.options.clickEvents.onMonthChange&&this.options.clickEvents.onMonthChange.apply(this,[b(this.month)]),0===this.month.month()&&this.options.clickEvents.onYearChange&&this.options.clickEvents.onYearChange.apply(this,[b(this.month)]))),this},c.prototype.back=function(a){return this.options.lengthOfTime.days?(this.intervalStart.subtract(this.options.lengthOfTime.interval,"days").startOf("day"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.days-1,"days").endOf("day"),this.month=this.intervalStart.clone()):(this.intervalStart.subtract(this.options.lengthOfTime.interval,"months").startOf("month"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.months||this.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month"),this.month=this.intervalStart.clone()),this.render(),a&&a.withCallbacks&&(this.options.lengthOfTime.days||this.options.lengthOfTime.months?this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)]):(this.options.clickEvents.onMonthChange&&this.options.clickEvents.onMonthChange.apply(this,[b(this.month)]),11===this.month.month()&&this.options.clickEvents.onYearChange&&this.options.clickEvents.onYearChange.apply(this,[b(this.month)]))),this},c.prototype.next=function(a){return this.forward(a),this},c.prototype.previous=function(a){return this.back(a),this},c.prototype.setMonth=function(a,c){return this.options.lengthOfTime.days||this.options.lengthOfTime.months?console.log("You are using a custom date interval; use Clndr.setIntervalStart(startDate) instead."):(this.month.month(a),this.intervalStart=this.month.clone().startOf("month"),this.intervalEnd=this.intervalStart.clone().endOf("month"),this.render(),c&&c.withCallbacks&&this.options.clickEvents.onMonthChange&&this.options.clickEvents.onMonthChange.apply(this,[b(this.month)])),this},c.prototype.setIntervalStart=function(a,c){return this.options.lengthOfTime.days?(this.intervalStart=b(a).startOf("day"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.days-1,"days").endOf("day")):this.options.lengthOfTime.months&&(this.intervalStart=b(a).startOf("month"),this.intervalEnd=this.intervalStart.clone().add(this.options.lengthOfTime.months||this.options.lengthOfTime.interval,"months").subtract(1,"days").endOf("month"),this.month=this.intervalStart.clone()),this.options.lengthOfTime.days||this.options.lengthOfTime.months?(this.render(),c&&c.withCallbacks&&this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)])):console.log("You are using a custom date interval; use Clndr.setIntervalStart(startDate) instead."),this},c.prototype.nextYear=function(a){return this.month.add(1,"year"),this.intervalStart.add(1,"year"),this.intervalEnd.add(1,"year"),this.render(),a&&a.withCallbacks&&(this.options.clickEvents.onYearChange&&this.options.clickEvents.onYearChange.apply(this,[b(this.month)]),this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)])),this},c.prototype.previousYear=function(a){return this.month.subtract(1,"year"),this.intervalStart.subtract(1,"year"),this.intervalEnd.subtract(1,"year"),this.render(),a&&a.withCallbacks&&(this.options.clickEvents.onYearChange&&this.options.clickEvents.onYearChange.apply(this,[b(this.month)]),this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)])),this},c.prototype.setYear=function(a,c){return this.month.year(a),this.intervalStart.year(a),this.intervalEnd.year(a),this.render(),c&&c.withCallbacks&&(this.options.clickEvents.onYearChange&&this.options.clickEvents.onYearChange.apply(this,[b(this.month)]),this.options.clickEvents.onIntervalChange&&this.options.clickEvents.onIntervalChange.apply(this,[b(this.intervalStart),b(this.intervalEnd)])),this},c.prototype.setEvents=function(a){return this.options.multiDayEvents?this.options.events=this.addMultiDayMomentObjectsToEvents(a):this.options.events=this.addMomentObjectToEvents(a),this.render(),this},c.prototype.addEvents=function(b){return this.options.multiDayEvents?this.options.events=a.merge(this.options.events,this.addMultiDayMomentObjectsToEvents(b)):this.options.events=a.merge(this.options.events,this.addMomentObjectToEvents(b)),this.render(),this},c.prototype.removeEvents=function(a){for(var b=this.options.events.length-1;b>=0;b--)1==a(this.options.events[b])&&this.options.events.splice(b,1);return this.render(),this},c.prototype.addMomentObjectToEvents=function(a){var c=this,d=0,e=a.length;for(d;e>d;d++)a[d]._clndrStartDateObject=b(a[d][c.options.dateParameter]),a[d]._clndrEndDateObject=b(a[d][c.options.dateParameter]);return a},c.prototype.addMultiDayMomentObjectsToEvents=function(a){var c=this,d=0,e=a.length;for(d;e>d;d++)a[d][c.options.multiDayEvents.endDate]||a[d][c.options.multiDayEvents.startDate]?(a[d]._clndrEndDateObject=b(a[d][c.options.multiDayEvents.endDate]||a[d][c.options.multiDayEvents.startDate]),a[d]._clndrStartDateObject=b(a[d][c.options.multiDayEvents.startDate]||a[d][c.options.multiDayEvents.endDate])):(a[d]._clndrEndDateObject=b(a[d][c.options.multiDayEvents.singleDay]),a[d]._clndrStartDateObject=b(a[d][c.options.multiDayEvents.singleDay]));return a},c.prototype.calendarDay=function(b){var c={day:"",classes:this.options.targets.empty,events:[],date:null};return a.extend({},c,b)},a.fn.clndr=function(a){if(1===this.length){if(!this.data("plugin_clndr")){var b=new c(this,a);return this.data("plugin_clndr",b),b}}else if(this.length>1)throw new Error("CLNDR does not support multiple elements yet. Make sure your clndr selector returns only one element.")}});