UNPKG

arrobefr-jquery-calendar

Version:

A responsive jquery calendar scheduler built with bootstrap and moment.js

6 lines 37.6 kB
/* * @class Calendar ~jquery-calendar plugin~ (https://github.com/ArrobeFr/jquery-calendar) * @author Developped by Arrobe (https://www.arrobe.fr) * @license Licensed under MIT (https://github.com/ArrobeFr/jquery-calendar/blob/master/LICENSE) */ jQuery(document).ready(function(f){function n(e,t){if("function"==typeof moment){var n=["#C62828","#AD1457","#6A1B9A","#4527A0","#283593","#1565C0","#0277BD","#00838F","#00695C","#2E7D32","#558B2F","#9E9D24","#F9A825","#FF8F00","#EF6C00","#D84315","#4E342E","#424242","#37474F","#212121"],a=["#EF9A9A","#F48FB1","#CE93D8","#B39DDB","#9FA8DA","#90CAF9","#81D4FA","#80DEEA","#80CBC4","#A5D6A7","#C5E1A5","#E6EE9C","#FFF59D","#FFE082","#FFCC80","#FFAB91","#BCAAA4","#EEEEEE","#B0BEC5"];return this.conf={locale:t.locale?t.locale:"fr",view:"week",enableKeyboard:!t.enableKeyboard||t.enableKeyboard,defaultView:{largeScreen:t.defaultView&&t.defaultView.largeScreen?t.defaultView.largeScreen:"week",smallScreen:t.defaultView&&t.defaultView.smallScreen?t.defaultView.smallScreen:"day",smallScreenThreshold:t.defaultView&&t.defaultView.smallScreenThreshold?t.defaultView.smallScreenThreshold:1e3},weekday:{timeline:{fromHour:t.weekday&&t.weekday.timeline&&t.weekday.timeline.fromHour?t.weekday.timeline.fromHour:7,toHour:t.weekday&&t.weekday.timeline&&t.weekday.timeline.toHour?t.weekday.timeline.toHour:20,intervalMinutes:t.weekday&&t.weekday.timeline&&t.weekday.timeline.intervalMinutes?t.weekday.timeline.intervalMinutes:60,format:t.weekday&&t.weekday.timeline&&t.weekday.timeline.format?t.weekday.timeline.format:"HH:mm",heightPx:t.weekday&&t.weekday.timeline&&t.weekday.timeline.heightPx?t.weekday.timeline.heightPx:50,autoResize:!t.weekday||(!t.weekday.timeline||(void 0===t.weekday.timeline.autoResize||t.weekday.timeline.autoResize))},dayline:{weekdays:t.weekday&&t.weekday.dayline&&t.weekday.dayline.weekdays?t.weekday.dayline.weekdays:[0,1,2,3,4,5,6],format:t.weekday&&t.weekday.dayline&&t.weekday.dayline.format?t.weekday.dayline.format:"dddd DD/MM",heightPx:t.weekday&&t.weekday.dayline&&t.weekday.dayline.heightPx&&t.weekday.dayline.heightPx&&31<t.weekday.dayline.heightPx?t.weekday.dayline.heightPx:31,month:{format:t.weekday&&t.weekday.dayline&&t.weekday.dayline.month&&t.weekday.dayline.month.format?t.weekday.dayline.month.format:"MMMM YYYY",heightPx:t.weekday&&t.weekday.dayline&&t.weekday.dayline.month&&t.weekday.dayline.month.heightPx?t.weekday.dayline.month.heightPx:30,weekFormat:t.weekday&&t.weekday.dayline&&t.weekday.dayline.month&&t.weekday.dayline.month.weekFormat?t.weekday.dayline.month.weekFormat:"w"}}},month:{format:t.month&&t.month.format?t.month.format:"MMMM YYYY",heightPx:t.month&&t.month.heightPx&&31<t.month.heightPx?t.month.heightPx:31,weekline:{format:t.month&&t.month.weekline&&t.month.weekline.format?t.month.weekline.format:"w",heightPx:t.month&&t.month.weekline&&t.month.weekline.heightPx?t.month.weekline.heightPx:80},dayheader:{weekdays:t.month&&t.month.dayheader&&t.month.dayheader.weekdays?t.month.dayheader.weekdays:[0,1,2,3,4,5,6],format:t.month&&t.month.dayheader&&t.month.dayheader.format?t.month.dayheader.format:"dddd",heightPx:t.month&&t.month.dayheader&&t.month.dayheader.heightPx?t.month.dayheader.heightPx:30},day:{format:t.month&&t.month.day&&t.month.day.format?t.month.day.format:"DD/MM"}},unixTimestamp:t.unixTimestamp?t.unixTimestamp:moment().format("X"),event:{hover:{delay:t.event&&t.event.hover&&t.event.hover.delay?t.event.hover.delay:500}},colors:{events:t.colors&&t.colors.events?t.colors.events:n,daynotes:t.colors&&t.colors.daynotes?t.colors.daynotes:a,random:!t.colors||(!t.colors.random||t.colors.random)},categories:{enable:!t.categories||(void 0===t.categories.enable||t.categories.enable),hover:{delay:t.categories&&t.categories.hover&&t.categories.hover.delay?t.categories.hover.delay:500}},now:{enable:!!t.now&&(void 0!==t.now.enable&&t.now.enable),refresh:!!t.now&&(void 0!==t.now.refresh&&t.now.refresh),heightPx:t.now&&t.now.heightPx?t.now.heightPx:1,style:t.now&&t.now.style?t.now.style:"solid",color:t.now&&t.now.color?t.now.color:"#03A9F4"}},moment.locale(this.conf.locale),this.setEventColors(this.conf.colors.events),this.setDaynoteColors(this.conf.colors.daynotes),this.eventCategoryColor=[],this.daynoteCategoryColor=[],this.userEventCategoryColor=[],this.userDaynoteCategoryColor=[],this.setEvents(t.events?t.events:[]),this.setDaynotes(t.daynotes?t.daynotes:[]),"mobile"==this.mobileQuery()?this.setView(this.conf.defaultView.smallScreen):this.setView(this.conf.defaultView.largeScreen),this.element=e,this.initTime=!1,this}console.error("Calendar require Moment.js !")}var t,o;n.prototype.init=function(){var e=Date.now();return this.element.addClass("loading"),this.calculateCurrentInterval(),f(this.element).trigger("Calendar.init",[this,this.getPrevViewInterval(),this.getViewInterval(),this.getNextViewInterval()]),f(this.element).html(""),f(this.element).hasClass("calendar")||f(this.element).addClass("calendar"),"day"!=this.getView()&&"week"!=this.getView()||this.conf.weekday.timeline.autoResize&&this.resizeTimeline(),this.drawCategories(),"day"!=this.getView()&&"week"!=this.getView()||(this.weekDrawTime(),this.weekDrawDays(),this.weekDrawDaynotes(),this.weekDrawEvents()),"month"==this.getView()&&(this.monthDrawWeek(),this.monthDrawWeekNumbers(),this.monthDrawWeekDays(),this.monthDrawDaynotes(),this.monthDrawEvents()),this.drawModal(),this.drawNow(),this.positionEvents(),this.hoverEventOrDaynote(),this.clickEventOrDaynote(),this.addBtnLeftRight(),this.addSwipe(),this.clickSwitchView(),this.keyboardSwitchView(),this.defaultEvents(),this.element.removeClass("loading"),this.initTime=Date.now()-e+"ms",this},n.prototype.defaultEvents=function(){if(null==this.binded){var e=function(e,t,n){e.isDefaultPrevented()||(parseInt(n.css("top"))>=n.closest("ul").height()/2-t.conf.weekday.timeline.heightPx?(heightPx=parseInt(n.css("top"))+parseInt(n.css("height")),n.css("z-index",10).animate({height:heightPx,top:0,width:"100%",left:0},50)):(heightPx=n.closest("ul").height()-parseInt(n.css("top")),n.css("z-index",10).animate({height:heightPx,width:"100%",left:0},50)),n.find(".event-name").removeClass("hidden"),n.find(".event-content").removeClass("hidden"))};f(self.element).off("Calendar.event-mouseenter",e).on("Calendar.event-mouseenter",e),f(self.element).off("Calendar.daynote-mouseenter",e).on("Calendar.daynote-mouseenter",e);var t=function(e,t,n){e.isDefaultPrevented()||(n.css("z-index","auto").animate({height:parseFloat(n.attr("data-height"))+"px",top:parseFloat(n.attr("data-top")),width:parseFloat(n.attr("data-width"))+"%",left:parseFloat(n.attr("data-left"))+"%"},50),n.find(".event-content").addClass("hidden"))};f(self.element).off("Calendar.event-mouseleave",t).on("Calendar.event-mouseleave",t),f(self.element).off("Calendar.daynote-mouseleave",t).on("Calendar.daynote-mouseleave",t);var n=function(e,t,n,a){e.isDefaultPrevented()||(modal=f(t.element).find("#calendar-modal"),rgb=t.hexToRgb(n.attr("data-color")),modal.css("background","rgba("+rgb.r+", "+rgb.g+", "+rgb.b+", 0.5)"),modal.find(".modal-title").append(n.attr("data-title")+" "),modal.find(".modal-body").append(f("<h4>").append(f(this).closest(".calendar-events-day").find("span").html()).append(" ").append(f("<small>").text(n.find(".event-date").text()))),modal.find(".modal-body").append(n.find(".event-content").html()),modal.modal("show"),modal.on("hidden.bs.modal",function(e){f(e.target).find(".modal-title").html(""),f(e.target).find(".modal-body").html("")}))};f(self.element).off("Calendar.event-click",n).on("Calendar.event-click",n),f(self.element).off("Calendar.daynote-click",n).on("Calendar.daynote-click",n);var a=function(e,t,n){if(!e.isDefaultPrevented()){var a=t.element.find('.calendar-event[data-category="'+f(n).text()+'"]');"false"==f(n).attr("data-clicked")&&a.animate({opacity:0},200,function(){a.css("display","none"),f(n).css("background-color","#E0E0E0"),f(n).attr("data-clicked",!0)}),"true"==f(n).attr("data-clicked")&&(a.css("display","list-item"),f(n).css("background-color",f(n).attr("data-color")),a.animate({opacity:1},200,function(){f(n).attr("data-clicked",!1)}))}};f(self.element).off("Calendar.category-event-click",a).on("Calendar.category-event-click",a),f(self.element).off("Calendar.category-daynote-click",a).on("Calendar.category-daynote-click",a);var o=function(e,t,n){e.isDefaultPrevented()||t.element.find(".calendar-event").each(function(e,t){f(t).attr("data-category")!=n.text()&&f(t).css("opacity",.2)})};f(self.element).off("Calendar.category-event-mouseenter",o).on("Calendar.category-event-mouseenter",o),f(self.element).off("Calendar.category-daynote-mouseenter",o).on("Calendar.category-daynote-mouseenter",o);var i=function(e,t,n){e.isDefaultPrevented()||t.element.find(".calendar-event").each(function(e,t){f(t).css("opacity",1)})};f(self.element).off("Calendar.category-event-mouseleave",i).on("Calendar.category-event-mouseleave",i),f(self.element).off("Calendar.category-daynote-mouseleave",i).on("Calendar.category-daynote-mouseleave",i),this.binded=!0}},n.prototype.weekDrawTime=function(){f(this.element).append(f("<div>",{class:"calendar-timeline"})),f(this.element).find("div.calendar-timeline").css("padding-top",this.conf.weekday.dayline.heightPx+"px");var e=this.conf.weekday.dayline.month.heightPx;this.conf.categories.enable&&(e+=30),f(this.element).find("div.calendar-timeline").css("margin-top",e+"px"),f(this.element).find("div.calendar-timeline").append(f("<ul>")),ul=f(this.element).find("div.calendar-timeline").find("ul"),time=moment(moment()).startOf("Week"),time.add(this.conf.weekday.timeline.fromHour,"H");for(var t=(60*(this.conf.weekday.timeline.toHour+1)-60*this.conf.weekday.timeline.fromHour)/this.conf.weekday.timeline.intervalMinutes,n=0;n<t;)li=f("<li>"),li.append(f("<span>").text(time.format(this.conf.weekday.timeline.format))),li.height(this.conf.weekday.timeline.heightPx),ul.append(li),time.add(this.conf.weekday.timeline.intervalMinutes,"m"),n++},n.prototype.weekDrawDays=function(){f(this.element).append(f("<div>",{class:"calendar-events"}));var e=f("<div>",{class:"calendar-month"}).css("height",this.conf.weekday.dayline.month.heightPx+"px").css("text-align","center").css("padding-top",(this.conf.weekday.dayline.month.heightPx-20)/2+"px");"week"==this.getView()&&(e.text(this.miscUcfirstString(moment.unix(this.conf.unixTimestamp).format(this.conf.weekday.dayline.month.format))),e.addClass("weektomonth")),"day"==this.getView()&&(e.text(this.miscUcfirstString(moment.unix(this.conf.unixTimestamp).format(this.conf.weekday.dayline.month.weekFormat))),e.addClass("daytoweek")),f(this.element).find("div.calendar-events").append(e),f(this.element).find("div.calendar-events").append(f("<ul>")),ul=f(this.element).find("div.calendar-events").find("ul");for(var t=this.getViewDays(),n=0;n<t.length;n++)time=moment.unix(t[n]),li=f("<li>",{class:"calendar-events-day"}),li.css("width",100/t.length+"%"),(e=f("<div>",{class:"calendar-day-header"})).height(this.conf.weekday.dayline.heightPx),0==n&&"desktop"==this.mobileQuery()&&e.append(f("<button>",{class:"btn btn-sm btn-default btn-move-calendar"}).attr("data-direction","left").append(f("<i>",{class:"glyphicon glyphicon-arrow-left"}))),e.append(f("<span>").addClass("weektoday").css("width","100%").text(this.miscUcfirstString(time.format(this.conf.weekday.dayline.format)))),n==t.length-1&&"desktop"==this.mobileQuery()&&e.append(f("<button>",{class:"btn btn-sm btn-default btn-move-calendar"}).attr("data-direction","right").append(f("<i>",{class:"glyphicon glyphicon-arrow-right"}))),li.append(e),li.attr("data-time",time.startOf("day").format("X")),li.append(f("<ul>")),li.find("ul").height(60/this.conf.weekday.timeline.intervalMinutes*(this.conf.weekday.timeline.toHour-this.conf.weekday.timeline.fromHour)*this.conf.weekday.timeline.heightPx+60/this.conf.weekday.timeline.intervalMinutes*this.conf.weekday.timeline.heightPx),ul.append(li);var a=0;f(this.element).find(".calendar-day-header").each(function(){f(this).height()>a&&(a=f(this).height())}),f(this.element).find(".calendar-day-header").each(function(){f(this).height(a)})},n.prototype.monthDrawWeek=function(){f(this.element).append(f("<div>",{class:"calendar-events"}));var e=f("<div>",{class:"calendar-month"});e.css("height",this.conf.month.heightPx+"px"),"desktop"==this.mobileQuery()&&e.append(f("<button>",{class:"btn btn-sm btn-default btn-move-calendar"}).attr("data-direction","left").append(f("<i>",{class:"glyphicon glyphicon-arrow-left"}))),e.append(f("<span>").css("position","absolute").css("top",this.conf.month.heightPx/2+"px").css("right","50%").css("transform","translate(50%,-50%)").text(this.miscUcfirstString(moment.unix(this.conf.unixTimestamp).format(this.conf.month.format)))),"desktop"==this.mobileQuery()&&e.append(f("<button>",{class:"btn btn-sm btn-default btn-move-calendar"}).css("float","right").attr("data-direction","right").append(f("<i>",{class:"glyphicon glyphicon-arrow-right"}))),f(this.element).find("div.calendar-events").append(e),f(this.element).find("div.calendar-events").append(f("<ul>")),ul=f(this.element).find("div.calendar-events").find("ul");for(var t=moment.unix(this.conf.unixTimestamp).startOf("month"),n=parseInt(t.format("MM")),a=parseInt(t.format("w")),o=0;parseInt(t.format("MM"))==n;){for(o++;parseInt(t.format("w"))==a;)t.add(1,"days");a=parseInt(t.format("w"))}for(var i=0;i<this.conf.month.dayheader.weekdays.length;i++){t=moment().startOf("week").add(this.conf.month.dayheader.weekdays[i],"days");var r=f("<li>",{class:"calendar-month-day-header"});r.append(f("<div>").css("height",this.conf.month.dayheader.heightPx+"px").css("padding-top",(this.conf.month.dayheader.heightPx-20)/2+"px").text(this.miscUcfirstString(t.format(this.conf.month.dayheader.format)))),r.css("width",100/this.conf.month.dayheader.weekdays.length+"%"),r.append(f("<ul>").css("height",o*this.conf.month.weekline.heightPx+"px")),ul.append(r)}var s=0;f(this.element).find(".calendar-month-day-header").each(function(){var e=f(this).find("div");f(e).height()>s&&(s=f(e).height())}),f(this.element).find(".calendar-month-day-header").each(function(){var e=f(this).find("div");f(e).height(s)})},n.prototype.monthDrawWeekNumbers=function(){f(this.element).append(f("<div>",{class:"calendar-timeline"}));var e=this.conf.month.dayheader.heightPx;e+=this.conf.month.heightPx,this.conf.categories.enable&&(e+=30),e+=2,f(this.element).find("div.calendar-timeline").css("margin-top",e+"px"),f(this.element).find("div.calendar-timeline").append(f("<ul>")),ul=f(this.element).find("div.calendar-timeline").find("ul");for(var t=moment.unix(this.conf.unixTimestamp).startOf("month"),n=parseInt(t.format("MM")),a=parseInt(t.format("w"));parseInt(t.format("MM"))==n;){for(li=f("<li>",{class:"monthtoweek"}),li.append(f("<span>").attr("data-timestamp",t.format("X")).text(t.format(this.conf.month.weekline.format)).css("margin-top",this.conf.month.weekline.heightPx/2+"px")),li.height(this.conf.month.weekline.heightPx),ul.append(li);parseInt(t.format("w"))==a;)t.add(1,"days");a=parseInt(t.format("w"))}},n.prototype.monthDrawWeekDays=function(){for(var e=this.getViewDays(),t=parseInt(moment.unix(e[0]).weekday()),n=moment.unix(e[0]);0<t;){n=n.subtract(1,"days");var a=this.element.find(".calendar-events>ul>.calendar-month-day-header>div:contains('"+this.miscUcfirstString(n.format(this.conf.month.dayheader.format))+"')").parent().find("ul");(o=f("<li>")).css("height",this.conf.month.weekline.heightPx+"px"),f(a).append(o),t--}for(t=0;t<e.length;t++){var o;a=this.element.find(".calendar-events>ul>.calendar-month-day-header>div:contains('"+this.miscUcfirstString(moment.unix(e[t]).format(this.conf.month.dayheader.format))+"')").parent().find("ul");(o=f("<li>",{class:"calendar-month-events-day"})).css("height",this.conf.month.weekline.heightPx+"px"),o.attr("data-time-from",moment.unix(e[t]).startOf("day").format("X")),o.attr("data-time-to",moment.unix(e[t]).endOf("day").format("X")),o.append(f("<span>").text(moment.unix(e[t]).format(this.conf.month.day.format))),f(a).append(o)}this.element.find(".calendar-month-events-day").each(function(){f(this).append(f("<ul>"))})},n.prototype.drawCategories=function(){if(this.determineEventsCategories(),this.determineDaynotesCategories(),this.conf.categories.enable){for(var e=f("<div>",{class:"calendar-categories"}).css("height","20px"),t=0;t<this.eventCategoryColor.length;t++){(n=f("<span>",{class:"label label-default calendar-label"})).css("margin-right","5px"),n.css("background-color",this.eventCategoryColor[t].color),n.css("cursor","pointer"),n.attr("data-color",this.eventCategoryColor[t].color),n.attr("data-clicked",!1),n.text(this.eventCategoryColor[t].category),e.append(n)}for(t=0;t<this.daynoteCategoryColor.length;t++){var n;(n=f("<span>",{class:"label label-default calendar-label calendar-label-daynote"})).css("margin-right","5px"),n.css("background-color",this.daynoteCategoryColor[t].color),n.css("cursor","pointer"),n.attr("data-color",this.daynoteCategoryColor[t].color),n.attr("data-clicked",!1),n.text(this.daynoteCategoryColor[t].category),e.append(n)}this.element.prepend(e),this.hoverCategory(),this.clickCategory()}},n.prototype.hoverCategory=function(){var e=this;this.element.find(".calendar-label").hover(function(){elem=f(this),setTimeoutConst=setTimeout(function(){elem.hasClass("calendar-label-daynote")?f(e.element).trigger("Calendar.category-daynote-mouseenter",[e,elem]):f(e.element).trigger("Calendar.category-event-mouseenter",[e,elem])},e.conf.categories.hover.delay)},function(){clearTimeout(setTimeoutConst),elem=f(this),elem.hasClass("calendar-label-daynote")?f(e.element).trigger("Calendar.category-daynote-mouseleave",[e,elem]):f(e.element).trigger("Calendar.category-event-mouseleave",[e,elem])})},n.prototype.clickCategory=function(){var t=this;this.element.find(".calendar-label").click(function(e){f(e.target).hasClass("calendar-label-daynote")?f(t.element).trigger("Calendar.category-daynote-click",[t,elem]):f(t.element).trigger("Calendar.category-event-click",[t,elem])})},n.prototype.positionEvents=function(){"day"!=this.getView()&&"week"!=this.getView()||this.positionEventsInWeek(),"month"==this.getView()&&this.positionEventsInMonth()},n.prototype.positionEventsInWeek=function(){self=this,zeroLast=0,this.element.find(".calendar-event").each(function(e){start=parseInt(f(this).attr("data-start")),end=parseInt(f(this).attr("data-end")),duration=end-start,zero=parseInt(f(this).closest("li.calendar-events-day").attr("data-time"))+60*self.conf.weekday.timeline.fromHour*60,zero>zeroLast&&(zeroLast=zero),eventTop=(start-zero)/60/self.conf.weekday.timeline.intervalMinutes*self.conf.weekday.timeline.heightPx-1,eventHeight=duration/60/self.conf.weekday.timeline.intervalMinutes*self.conf.weekday.timeline.heightPx+1,endsOnCurrent=0,nbEventNotOnCurrent=!1,nbEventOnCurrent=0,tmp=[],currentElement=f(this),f(this).closest("ul").find("li.calendar-event").each(function(e,t){f(t)[0]!=currentElement[0]&&(parseInt(currentElement.attr("data-start"))<parseInt(f(t).attr("data-end"))&&parseInt(currentElement.attr("data-end"))>parseInt(f(t).attr("data-start"))&&(tmp.push(f(t)),nbEventOnCurrent++),parseInt(currentElement.attr("data-start"))<parseInt(f(t).attr("data-end"))&&parseInt(currentElement.attr("data-end"))>parseInt(f(t).attr("data-end"))?endsOnCurrent++:parseInt(currentElement.attr("data-start"))==parseInt(f(t).attr("data-start"))&&parseInt(f(t).attr("data-index"))<parseInt(currentElement.attr("data-index"))&&endsOnCurrent++)});var t=[];t.push(parseInt(currentElement.attr("data-start"))),t.push(parseInt(currentElement.attr("data-end")));for(e=0;e<tmp.length;e++)parseInt(tmp[e].attr("data-start"))>=parseInt(currentElement.attr("data-start"))&&parseInt(tmp[e].attr("data-start"))<=parseInt(currentElement.attr("data-end"))&&t.push(parseInt(tmp[e].attr("data-start"))),parseInt(tmp[e].attr("data-end"))>=parseInt(currentElement.attr("data-start"))&&parseInt(tmp[e].attr("data-end"))<=parseInt(currentElement.attr("data-end"))&&t.push(parseInt(tmp[e].attr("data-end")));(t=self.miscUniqueArray(t)).sort(function(e,t){return t<e?1:-1});for(e=0;e<t.length;e++){for(var n=0,a=0;a<tmp.length;a++)t[e]>parseInt(tmp[a].attr("data-start"))&&t[e]<=parseInt(tmp[a].attr("data-end"))&&n++;(0<n&&n>nbEventNotOnCurrent||!1===nbEventNotOnCurrent)&&(nbEventNotOnCurrent=n)}currentElement.attr("data-events",nbEventNotOnCurrent+1),currentElement.attr("data-divider",nbEventNotOnCurrent+1);for(e=0;e<tmp.length;e++)parseInt(tmp[e].attr("data-divider"))>parseInt(currentElement.attr("data-divider"))&&currentElement.attr("data-divider",tmp[e].attr("data-divider"));var o=[];for(e=0;e<parseInt(currentElement.attr("data-divider"));e++){o[e]=!1;for(a=0;a<tmp.length;a++)for(var i=0;i<String(tmp[a].attr("data-positions")).split(",").length;i++){String(tmp[a].attr("data-positions")).split(",")[i]==e&&(o[e]=!0)}}currentElement.attr("data-positions",-1);for(e=0;-1==parseInt(currentElement.attr("data-positions"));){if(!1===o[e]&&(currentElement.attr("data-positions",e),1<parseInt(currentElement.attr("data-divider"))-parseInt(currentElement.attr("data-events"))+1))for(;!1===o[e+1];)currentElement.attr("data-positions",currentElement.attr("data-positions")+","+(e+1)),e++;e++}eventWidth=100/(parseInt(currentElement.attr("data-divider"))/String(currentElement.attr("data-positions")).split(",").length),eventLeft=String(currentElement.attr("data-positions")).split(",")[0]/parseInt(currentElement.attr("data-divider"))*100,self.setEventPosition(this,eventTop,eventHeight,eventLeft,eventWidth)})},n.prototype.positionEventsInMonth=function(){var r=this;this.element.find("li.calendar-month-events-day").each(function(){var i=f(this).find(".calendar-event").length;f(this).find(".calendar-event").each(function(e){var t=parseInt(f(this).closest(".calendar-month-events-day").index())*r.conf.month.weekline.heightPx+20-1,n=r.conf.month.weekline.heightPx-21+1,a=100/i,o=100/i*e;r.setEventPosition(this,t,n,o,a)})})},n.prototype.setEventPosition=function(e,t,n,a,o){f(e).attr("data-top",t),f(e).attr("data-height",n),f(e).attr("data-left",a),f(e).attr("data-width",o),f(e).css({top:t+"px",height:n+"px",left:a+"%",width:o+"%"})},n.prototype.weekDrawEvents=function(){for(var t=0;t<this.events.length;t++)e=this.events[t],day=!1,fromHour=this.conf.weekday.timeline.fromHour,toHour=this.conf.weekday.timeline.toHour,interval=this.conf.weekday.timeline.intervalMinutes,f(this.element).find(".calendar-events-day").each(function(t,n){e.start>=parseInt(f(n).attr("data-time"))+60*fromHour*60&&e.end<=parseInt(f(n).attr("data-time"))+60*toHour*60+60/interval*interval*60&&(day=n)}),!1===day||this.drawEventsOrDaynotes(day,t,moment.unix(e.start).format("X"),moment.unix(e.end).format("X"),e.title,e.content,e.category,this.getEventCategoryColor(e.category),moment.unix(e.start).format(this.conf.weekday.timeline.format)+" - "+moment.unix(e.end).format(this.conf.weekday.timeline.format),["calendar-event"])},n.prototype.weekDrawDaynotes=function(){for(var t=0;t<this.daynotes.length;t++)if(e=this.daynotes[t],day=!1,f(this.element).find(".calendar-events-day").each(function(t,n){parseInt(moment.unix(e.time).startOf("day").format("X"))==parseInt(f(n).attr("data-time"))&&(day=n)}),!1===day);else{color=this.getDaynoteCategoryColor(e.category);var n=this.conf.weekday.timeline.fromHour,a=this.conf.weekday.timeline.toHour+parseInt(this.conf.weekday.timeline.intervalMinutes/60),o=60*(this.conf.weekday.timeline.intervalMinutes/60-parseInt(this.conf.weekday.timeline.intervalMinutes/60));this.drawEventsOrDaynotes(day,t,moment.unix(e.time).startOf("day").add(n,"h").format("X"),moment.unix(e.time).startOf("day").add(a,"h").add(o,"m").format("X"),e.title,e.content,e.category,this.getDaynoteCategoryColor(e.category),"",["calendar-event","calendar-daynote"])}},n.prototype.drawEventsOrDaynotes=function(e,t,n,o,i,r,s,d,l,m){for(var h=f("<li>"),c=0;c<m.length;c++)h.addClass(m[c]);h.attr("data-index",t),h.attr("data-start",n),h.attr("data-end",o),h.attr("data-title",i),h.attr("data-content",r),h.attr("data-category",s),h.attr("data-color",d),h.css("background",d),a=f("<a>",{href:"#"}),a.append(f("<em>",{class:"event-name"}).text(i)),a.append(f("<em>",{class:"event-content hidden"})),a.find(".event-content").append(f("<b>",{class:"event-date"}).html(l)),a.find(".event-content").append(f("<br>")),a.find(".event-content").append(r),h.append(a),f(e).find("ul").append(h)},n.prototype.monthDrawEvents=function(){for(var t=0;t<this.events.length;t++)e=this.events[t],day=!1,f(this.element).find(".calendar-month-events-day").each(function(t,n){e.start>=parseInt(f(n).attr("data-time-from"))&&e.end<=parseInt(f(n).attr("data-time-to"))&&(day=n)}),!1===day||this.drawEventsOrDaynotes(day,t,moment.unix(e.start).format("X"),moment.unix(e.end).format("X"),e.title,e.content,e.category,this.getEventCategoryColor(e.category),moment.unix(e.start).format(this.conf.month.day.format)+" : "+moment.unix(e.start).format(this.conf.weekday.timeline.format)+" - "+moment.unix(e.end).format(this.conf.weekday.timeline.format),["calendar-event"])},n.prototype.monthDrawDaynotes=function(){for(var t=0;t<this.daynotes.length;t++)e=this.daynotes[t],day=!1,f(this.element).find(".calendar-month-events-day").each(function(t,n){e.time>=parseInt(f(n).attr("data-time-from"))&&e.time<=parseInt(f(n).attr("data-time-to"))&&(day=n)}),!1===day||this.drawEventsOrDaynotes(day,t,moment.unix(e.time).startOf("day").format("X"),moment.unix(e.time).endOf("day").format("X"),e.title,e.content,e.category,this.getDaynoteCategoryColor(e.category),moment.unix(e.time).format(this.conf.month.day.format),["calendar-event","calendar-daynote"])},n.prototype.drawModal=function(){modal='<div class="modal fade" id="calendar-modal" tabindex="-1" role="dialog">',modal+='<div class="modal-dialog" role="document">',modal+='<div class="modal-content">',modal+='<div class="modal-header">',modal+='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>',modal+='<h3 class="modal-title"></h3>',modal+="</div>",modal+='<div class="modal-body">',modal+="</div>",modal+="</div>",modal+="</div>",modal+="</div>",f(this.element).append(modal)},n.prototype.drawNow=function(){if(this.conf.now.enable){var e=f("<hr>",{class:"featurette-divider calendar-now"});e.css("width","100%"),e.css("position","absolute"),e.css("z-index",3),e.css("border-top",this.conf.now.heightPx+"px "+this.conf.now.style+" "+this.conf.now.color);var t=(moment().format("X")-moment().startOf("day").add(this.conf.weekday.timeline.fromHour,"h").format("X"))/60/this.conf.weekday.timeline.intervalMinutes*this.conf.weekday.timeline.heightPx-this.conf.weekday.timeline.heightPx/2;if(e.css("top",t+"px"),this.element.find('li.calendar-events-day[data-time="'+moment().startOf("day").format("X")+'"]').find("ul").append(e),this.conf.now.refresh){var n=this;setInterval(function(){var e=n.element.find("hr.calendar-now").remove();(e=f("<hr>",{class:"featurette-divider calendar-now"})).css("width","100%"),e.css("position","absolute"),e.css("z-index",2),e.css("border-top",n.conf.now.heightPx+"px "+n.conf.now.style+" "+n.conf.now.color);var t=(moment().format("X")-moment().startOf("day").add(n.conf.weekday.timeline.fromHour,"h").format("X"))/60/n.conf.weekday.timeline.intervalMinutes*n.conf.weekday.timeline.heightPx-n.conf.weekday.timeline.heightPx/2;e.css("top",t+"px"),n.element.find('li.calendar-events-day[data-time="'+moment().startOf("day").format("X")+'"]').find("ul").append(e)},1e4)}}},n.prototype.hoverEventOrDaynote=function(){var t=this;this.element.find(".calendar-event").each(function(){var e;f(this).hover(function(){elem=f(this),e=setTimeout(function(){elem.hasClass("calendar-daynote")?f(t.element).trigger("Calendar.daynote-mouseenter",[t,elem]):f(t.element).trigger("Calendar.event-mouseenter",[t,elem])},t.conf.event.hover.delay)},function(){clearTimeout(e),elem=f(this),elem.hasClass("calendar-daynote")?f(t.element).trigger("Calendar.daynote-mouseleave",[t,elem]):f(t.element).trigger("Calendar.event-mouseleave",[t,elem])})})},n.prototype.clickEventOrDaynote=function(){(self=this).element.find(".calendar-event").each(function(){f(this).click(function(e){elem=f(e.target),"LI"===elem.prop("nodeName")||elem.hasClass("calendar-event")||(elem=elem.closest("li.calendar-event")),elem.hasClass("calendar-daynote")?f(self.element).trigger("Calendar.daynote-click",[self,elem,self.daynotes[parseInt(elem.attr("data-index"))]]):f(self.element).trigger("Calendar.event-click",[self,elem,self.events[parseInt(elem.attr("data-index"))]])})})},n.prototype.resizeTimeline=function(){for(var e=0;e<this.events.length;e++)parseInt(moment.unix(this.events[e].start).format("HH"))<this.conf.weekday.timeline.fromHour&&(this.conf.weekday.timeline.fromHour=parseInt(moment.unix(this.events[e].start).format("HH"))),parseInt(this.events[e].end)>parseInt(moment.unix(this.events[e].end).startOf("day").add(this.conf.weekday.timeline.toHour,"hour").format("X"))&&(this.conf.weekday.timeline.toHour=parseInt(moment.unix(this.events[e].end).hour()),this.conf.weekday.timeline.toHour<23&&this.conf.weekday.timeline.toHour++)},n.prototype.getViewDays=function(){var e=[];if("day"==this.getView()&&e.push(parseInt(moment.unix(this.conf.unixTimestamp).format("X"))),"week"==this.getView())for(var t=0;t<this.conf.weekday.dayline.weekdays.length;t++)e.push(parseInt(moment.unix(this.conf.unixTimestamp).startOf("week").add(this.conf.weekday.dayline.weekdays[t],"days").format("X")));if("month"==this.getView()){var n=moment.unix(this.conf.unixTimestamp).daysInMonth(),a=moment.unix(this.conf.unixTimestamp).startOf("month");for(t=0;t<n;t++)e.push(parseInt(a.startOf("day").format("X"))),a.add(1,"days")}return e},n.prototype.addBtnLeftRight=function(){var t=this;this.element.find(".btn-move-calendar").click(function(e){elem=f(e.target),"BUTTON"!==elem.prop("nodeName")&&(elem=elem.closest(".btn-move-calendar")),t.moveCurrentIntervalView(f(elem).attr("data-direction"))})},n.prototype.addSwipe=function(){var n=this;n.element.find(".calendar-events").swipe({swipe:function(e,t){"left"!=t&&"right"!=t||("left"==t?t="right":"right"==t&&(t="left"),n.moveCurrentIntervalView(t))},threshold:100,allowPageScroll:"auto"})},n.prototype.clickSwitchView=function(){var e=this;f(this.element).find(".monthtoweek").click(function(){e.setTimestamp(parseInt(f(this).find("span").attr("data-timestamp"))),e.setView("week"),e.init()}),f(this.element).find(".weektomonth").click(function(){e.setView("month"),e.init()}),f(this.element).find(".daytoweek").click(function(){e.setView("week"),e.init()}),f(this.element).find(".weektoday").click(function(){e.setTimestamp(f(this).closest(".calendar-events-day").attr("data-time")),e.setView("day"),e.init()})},n.prototype.keyboardSwitchView=function(){if(this.conf.enableKeyboard){var t=this;f(window).unbind("keydown").on("keydown",function(e){37==e.keyCode&&e.ctrlKey&&t.moveCurrentIntervalView("left"),39==e.keyCode&&e.ctrlKey&&t.moveCurrentIntervalView("right"),38==e.keyCode&&e.ctrlKey&&("week"==t.getView()&&(t.setView("month"),t.init()),"day"==t.getView()&&(t.setView("week"),t.init())),40==e.keyCode&&e.ctrlKey&&("week"==t.getView()&&(t.setView("day"),t.init()),"month"==t.getView()&&(t.setView("week"),t.init()))})}},n.prototype.moveCurrentIntervalView=function(e){var t;"day"==this.getView()&&(t="days"),"week"==this.getView()&&(t="week"),"month"==this.getView()&&(t="month"),"left"==e&&(this.conf.unixTimestamp=parseInt(moment.unix(self.conf.unixTimestamp).subtract(1,t).format("X"))),"right"==e&&(this.conf.unixTimestamp=parseInt(moment.unix(self.conf.unixTimestamp).add(1,t).format("X"))),this.init()},n.prototype.mobileQuery=function(){return f(window).width()<this.conf.defaultView.smallScreenThreshold?"mobile":"desktop"},n.prototype.hexToRgb=function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,n,a){return t+t+n+n+a+a});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},n.prototype.calculateCurrentInterval=function(){var e=this.getViewDays();this.fromTimestamp=parseInt(moment.unix(e[0]).startOf("day").format("X")),this.toTimestamp=parseInt(moment.unix(e[e.length-1]).endOf("day").format("X"))},n.prototype.getCategories=function(t,n,a){for(var o=[],i=0;i<t.length;i++)e=t[i],parseInt(e[n])>=parseInt(this.fromTimestamp)&&parseInt(e[a])<=parseInt(this.toTimestamp)&&o.push(e.category);return o=this.miscUniqueArray(o)},n.prototype.getCategoryColor=function(e,t,n,a){for(var o=0;o<t.length;o++)if(t[o].category==e)return t[o].color;for(o=0;o<n.length;o++){used=!1;for(var i=0;i<t.length;i++)t[i].color==n[o]&&(used=!0);if(!used)return t.push({category:e,color:n[o]}),n[o]}return a},n.prototype.getEventsCategories=function(){return this.getCategories(this.events,"start","end")},n.prototype.determineEventsCategories=function(){var e=this.getEventsCategories();this.eventCategoryColor=0<this.userEventCategoryColor.length?this.userEventCategoryColor:[];for(var t=0;t<e.length;t++)this.getEventCategoryColor(e[t])},n.prototype.getEventCategoryColor=function(e){return this.getCategoryColor(e,this.eventCategoryColor,this.conf.colors.events,"#000000")},n.prototype.getEventCategoriesColors=function(){return this.eventCategoryColor},n.prototype.setEventCategoriesColors=function(e){return this.userEventCategoryColor=e,this},n.prototype.getDaynotesCategories=function(){return this.getCategories(this.daynotes,"time","time")},n.prototype.determineDaynotesCategories=function(){var e=this.getDaynotesCategories();this.daynoteCategoryColor=0<this.userDaynoteCategoryColor.length?this.userDaynoteCategoryColor:[];for(var t=0;t<e.length;t++)this.getDaynoteCategoryColor(e[t])},n.prototype.getDaynoteCategoryColor=function(e){return this.getCategoryColor(e,this.daynoteCategoryColor,this.conf.colors.daynotes,"#FEFEFE")},n.prototype.getDaynoteCategoriesColors=function(){return this.daynoteCategoryColor},n.prototype.setDaynoteCategoriesColors=function(e){this.userDaynoteCategoryColor=e},n.prototype.getEventColors=function(){return this.conf.colors.events},n.prototype.setEventColors=function(e){return this.conf.colors.events=this.miscDedupeArray(e),this.conf.colors.random&&this.conf.colors.events.sort(function(){return.5-Math.random()}),this},n.prototype.getDaynoteColors=function(){return this.conf.colors.daynotes},n.prototype.setDaynoteColors=function(e){return this.conf.colors.daynotes=this.miscDedupeArray(e),this.conf.colors.random&&this.conf.colors.daynotes.sort(function(){return.5-Math.random()}),this},n.prototype.getEvents=function(){return this.events},n.prototype.setEvents=function(e){return this.events=e||[],this.events.sort(function(e,t){return e.start>t.start?1:-1}),this},n.prototype.addEvents=function(e){return this.events=this.events.concat(e),this.events.sort(function(e,t){return e.start>t.start?1:-1}),this},n.prototype.getDaynotes=function(){return this.daynotes},n.prototype.setDaynotes=function(e){return this.daynotes=e||[],this.daynotes.sort(function(e,t){return e.start>t.start?1:-1}),this},n.prototype.addDaynotes=function(e){return this.daynotes.concat(e),this.daynotes.sort(function(e,t){return e.start>t.start?1:-1}),this},n.prototype.getInitTime=function(){return this.initTime},n.prototype.getViewInterval=function(){return[this.fromTimestamp,this.toTimestamp]},n.prototype.getNextViewInterval=function(){return"day"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).add(1,"d").format("X")),parseInt(moment.unix(this.toTimestamp).add(1,"d").format("X"))]:"week"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).add(1,"w").format("X")),parseInt(moment.unix(this.toTimestamp).add(1,"w").format("X"))]:"month"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).add(1,"M").format("X")),parseInt(moment.unix(this.toTimestamp).add(1,"M").format("X"))]:void 0},n.prototype.getPrevViewInterval=function(){return"day"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).subtract(1,"d").format("X")),parseInt(moment.unix(this.toTimestamp).subtract(1,"d").format("X"))]:"week"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).subtract(1,"w").format("X")),parseInt(moment.unix(this.toTimestamp).subtract(1,"w").format("X"))]:"month"==this.getView()?[parseInt(moment.unix(this.fromTimestamp).subtract(1,"M").format("X")),parseInt(moment.unix(this.toTimestamp).subtract(1,"M").format("X"))]:void 0},n.prototype.getTimestamp=function(){return this.conf.unixTimestamp},n.prototype.setTimestamp=function(e){return this.conf.unixTimestamp=parseInt(e),this},n.prototype.getView=function(){return this.conf.view},n.prototype.setView=function(e){return"day"!=e&&"week"!=e&&"month"!=e||(this.conf.view=e),this},n.prototype.miscDedupeArray=function(e){e=e.concat();for(var t=0;t<e.length;++t)for(var n=t+1;n<e.length;++n)e[t]===e[n]&&e.splice(n--,1);return e},n.prototype.miscUniqueArray=function(e){e=e.concat();for(var t=0;t<e.length;++t)for(var n=t+1;n<e.length;++n)e[t]===e[n]&&e.splice(n--,1);return e},n.prototype.miscUcfirstString=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},objSchedulesPlan=[],jQuery.extend(jQuery.fn,{Calendar:function(e){var t=new n(f(this),void 0===e?{}:e);return objSchedulesPlan.push(t),t}}),pause1=500,window.addEventListener("orientationchange",function(){clearTimeout(t),t=setTimeout(function(){objSchedulesPlan.forEach(function(e){e.init()})},500)}),pause2=500,window.addEventListener("resize",function(){clearTimeout(o),o=setTimeout(function(){objSchedulesPlan.forEach(function(e){"desktop"==e.mobileQuery()&&e.init()})},500)})});