1 line
6.6 KiB
JavaScript
1 line
6.6 KiB
JavaScript
|
!function(t){var e={events:[],detailedWidthBreakpoint:550,onEventClick:null,onPreviousMonthStart:null,onNextMonthStart:null,onCurrentMonthStart:null,onLoadStart:null,onLoadEnd:null},n={start:null,end:null,title:"",url:"","class":"",color:"",data:{}},a={init:function(a){return this.each(function(){var s=t(this),o=s.data("equinox");if(!o){for(var d=t.extend({},e,a),i=moment(),v=[],u=0;u<d.events.length;u++)d.events[u]=t.extend({},n,d.events[u]),d.events[u].start=moment(d.events[u].start),d.events[u].end=moment(d.events[u].end),d.events[u].start.isValid()&&d.events[u].end.isValid()&&(d.events[u].start.valueOf()>d.events[u].end.valueOf()||(d.events[u].allDay=r(d.events[u].start,d.events[u].end),d.events[u].daySpan=l(d.events[u].start,d.events[u].end),v.push(d.events[u])));d.events.sort(function(t,e){return t.start.valueOf()-e.start.valueOf()});for(var c=[],u=0;u<d.events.length;u++){d.events[u].id=u;var f=moment(d.events[u].start).startOf("day").format("UX");f in c||(c[f]=[]),c[f].push(d.events[u])}o={target:s,settings:d,currentDate:i,segmentedEvents:c,activeMonth:moment(i).startOf("month")},s.data("equinox",o),s.addClass("equinox"),s.equinox("refresh"),s.equinox("load"),t(window).resize(function(){s.equinox("refresh")}),s.on("click",".calendar-actions button.prev",function(t){var e=s.data("equinox");e.activeMonth.subtract(1,"months"),typeof e.settings.onPreviousMonthStart==typeof Function&&e.settings.onPreviousMonthStart(t,e),s.equinox("load")}),s.on("click",".calendar-actions button.next",function(t){var e=s.data("equinox");e.activeMonth.add(1,"months"),typeof e.settings.onNextMonthStart==typeof Function&&e.settings.onNextMonthStart(t,e),s.equinox("load")}),s.on("click",".calendar-actions button.today",function(t){var e=s.data("equinox"),n=moment().startOf("month");typeof e.settings.onCurrentMonthStart==typeof Function&&e.settings.onCurrentMonthStart(t,e),0!==e.activeMonth.startOf("month").diff(n)&&(e.activeMonth=n,s.equinox("load"))}),s.on("click","a.event",function(e){var n=s.data("equinox");if(typeof n.settings.onEventClick==typeof Function){var a=n.settings.events[t(this).data("event-id")],o=t.extend({start:a.start,end:a.end,title:a.title,url:a.url,"class":a["class"]},a.data);n.settings.onEventClick(e,o)}})}})},load:function(){return this.each(function(){var e=t(this),n=e.data("equinox");typeof n.settings.onLoadStart==typeof Function&&n.settings.onLoadStart(n);var a=n.activeMonth,o=s(a,n.segmentedEvents);typeof n.settings.onLoadEnd==typeof Function&&n.settings.onLoadEnd(n),e.html(o)})},refresh:function(){return this.each(function(){var e=t(this),n=e.data("equinox");e.width()<n.settings.detailedWidthBreakpoint?e.removeClass("detailed"):e.addClass("detailed")})}};t.fn.equinox=function(e){return a[e]?a[e].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof e&&e?void t.error("Method "+e+" does not exist on jQuery.equinox"):a.init.apply(this,arguments)};var s=function(e,n){var a=t('<div class="calendar"></div>'),s=t('<div class="calendar-header"></div>');s.append('<div class="month-label">'+e.format("MMMM YYYY")+"</div>"),s.append('<div class="calendar-actions"></div>'),t(".calendar-actions",s).append('<button type="button" class="prev">Previous</button> '),t(".calendar-actions",s).append('<button type="button" class="next">Next</button> '),t(".calendar-actions",s).append('<button type="button" class="today">Today</button> '),a.append(s);for(var r=t('<div class="month-weeks"></div>'),v=t('<div class="week week-header"><div class="days-container"></div></div>'),u=0;u<7;u++)t(".days-container",v).append('<div class="day '+moment().day(u).format("dddd").toLowerCase()+'">'+moment().day(u).format("dddd")+"</div>");r.append(v);var c=moment(e).startOf("month").startOf("week"),f=[];for(var u in n){if(parseInt(u.substr(1))>=c.unix())break;for(var p=0;p<n[u].length;p++)n[u][p].end.valueOf()>c.valueOf()&&(n[u][p].daysLeft=l(c,n[u][p].end)-(i(n[u][p].end)?1:0),f.push(n[u][p]))}var h=!1,m=e.daysInMonth(),y=moment();for(u=0;!h;u++){for(var g=t('<div class="week week-'+u+'"></div>'),x=[[]],M=moment(c),p=0;p<7;p++){if(M.d
|