/* * jsCalendar v1.4.2 * * * MIT License * * Copyright (c) 2018 Grammatopoulos Athanasios-Vasileios * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ var jsCalendar=function(){function c(){0!==arguments.length&&this._construct(arguments)}c.version="v1.4.2";c.prototype._construct=function(a){a=this._parseArguments(a);this._init(a.options);this._setTarget(a.target);this._initTarget();this._setDate(a.date);this._create();this._update()};c.prototype.languages={en:{months:"January February March April May June July August September October November December".split(" "),days:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ")}};c.prototype._init= function(a){this._elements={};this._events={};this._events.date=[];this._events.month=[];this._date=this._now=null;this._selected=[];this.language={};this._parseOptions(a)};c.prototype._parseArguments=function(a){var b={target:null,date:new Date,options:{}};if(0===a.length)throw Error("jsCalendar: No parameters were given.");if(1===a.length)if(("object"===typeof HTMLElement?a[0]instanceof HTMLElement:a[0])&&"object"===typeof a[0]&&null!==a[0]&&1===a[0].nodeType&&"string"===typeof a[0].nodeName||"string"=== typeof a[0])b.target=a[0];else{b.options=a[0];if("undefined"!==typeof a[0].target)b.target=a[0].target;else throw Error("jsCalendar: Not target was given.");"undefined"!==typeof a[0].date&&(b.date=a[0].date)}else b.target=a[0],2<=a.length&&(b.date=a[1]),3<=a.length&&(b.options=a[2]);return b};c.prototype._parseOptions=function(a){this._options={language:"en",zeroFill:!1,monthFormat:"month",dayFormat:"D",firstDayOfTheWeek:1,navigator:!0,navigatorPosition:"both",min:!1,max:!1};"undefined"!==typeof a.zeroFill&& (this._options.zeroFill="false"!==a.zeroFill&&a.zeroFill?!0:!1);"undefined"!==typeof a.monthFormat&&(this._options.monthFormat=a.monthFormat);"undefined"!==typeof a.dayFormat&&(this._options.dayFormat=a.dayFormat);"undefined"!==typeof a.navigator&&(this._options.navigator="false"!==a.navigator&&a.navigator?!0:!1);"undefined"!==typeof a.navigatorPosition&&(this._options.navigatorPosition=a.navigatorPosition);"string"===typeof a.language&&"undefined"!==typeof this.languages[a.language]&&(this._options.language= a.language);this.setLanguage(this._options.language);"undefined"!==typeof a.fdotw&&(a.firstDayOfTheWeek=a.fdotw);if("undefined"!==typeof a.firstDayOfTheWeek&&("number"===typeof a.firstDayOfTheWeek&&1<=a.firstDayOfTheWeek&&7>=a.firstDayOfTheWeek&&(this._options.firstDayOfTheWeek=a.firstDayOfTheWeek),"string"===typeof a.firstDayOfTheWeek))if(a.firstDayOfTheWeek.match(/^[1-7]$/))this._options.firstDayOfTheWeek=parseInt(a.firstDayOfTheWeek,10);else if(this._options.firstDayOfTheWeek=this.language.days.indexOf(a.firstDayOfTheWeek)+ 1,1>this._options.firstDayOfTheWeek||7a.getTime()||!1!==this._options.max&&this._options.max.getTime() a.getMonth()?"0":"")+(a.getMonth()+1);case "M":return a.getMonth()+1;case "DAY":case "day":return d.days[a.getDay()];case "DDD":case "ddd":return d.days[a.getDay()].substring(0,3);case "dd":return d.days[a.getDay()].substring(0,2);case "d":return d.days[a.getDay()].substring(0,1);case "DD":return(9>=a.getDate()?"0":"")+a.getDate();case "D":return a.getDate();case "YYYY":case "yyyy":return a.getYear()+1900}})};c.prototype._getVisibleMonth=function(a){a="undefined"===typeof a?this._date:this._parseDate(a); var b=new Date(a.getTime());b.setDate(1);var d=b.getDay()-(this._options.firstDayOfTheWeek-1);0>d&&(d+=7);var c=this.language,g=this._options.monthFormat.replace(/(MONTH|month|MMM|mmm|##|#|YYYY|yyyy)/g,function(a){switch(a){case "MONTH":case "month":return c.months[b.getMonth()];case "MMM":case "mmm":return c.months[b.getMonth()].substring(0,3);case "##":return(9>b.getMonth()?"0":"")+(b.getMonth()+1);case "#":return b.getMonth()+1;case "YYYY":case "yyyy":return b.getYear()+1900}});a=this._getVisibleDates(a); var h=(new Date(b.getYear()+1900,b.getMonth()+1,0)).getDate(),f=-1;b.getYear()===this._now.getYear()&&b.getMonth()===this._now.getMonth()&&(f=d+this._now.getDate()-1);return{name:g,days:a,start:d+1,current:f,end:d+h}};c.prototype._getVisibleDates=function(a){a="undefined"===typeof a?this._date:this._parseDate(a);var b=[],d=new Date(a.getTime());d.setDate(1);var c=d.getDay()-(this._options.firstDayOfTheWeek-1);0>c&&(c+=7);for(a=new Date(d.getTime());0b;b++)this._elements.headRows.push(document.createElement("tr")),this._elements.head.appendChild(this._elements.headRows[b]);b=document.createElement("th");b.setAttribute("colspan",7);this._elements.headRows[0].className= "jsCalendar-title-row";this._elements.headRows[0].appendChild(b);this._elements.headLeft=document.createElement("div");this._elements.headLeft.className="jsCalendar-title-left";b.appendChild(this._elements.headLeft);this._elements.month=document.createElement("div");this._elements.month.className="jsCalendar-title-name";b.appendChild(this._elements.month);this._elements.headRight=document.createElement("div");this._elements.headRight.className="jsCalendar-title-right";b.appendChild(this._elements.headRight); this._options.navigator&&(this._elements.navLeft=document.createElement("div"),this._elements.navLeft.className="jsCalendar-nav-left",this._elements.navRight=document.createElement("div"),this._elements.navRight.className="jsCalendar-nav-right","left"===this._options.navigatorPosition?(this._elements.headLeft.appendChild(this._elements.navLeft),this._elements.headLeft.appendChild(this._elements.navRight)):("right"===this._options.navigatorPosition?this._elements.headRight.appendChild(this._elements.navLeft): this._elements.headLeft.appendChild(this._elements.navLeft),this._elements.headRight.appendChild(this._elements.navRight)),this._elements.navLeft.addEventListener("click",function(b){a.previous();a._eventFire_monthChange(b,a._date)},!1),this._elements.navRight.addEventListener("click",function(b){a.next();a._eventFire_monthChange(b,a._date)},!1));this._elements.headRows[1].className="jsCalendar-week-days";b.className="jsCalendar-title";this._elements.days=[];for(b=0;7>b;b++){this._elements.days.push(document.createElement("th")); this._elements.headRows[1].appendChild(this._elements.days[this._elements.days.length-1]);var d=this.language.days[(b+this._options.firstDayOfTheWeek-1)%7];var c=this._options.dayFormat.replace(/(DAY|day|DDD|ddd|DD|dd|D)/g,function(a){switch(a){case "DAY":case "day":return d;case "DDD":case "ddd":return d.substring(0,3);case "DD":case "dd":return d.substring(0,2);case "D":return d.substring(0,1)}});this._elements.days[this._elements.days.length-1].textContent=c}this._elements.bodyRows=[];this._elements.bodyCols= [];for(b=0;6>b;b++)for(this._elements.bodyRows.push(document.createElement("tr")),this._elements.body.appendChild(this._elements.bodyRows[b]),c=0;7>c;c++)this._elements.bodyCols.push(document.createElement("td")),this._elements.bodyRows[b].appendChild(this._elements.bodyCols[7*b+c]),this._elements.bodyCols[7*b+c].addEventListener("click",function(b){return function(c){a._eventFire_dateClick(c,a._active[b])}}(7*b+c),!1)};c.prototype._selectDates=function(a){a=a.slice();for(var b=0;bthis._selected.indexOf(a[b])&&this._selected.push(a[b])};c.prototype._unselectDates=function(a){a=a.slice();for(var b=0;bc?b+c:c,0<=this._selected.indexOf(a.days[e].getTime())?this._elements.bodyCols[e].className="jsCalendar-selected":this._elements.bodyCols[e].removeAttribute("class");for(e=0;e=a?!0:!1};c.prototype.isInMonth=function(a){if("undefined"===typeof a||null===a)return!1;a=this._parseDate(a);a.setHours(0,0,0,0);a.setDate(1);var b=this._parseDate(this._date);b.setHours(0,0,0,0);b.setDate(1);return a.getTime()===b.getTime()?!0:!1};c.prototype.setLanguage=function(a){if("string"!== typeof a)throw Error("jsCalendar: Invalid language code.");if("undefined"===typeof this.languages[a])throw Error("jsCalendar: Language not found.");this._options.language=a;this.language.months=this.languages[this._options.language].months;this.language.days=this.languages[this._options.language].days;this.refresh();return this};c.autoFind=function(){for(var a=document.getElementsByClassName("auto-jsCalendar"),b,c=0;c