| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- /*
- Monthly 2.0.7 by Kevin Thornbloom is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
- */
- (function($) {
- $.fn.extend({
- monthly: function(options) {
- // These are overridden by options declared in footer
- var defaults = {
- weekStart: 'Sun',
- mode: '',
- xmlUrl: '',
- target: '',
- eventList: true,
- maxWidth: false,
- setWidth: false,
- startHidden: false,
- showTrigger: '',
- stylePast: false,
- disablePast: false
- }
- var options = $.extend(defaults, options),
- that = this,
- uniqueId = $(this).attr('id'),
- d = new Date(),
- currentMonth = d.getMonth() + 1,
- currentYear = d.getFullYear(),
- currentDay = d.getDate(),
- monthNames = options.monthNames || ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
- dayNames = options.dayNames || ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
- if (options.maxWidth != false){
- $('#'+uniqueId).css('maxWidth',options.maxWidth);
- }
- if (options.setWidth != false){
- $('#'+uniqueId).css('width',options.setWidth);
- }
- if (options.startHidden == true){
- $('#'+uniqueId).addClass('monthly-pop').css({
- 'position' : 'absolute',
- 'display' : 'none'
- });
- $(document).on('focus', ''+options.showTrigger+'', function (e) {
- $('#'+uniqueId).show();
- e.preventDefault();
- });
- $(document).on('click', ''+options.showTrigger+', .monthly-pop', function (e) {
- e.stopPropagation();
- e.preventDefault();
- });
- $(document).on('click', function (e) {
- $('#'+uniqueId).hide();
- });
- }
- // Add Day Of Week Titles
- if (options.weekStart == 'Sun') {
- $('#' + uniqueId).append('<div class="monthly-day-title-wrap"><div>'+dayNames[0]+'</div><div>'+dayNames[1]+'</div><div>'+dayNames[2]+'</div><div>'+dayNames[3]+'</div><div>'+dayNames[4]+'</div><div>'+dayNames[5]+'</div><div>'+dayNames[6]+'</div></div><div class="monthly-day-wrap"></div>');
- } else if (options.weekStart == 'Mon') {
- $('#' + uniqueId).append('<div class="monthly-day-title-wrap"><div>'+dayNames[1]+'</div><div>'+dayNames[2]+'</div><div>'+dayNames[3]+'</div><div>'+dayNames[4]+'</div><div>'+dayNames[5]+'</div><div>'+dayNames[6]+'</div><div>'+dayNames[0]+'</div></div><div class="monthly-day-wrap"></div>');
- } else {
- console.error('Monthly.js has an incorrect entry for the weekStart variable');
- }
- // Add Header & event list markup
- $('#' + uniqueId).prepend('<div class="monthly-header"><div class="monthly-header-title"></div><a href="#" class="monthly-prev"></a><a href="#" class="monthly-next"></a></div>').append('<div class="monthly-event-list"></div>');
- // How many days are in this month?
- function daysInMonth(m, y){
- return m===2?y&3||!(y%25)&&y&15?28:29:30+(m+(m>>3)&1);
- }
- // Massive function to build the month
- function setMonthly(m, y){
- $('#' + uniqueId).data('setMonth', m).data('setYear', y);
- // Get number of days
- var dayQty = daysInMonth(m, y),
- // Get day of the week the first day is
- mZeroed = m -1,
- firstDay = new Date(y, mZeroed, 1, 0, 0, 0, 0).getDay();
- // Remove old days
- $('#' + uniqueId + ' .monthly-day, #' + uniqueId + ' .monthly-day-blank').remove();
- $('#'+uniqueId+' .monthly-event-list').empty();
- $('#'+uniqueId+' .monthly-day-wrap').empty();
- // Print out the days
- if (options.mode == 'event') {
- for(var i = 0; i < dayQty; i++) {
- var day = i + 1; // Fix 0 indexed days
- var dayNamenum = new Date(y, mZeroed, day, 0, 0, 0, 0).getDay()
- $('#' + uniqueId + ' .monthly-day-wrap').append('<a href="#" class="m-d monthly-day monthly-day-event" data-number="'+day+'"><div class="monthly-day-number">'+day+'</div><div class="monthly-indicator-wrap"></div></a>');
- $('#' + uniqueId + ' .monthly-event-list').append('<div class="monthly-list-item" id="'+uniqueId+'day'+day+'" data-number="'+day+'"><div class="monthly-event-list-date">'+dayNames[dayNamenum]+'<br>'+day+'</div></div>');
- }
- } else {
- for(var i = 0; i < dayQty; i++) {
- // Fix 0 indexed days
- var day = i + 1;
- // Check if it's a day in the past
- if(((day < currentDay && m === currentMonth) || y < currentYear || (m < currentMonth && y == currentYear)) && options.stylePast == true){
- $('#' + uniqueId + ' .monthly-day-wrap').append('<a href="#" data-toggle="modal" data-target="#schedule-box" class="m-d monthly-day monthly-day-pick monthly-past-day" data-number="'+day+'"><div class="monthly-day-number">'+day+'</div><div class="monthly-indicator-wrap"></div></a>');
- } else {
- $('#' + uniqueId + ' .monthly-day-wrap').append('<a href="#" data-toggle="modal" data-target="#schedule-box" class="m-d monthly-day monthly-day-pick" data-number="'+day+'"><div class="monthly-day-number">'+day+'</div><div class="monthly-indicator-wrap"></div></a>');
- }
- }
- }
- // Set Today
- var setMonth = $('#' + uniqueId).data('setMonth'),
- setYear = $('#' + uniqueId).data('setYear');
- if (setMonth == currentMonth && setYear == currentYear) {
- $('#' + uniqueId + ' *[data-number="'+currentDay+'"]').addClass('monthly-today');
- }
- // Reset button
- if (setMonth == currentMonth && setYear == currentYear) {
- $('#' + uniqueId + ' .monthly-header-title').html(monthNames[m - 1] +' '+ y);
- } else {
- $('#' + uniqueId + ' .monthly-header-title').html(monthNames[m - 1] +' '+ y +'<a href="#" class="monthly-reset" title="Back To This Month"></a> ');
- }
- // Account for empty days at start
- if(options.weekStart == 'Sun' && firstDay != 7) {
- for(var i = 0; i < firstDay; i++) {
- $('#' + uniqueId + ' .monthly-day-wrap').prepend('<div class="m-d monthly-day-blank"><div class="monthly-day-number"></div></div>');
- }
- } else if (options.weekStart == 'Mon' && firstDay == 0) {
- for(var i = 0; i < 6; i++) {
- $('#' + uniqueId + ' .monthly-day-wrap').prepend('<div class="m-d monthly-day-blank" ><div class="monthly-day-number"></div></div>');
- }
- } else if (options.weekStart == 'Mon' && firstDay != 1) {
- for(var i = 0; i < (firstDay - 1); i++) {
- $('#' + uniqueId + ' .monthly-day-wrap').prepend('<div class="m-d monthly-day-blank" ><div class="monthly-day-number"></div></div>');
- }
- }
- //Account for empty days at end
- var numdays = $('#' + uniqueId + ' .monthly-day').length,
- numempty = $('#' + uniqueId + ' .monthly-day-blank').length,
- totaldays = numdays + numempty,
- roundup = Math.ceil(totaldays/7) * 7,
- daysdiff = roundup - totaldays;
- if(totaldays % 7 != 0) {
- for(var i = 0; i < daysdiff; i++) {
- $('#' + uniqueId + ' .monthly-day-wrap').append('<div class="m-d monthly-day-blank"><div class="monthly-day-number"></div></div>');
- }
- }
- // Events
- if (options.mode == 'event') {
- // Remove previous events
- // Add Events
- $.get(''+options.xmlUrl+'', function(d){
- $(d).find('event').each(function(){
- // Year [0] Month [1] Day [2]
- var fullstartDate = $(this).find('startdate').text(),
- startArr = fullstartDate.split("-"),
- startYear = startArr[0],
- startMonth = parseInt(startArr[1], 10),
- startDay = parseInt(startArr[2], 10),
- fullendDate = $(this).find('enddate').text(),
- endArr = fullendDate.split("-"),
- endYear = endArr[0],
- endMonth = parseInt(endArr[1], 10),
- endDay = parseInt(endArr[2], 10),
- eventURL = $(this).find('url').text(),
- eventTitle = $(this).find('name').text(),
- eventColor = $(this).find('color').text(),
- eventId = $(this).find('id').text(),
- startTime = $(this).find('starttime').text(),
- startSplit = startTime.split(":");
- endTime = $(this).find('endtime').text(),
- endSplit = endTime.split(":");
- eventLink = '',
- startPeriod = 'AM',
- endPeriod = 'PM';
- /* Convert times to 12 hour & determine AM or PM */
- if(parseInt(startSplit[0]) >= 12) {
- var startTime = (startSplit[0] - 12)+':'+startSplit[1]+'';
- var startPeriod = 'PM'
- }
- if(parseInt(startTime) == 0) {
- var startTime = '12:'+startSplit[1]+'';
- }
- if(parseInt(endSplit[0]) >= 12) {
- var endTime = (endSplit[0] - 12)+':'+endSplit[1]+'';
- var endPeriod = 'PM'
- }
- if(parseInt(endTime) == 0) {
- var endTime = '12:'+endSplit[1]+'';
- }
- if (eventURL){
- var eventLink = 'href="'+eventURL+'"';
- }
- // function to print out list for multi day events
- function multidaylist(){
- var timeHtml = '';
- if (startTime){
- var startTimehtml = '<div><div class="monthly-list-time-start">'+startTime+' '+startPeriod+'</div>';
- var endTimehtml = '';
- if (endTime){
- var endTimehtml = '<div class="monthly-list-time-end">'+endTime+' '+endPeriod+'</div>';
- }
- var timeHtml = startTimehtml + endTimehtml + '</div>';
- }
- $('#'+uniqueId+' .monthly-list-item[data-number="'+i+'"]').addClass('item-has-event').append('<a href="'+eventURL+'" class="listed-event" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+' '+timeHtml+'</a>');
- }
- // If event is one day & within month
- if (!fullendDate && startMonth == setMonth && startYear == setYear) {
- // Add Indicators
- $('#'+uniqueId+' *[data-number="'+startDay+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+'</div>');
- // Print out event list for single day event
- var timeHtml = '';
- if (startTime){
- var startTimehtml = '<div><div class="monthly-list-time-start">'+startTime+' '+startPeriod+'</div>';
- var endTimehtml = '';
- if (endTime){
- var endTimehtml = '<div class="monthly-list-time-end">'+endTime+' '+endPeriod+'</div>';
- }
- var timeHtml = startTimehtml + endTimehtml + '</div>';
- }
- $('#'+uniqueId+' .monthly-list-item[data-number="'+startDay+'"]').addClass('item-has-event').append('<a href="'+eventURL+'" class="listed-event" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+' '+timeHtml+'</a>');
- // If event is multi day & within month
- } else if (startMonth == setMonth && startYear == setYear && endMonth == setMonth && endYear == setYear){
- for(var i = parseInt(startDay); i <= parseInt(endDay); i++) {
- // If first day, add title
- if (i == parseInt(startDay)) {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+'</div>');
- } else {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'"></div>');
- }
- multidaylist();
- }
- // If event is multi day, starts in prev month, and ends in current month
- } else if ((endMonth == setMonth && endYear == setYear) && ((startMonth < setMonth && startYear == setYear) || (startYear < setYear))) {
- for(var i = 0; i <= parseInt(endDay); i++) {
- // If first day, add title
- if (i==1){
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+'</div>');
- } else {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'"></div>');
- }
- multidaylist();
- }
- // If event is multi day, starts in this month, but ends in next
- } else if ((startMonth == setMonth && startYear == setYear) && ((endMonth > setMonth && endYear == setYear) || (endYear > setYear))){
- for(var i = parseInt(startDay); i <= dayQty; i++) {
- // If first day, add title
- if (i == parseInt(startDay)) {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+'</div>');
- } else {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'"></div>');
- }
- multidaylist();
- }
- // If event is multi day, starts in a prev month, ends in a future month
- } else if (((startMonth < setMonth && startYear == setYear) || (startYear < setYear)) && ((endMonth > setMonth && endYear == setYear) || (endYear > setYear))){
- for(var i = 0; i <= dayQty; i++) {
- // If first day, add title
- if (i == 1){
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'">'+eventTitle+'</div>');
- } else {
- $('#'+uniqueId+' *[data-number="'+i+'"] .monthly-indicator-wrap').append('<div class="monthly-event-indicator" data-eventid="'+ eventId +'" style="background:'+eventColor+'" title="'+eventTitle+'"></div>');
- }
- multidaylist();
- }
- }
- });
- }).fail(function() {
- console.error('Monthly.js failed to import '+options.xmlUrl+'. Please check for the correct path & XML syntax.');
- });
- }
- var divs = $("#"+uniqueId+" .m-d");
- for(var i = 0; i < divs.length; i+=7) {
- divs.slice(i, i+7).wrapAll("<div class='monthly-week'></div>");
- }
- }
- // Set the calendar the first time
- setMonthly(currentMonth, currentYear);
- // Function to go back to the month view
- function viewToggleButton(){
- if($('#'+uniqueId+' .monthly-event-list').is(":visible")) {
- $('#'+uniqueId+' .monthly-cal').remove();
- $('#'+uniqueId+' .monthly-header-title').prepend('<a href="#" class="monthly-cal" title="Back To Month View"><div></div></a>');
- }
- }
- // Advance months
- $(document.body).on('click', '#'+uniqueId+' .monthly-next', function (e) {
- var setMonth = $('#' + uniqueId).data('setMonth'),
- setYear = $('#' + uniqueId).data('setYear');
- if (setMonth == 12) {
- var newMonth = 1,
- newYear = setYear + 1;
- setMonthly(newMonth, newYear);
- } else {
- var newMonth = setMonth + 1,
- newYear = setYear;
- setMonthly(newMonth, newYear);
- }
- viewToggleButton();
- e.preventDefault();
- });
- // Go back in months
- $(document.body).on('click', '#'+uniqueId+' .monthly-prev', function (e) {
- var setMonth = $('#' + uniqueId).data('setMonth'),
- setYear = $('#' + uniqueId).data('setYear');
- if (setMonth == 1) {
- var newMonth = 12,
- newYear = setYear - 1;
- setMonthly(newMonth, newYear);
- } else {
- var newMonth = setMonth - 1,
- newYear = setYear;
- setMonthly(newMonth, newYear);
- }
- viewToggleButton();
- e.preventDefault();
- });
- // Reset Month
- $(document.body).on('click', '#'+uniqueId+' .monthly-reset', function (e) {
- setMonthly(currentMonth, currentYear);
- viewToggleButton();
- e.preventDefault();
- e.stopPropagation();
- });
- // Back to month view
- $(document.body).on('click', '#'+uniqueId+' .monthly-cal', function (e) {
- $(this).remove();
- $('#' + uniqueId+' .monthly-event-list').css('transform','scale(0)').delay('800').hide();
- e.preventDefault();
- });
- // Click A Day
- $(document.body).on('click', '#'+uniqueId+' a.monthly-day', function (e) {
- // If events, show events list
- if(options.mode == 'event' && options.eventList == true) {
- var whichDay = $(this).data('number');
- $('#' + uniqueId+' .monthly-event-list').show();
- $('#' + uniqueId+' .monthly-event-list').css('transform');
- $('#' + uniqueId+' .monthly-event-list').css('transform','scale(1)');
- $('#'+uniqueId+' .monthly-list-item[data-number="'+whichDay+'"]').show();
- var myElement = document.getElementById(uniqueId+'day'+whichDay);
- var topPos = myElement.offsetTop;
- //document.getElementByClassname('scrolling_div').scrollTop = topPos;
- $('#'+uniqueId+' .monthly-event-list').scrollTop(topPos);
- viewToggleButton();
- // If picker, pick date
- } else if (options.mode == 'picker') {
- var whichDay = $(this).data('number'),
- setMonth = $('#' + uniqueId).data('setMonth'),
- setYear = $('#' + uniqueId).data('setYear');
- // Should days in the past be disabled?
- if($(this).hasClass('monthly-past-day') && options.disablePast == true) {
- // If so, don't do anything.
- e.preventDefault();
- } else {
- // Otherwise, select the date ...
- $(''+options.target+'').val(setMonth+'/'+whichDay+'/'+setYear);
- // ... and then hide the calendar if it started that way
- if(options.startHidden == true) {
- $('#'+uniqueId).hide();
- }
- }
- }
- e.preventDefault();
- });
- // Clicking an event within the list
- $(document.body).on('click', '#'+uniqueId+' .listed-event', function (e) {
- var href = $(this).attr('href');
- // If there isn't a link, don't go anywhere
- if(!href) {
- e.preventDefault();
- }
- });
- }
- });
- })(jQuery);
|