/* * jsCalendar v1.4.4 * * * MIT License * * Copyright (c) 2019 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.4";c.prototype._construct=function(a){a=this._parseArguments(a);this._setTarget(a.target);this._init(a.options);this._initTarget();this._setDate(null!==a.date?a.date:this._target.dataset.hasOwnProperty("date")?this._target.dataset.date:new Date);if(!this._now)throw Error("jsCalendar: Date is outside range.");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(" "),_dateStringParser:function(a,b){return c._defaultDateStringParser(a,b,this)},_dayStringParser:function(a,b){return c._defaultDayStringParser(a,b,this)}}};c.prototype._init=function(a){this._elements={};this._events={};this._events.date=[];this._events.month=[];this._events.day_render=[];this._events.date_render=[];this._events.month_render=[];this._date=this._now=null;this._selected=[];this.language={};this._parseOptions(a)}; c.prototype._parseArguments=function(a){var b={target:null,date:null,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.options={language:"en",zeroFill:!1,monthFormat:"month",dayFormat:"D",firstDayOfTheWeek:1,navigator:!0,navigatorPosition:"both",min:!1,max:!1,onMonthRender:!1,onDayRender:!1,onDateRender:!1};c.prototype._parseOptions=function(a){this._options={};var b={},d;for(d in c.options)c.options.hasOwnProperty(d)&&(this._options[d]=c.options[d]),a.hasOwnProperty(d)?b[d]=a[d]:this._target.dataset.hasOwnProperty(d)&& (b[d]=this._target.dataset[d]);"undefined"!==typeof b.zeroFill&&(this._options.zeroFill="false"!==b.zeroFill&&b.zeroFill?!0:!1);"undefined"!==typeof b.monthFormat&&(this._options.monthFormat=b.monthFormat);"undefined"!==typeof b.dayFormat&&(this._options.dayFormat=b.dayFormat);"undefined"!==typeof b.navigator&&(this._options.navigator="false"!==b.navigator&&b.navigator?!0:!1);"undefined"!==typeof b.navigatorPosition&&(this._options.navigatorPosition=b.navigatorPosition);"string"===typeof b.language&& "undefined"!==typeof this.languages[b.language]&&(this._options.language=b.language);this.setLanguage(this._options.language);"undefined"!==typeof b.fdotw&&(b.firstDayOfTheWeek=b.fdotw);if("undefined"!==typeof b.firstDayOfTheWeek&&("number"===typeof b.firstDayOfTheWeek&&1<=b.firstDayOfTheWeek&&7>=b.firstDayOfTheWeek&&(this._options.firstDayOfTheWeek=b.firstDayOfTheWeek),"string"===typeof b.firstDayOfTheWeek))if(b.firstDayOfTheWeek.match(/^[1-7]$/))this._options.firstDayOfTheWeek=parseInt(b.firstDayOfTheWeek, 10);else if(this._options.firstDayOfTheWeek=this.language.days.indexOf(b.firstDayOfTheWeek)+1,1>this._options.firstDayOfTheWeek||7a.getTime()||!1!==this._options.max&&this._options.max.getTime()d&&(d+=7);var c=this.language,h=this._options.monthFormat.replace(/(MONTH|month|MMM|mmm|##|#|YYYY|yyyy)/g, function(a){return c.dateStringParser(a,b)});a=this._getVisibleDates(a);var f=(new Date(b.getYear()+1900,b.getMonth()+1,0)).getDate(),g=-1;b.getYear()===this._now.getYear()&&b.getMonth()===this._now.getMonth()&&(g=d+this._now.getDate()-1);return{name:h,days:a,start:d+1,current:g,end:d+f}};c.prototype._getVisibleDates=function(a){a="undefined"===typeof a?this._date:e.parseDate(a);var b=[],d=new Date(a.getTime());d.setDate(1);d.setHours(0,0,0,0);var c=d.getDay()-(this._options.firstDayOfTheWeek-1); 0>c&&(c+=7);for(a=new Date(d.getTime());0a;a++)this._elements.headRows.push(document.createElement("tr")),this._elements.head.appendChild(this._elements.headRows[a]); a=document.createElement("th");a.setAttribute("colspan",7);this._elements.headRows[0].className="jsCalendar-title-row";this._elements.headRows[0].appendChild(a);this._elements.headLeft=document.createElement("div");this._elements.headLeft.className="jsCalendar-title-left";a.appendChild(this._elements.headLeft);this._elements.month=document.createElement("div");this._elements.month.className="jsCalendar-title-name";a.appendChild(this._elements.month);this._elements.headRight=document.createElement("div"); this._elements.headRight.className="jsCalendar-title-right";a.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(a){d.previous();var b=new Date(d._date.getTime());b.setDate(1);d._eventFire("month",b,a)},!1),this._elements.navRight.addEventListener("click",function(a){d.next();var b=new Date(d._date.getTime());b.setDate(1);d._eventFire("month", b,a)},!1));this._elements.headRows[1].className="jsCalendar-week-days";a.className="jsCalendar-title";this._elements.days=[];for(a=0;7>a;a++)this._elements.days.push(document.createElement("th")),this._elements.headRows[1].appendChild(this._elements.days[this._elements.days.length-1]);this._elements.bodyRows=[];this._elements.bodyCols=[];for(a=0;6>a;a++)for(this._elements.bodyRows.push(document.createElement("tr")),this._elements.body.appendChild(this._elements.bodyRows[a]),b=0;7>b;b++)this._elements.bodyCols.push(document.createElement("td")), this._elements.bodyRows[a].appendChild(this._elements.bodyCols[7*a+b]),this._elements.bodyCols[7*a+b].addEventListener("click",function(a){return function(b){d._eventFire("date",d._active[a],b)}}(7*a+b),!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;bd?b+d:d,0<=this._selected.indexOf(a.days[c].getTime())?this._elements.bodyCols[c].className="jsCalendar-selected":this._elements.bodyCols[c].removeAttribute("class");for(c=0;cc;c++){var e=this;this._elements.days[c].textContent=this._options.dayFormat.replace(/(DAY|day|DDD|ddd|DD|dd|D)/g,function(a){return e.language.dayStringParser(a,(c+e._options.firstDayOfTheWeek-1)%7)})}if(0c;c++)for(this._elements.days[c].removeAttribute("style"),b=0;b=a?!0:!1};c.prototype.isInMonth=function(a){if("undefined"===typeof a||null===a)return!1;a=e.parseDate(a);a.setHours(0,0,0,0);a.setDate(1);var b=e.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;a=this.languages[a];this.language.months=a.months;this.language.days=a.days;this.language.dateStringParser=a._dateStringParser;this.language.dayStringParser=a._dayStringParser;this.refresh();return this};c.autoFind=function(){for(var a=document.getElementsByClassName("auto-jsCalendar"),b=0;bb.getMonth()?"0":"")+(b.getMonth()+1);case "M":return b.getMonth()+1;case "##":return(9>b.getMonth()?"0":"")+(b.getMonth()+1);case "#":return b.getMonth()+1;case "DAY":case "day":return c.days[b.getDay()];case "DDD":case "ddd":return c.days[b.getDay()].substring(0,3);case "dd":return c.days[b.getDay()].substring(0,2);case "d":return c.days[b.getDay()].substring(0,1);case "DD":return(9>= b.getDate()?"0":"")+b.getDate();case "D":return b.getDate();case "YYYY":case "yyyy":return b.getYear()+1900}};c._defaultDayStringParser=function(a,b,c){switch(a){case "DAY":case "day":return c.days[b];case "DDD":case "ddd":return c.days[b].substring(0,3);case "DD":case "dd":return c.days[b].substring(0,2);case "D":return c.days[b].substring(0,1)}};(function(){if("undefined"!==typeof window.jsCalendar_language2load){for(;window.jsCalendar_language2load.length;)setTimeout(function(a){return function(){c.addLanguage(a)}}(window.jsCalendar_language2load.pop()), 0);delete window.jsCalendar_language2load}})();window.addEventListener("load",function(){c.autoFind()},!1);return c}();