calendar.min.js
24.8 KB
!function(e,a){"use strict";Date.convertNumbers=function(e){e=e.toString();if("[object Array]"===Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers))for(var a=0;a<JoomlaCalLocale.localLangNumbers.length;a++)e=e.replace(new RegExp(a,"g"),JoomlaCalLocale.localLangNumbers[a]);return e},Date.toEnglish=function(e){e=this.toString();for(var a=[0,1,2,3,4,5,6,7,8,9],t=0;t<10;t++)e=e.replace(new RegExp(a[t],"g"),t);return e};var t=function(e){if(!e)throw new Error("Calendar setup failed:\n No valid element found, Please check your code");if("function"!=typeof Date.parseFieldDate)throw new Error("Calendar setup failed:\n No valid date helper, Please check your code");if(e._joomlaCalendar)throw new Error("JoomlaCalendar instance already exists for the element");if(e._joomlaCalendar=this,this.writable=!0,this.hidden=!0,this.params={},this.element=e,this.inputField=e.getElementsByTagName("input")[0],this.button=e.getElementsByTagName("button")[0],!this.inputField)throw new Error("Calendar setup failed:\n No valid input found, Please check your code");this.params={debug:!1,clicked:!1,element:{style:{display:"none"}},writable:!0};var t=this,s=this.button,r={inputField:this.inputField,dateType:JoomlaCalLocale.dateType?JoomlaCalLocale.dateType:"gregorian",direction:void 0!==a.dir?a.dir:a.getElementsByTagName("html")[0].getAttribute("dir"),firstDayOfWeek:s.getAttribute("data-firstday")?parseInt(s.getAttribute("data-firstday")):0,dateFormat:"%Y-%m-%d %H:%M:%S",weekend:JoomlaCalLocale.weekend?JoomlaCalLocale.weekend:[0,6],minYear:JoomlaCalLocale.minYear?JoomlaCalLocale.minYear:1900,maxYear:JoomlaCalLocale.maxYear?JoomlaCalLocale.maxYear:2100,minYearTmp:s.getAttribute("data-min-year"),maxYearTmp:s.getAttribute("data-max-year"),weekendTmp:s.getAttribute("data-weekend"),time24:!0,showsOthers:1===parseInt(s.getAttribute("data-show-others")),showsTime:!0,weekNumbers:1===parseInt(s.getAttribute("data-week-numbers")),showsTodayBtn:!0,compressedHeader:1===parseInt(s.getAttribute("data-only-months-nav"))};for(var o in s.getAttribute("data-dayformat")&&(r.dateFormat=s.getAttribute("data-dayformat")?s.getAttribute("data-dayformat"):"%Y-%m-%d %H:%M:%S"),s.getAttribute("data-time-24")&&(r.time24=24===parseInt(s.getAttribute("data-time-24"))),s.getAttribute("data-show-time")&&(r.showsTime=1===parseInt(s.getAttribute("data-show-time"))),s.getAttribute("data-today-btn")&&(r.showsTodayBtn=1===parseInt(s.getAttribute("data-today-btn"))),r)this.params[o]=r[o];i(t.params.minYearTmp)&&(t.params.minYear=l(parseInt(t.params.minYearTmp),t.params.dateType)),i(t.params.maxYearTmp)&&(t.params.maxYear=l(parseInt(t.params.maxYearTmp),t.params.dateType)),"undefined"!==t.params.weekendTmp&&(t.params.weekend=t.params.weekendTmp.split(",").map(function(e){return parseInt(e,10)})),this._dayMouseDown=function(e){return t._handleDayMouseDown(e)},this._calKeyEvent=function(e){return t._handleCalKeyEvent(e)},this._documentClick=function(e){return t._handleDocumentClick(e)},this.checkInputs(),this.inputField.getAttribute("readonly")||(this._create(),this._bindEvents())};t.prototype.checkInputs=function(){var e=Date.parseFieldDate(this.inputField.getAttribute("data-alt-value"),this.params.dateFormat,"gregorian");""!==this.inputField.value?(this.date=e,this.inputField.value=e.print(this.params.dateFormat,this.params.dateType,!0)):this.date=new Date},t.prototype.recreate=function(){var e=this.element,a=e.querySelector(".js-calendar");a&&(e._joomlaCalendar=null,a.parentNode.removeChild(a),new t(e))},t.prototype.updateTime=function(e,a,t){var s=this.date,r=this.date.getLocalDate(this.params.dateType),i=this.date.getLocalMonth(this.params.dateType),l=this.date.getLocalFullYear(this.params.dateType),o=this.inputField.parentNode.parentNode.querySelectorAll(".time-ampm")[0];this.params.time24||(/pm/i.test(o.value)&&e<12?e=parseInt(e)+12:/am/i.test(o.value)&&12==e&&(e=0)),s.setHours(e),s.setMinutes(parseInt(a,10)),s.setSeconds(s.getSeconds()),s.setLocalFullYear(this.params.dateType,l),s.setLocalMonth(this.params.dateType,i),s.setLocalDate(this.params.dateType,r),this.dateClicked=!1,this.callHandler()},t.prototype.setDate=function(e){e.equalsTo(this.date)||(this.date=e,this.processCalendar(this.params.firstDayOfWeek,e))},t.prototype.moveCursorBy=function(e){var a=new Date(this.date);a.setDate(a.getDate()-e),this.setDate(a)},t.prototype.resetSelected=function(e){for(var a=e.options,t=a.length;t--;){var s=a[t];s.selected&&(s.selected=!1)}},t.prototype.callHandler=function(){this.inputField.setAttribute("data-alt-value",this.date.print(this.params.dateFormat,"gregorian",!1)),this.inputField.getAttribute("data-alt-value")&&"0000-00-00 00:00:00"!==this.inputField.getAttribute("data-alt-value")&&(this.inputField.value=this.date.print(this.params.dateFormat,this.params.dateType,!0),"gregorian"!==this.params.dateType&&this.inputField.setAttribute("data-local-value",this.date.print(this.params.dateFormat,this.params.dateType,!0))),this.inputField.value=this.date.print(this.params.dateFormat,this.params.dateType,!0),"function"==typeof this.inputField.onchange&&this.inputField.onchange(),this.dateClicked&&"function"==typeof this.params.onUpdate&&this.params.onUpdate(this),this.dateClicked?this.close():this.processCalendar()},t.prototype.close=function(){this.hide()},t.prototype.show=function(){if(-1!==navigator.appName.indexOf("Internet Explorer")&&(-1===navigator.appVersion.indexOf("MSIE 9")&&-1===navigator.appVersion.indexOf("MSIE 1")&&e.jQuery&&jQuery().chosen))for(var t=this.element.getElementsByTagName("select"),s=0;s<t.length;s++)jQuery(t[s]).chosen("destroy");this.checkInputs(),this.inputField.focus(),this.dropdownElement.style.display="block",this.hidden=!1,a.addEventListener("keydown",this._calKeyEvent,!0),a.addEventListener("keypress",this._calKeyEvent,!0),a.addEventListener("mousedown",this._documentClick,!0);var r=this.element.querySelector(".js-calendar");e.innerHeight<r.getBoundingClientRect().bottom+20&&(r.style.marginTop=-(r.getBoundingClientRect().height+this.inputField.getBoundingClientRect().height)+"px"),this.processCalendar()},t.prototype.hide=function(){a.removeEventListener("keydown",this._calKeyEvent,!0),a.removeEventListener("keypress",this._calKeyEvent,!0),a.removeEventListener("mousedown",this._documentClick,!0),this.dropdownElement.style.display="none",this.hidden=!0},t.prototype._handleDocumentClick=function(e){var t=e.target;if(null!==t&&!t.classList.contains("time"))for(;null!==t&&t!==this.element;t=t.parentNode);if(null===t)return a.activeElement.blur(),this.hide(),s(e)},t.prototype._handleDayMouseDown=function(e){var a=e.currentTarget,t=e.target||e.srcElement;if(!t||!t.hasAttribute("data-action")){if("TD"!==a.nodeName){var r=a.getParent("TD");"TD"===r.nodeName?a=r:(a=a.getParent("TD")).classList.contains("js-calendar")&&(a=a.getElementsByTagName("table")[0])}else if(!t.classList.contains("js-btn")&&!a.classList.contains("day")&&!a.classList.contains("title"))return;if(!a||a.disabled)return!1;if(void 0===a.navtype||300!==a.navtype){50===a.navtype&&(a._current=a.innerHTML),t!==a&&t.parentNode!==a||this.cellClick(a,e);var i=null;void 0!==a.month&&(i=a),void 0!==a.parentNode.month&&(i=a.parentNode);var l=null;if(i)l=new Date(this.date),i.month!==l.getLocalMonth(this.params.dateType)&&(l.setLocalMonth(this.params.dateType,i.month),this.setDate(l),this.dateClicked=!1,this.callHandler());else{var o=null;void 0!==a.year&&(o=t),void 0!==a.parentNode.year&&(o=t.parentNode),o&&(l=new Date(this.date),o.year!==l.getLocalFullYear(this.params.dateType)&&(l.setFullYear(this.params.dateType,o.year),this.setDate(l),this.dateClicked=!1,this.callHandler()))}}return s(e)}},t.prototype.cellClick=function(e,a){var t=!1,s=!1,r=null;if(void 0===e.navtype){this.currentDateEl&&(e.classList.add("selected"),this.currentDateEl=e.caldate,(t=this.currentDateEl===e.caldate)||(this.currentDateEl=e.caldate)),this.date.setLocalDateOnly("gregorian",e.caldate);var i=!(this.dateClicked=!e.otherMonth);this.currentDateEl&&(s=!e.disabled),i&&this.processCalendar()}else{r=new Date(this.date),this.dateClicked=!1;var l=r.getOtherFullYear(this.params.dateType),o=r.getLocalMonth(this.params.dateType);switch(e.navtype){case 400:break;case-2:this.params.compressedHeader||l>this.params.minYear&&r.setOtherFullYear(this.params.dateType,l-1);break;case-1:var n=r.getLocalDate(this.params.dateType);if(o>0)n>(d=r.getLocalMonthDays(this.params.dateType,o-1))&&r.setLocalDate(this.params.dateType,d),r.setLocalMonth(this.params.dateType,o-1);else if(l-- >this.params.minYear){r.setOtherFullYear(this.params.dateType,l),n>(d=r.getLocalMonthDays(this.params.dateType,11))&&r.setLocalDate(this.params.dateType,d),r.setLocalMonth(this.params.dateType,11)}break;case 1:n=r.getLocalDate(this.params.dateType);if(o<11)n>(d=r.getLocalMonthDays(this.params.dateType,o+1))&&r.setLocalDate(this.params.dateType,d),r.setLocalMonth(this.params.dateType,o+1);else if(l<this.params.maxYear){var d;r.setOtherFullYear(this.params.dateType,l+1),n>(d=r.getLocalMonthDays(this.params.dateType,0))&&r.setLocalDate(this.params.dateType,d),r.setLocalMonth(this.params.dateType,0)}break;case 2:this.params.compressedHeader||l<this.params.maxYear&&r.setOtherFullYear(this.params.dateType,l+1)}r.equalsTo(this.date)?0===e.navtype&&(s=t=!0):(this.setDate(r),s=!0)}s&&(this.params.showsTime&&(this.dateClicked=!1),a&&this.callHandler()),e.classList.remove("hilite"),t&&!this.params.showsTime&&(this.dateClicked=!1,a&&this.close())},t.prototype._handleCalKeyEvent=function(e){var a=e.keyCode;if(e.target!==this.inputField||13!==a&&9!==a||this.close(),"rtl"===this.params.direction&&(37===a?a=39:39===a&&(a=37)),32===a&&e.shiftKey&&(e.preventDefault(),this.cellClick(this._nav_now,e),this.close()),27===a&&this.close(),38===a&&this.moveCursorBy(7),40===a&&this.moveCursorBy(-7),37===a&&this.moveCursorBy(1),39===a&&this.moveCursorBy(-1),e.target===this.inputField&&!(a>48||a<57||186===a||189===a||190===a||32===a))return s(e)},t.prototype._create=function(){var e=this,a=this.element,t=r("table"),s=r("div");this.table=t,t.className="table",t.cellSpacing=0,t.cellPadding=0,t.style.marginBottom=0,this.dropdownElement=s,a.appendChild(s),this.params.direction&&(s.style.direction=this.params.direction),s.className="js-calendar",s.style.position="absolute",s.style.boxShadow="0px 0px 70px 0px rgba(0,0,0,0.67)",s.style.minWidth=this.inputField.width,s.style.padding="0",s.style.display="none",s.style.left="auto",s.style.top="auto",s.style.zIndex=1060,s.style.borderRadius="20px",this.wrapper=r("div"),this.wrapper.className="calendar-container",s.appendChild(this.wrapper),this.wrapper.appendChild(t);var i=r("thead",t);i.className="calendar-header";var l=null,o=null,n=this,d=function(a,t,s,i,d,m,p){for(var c in d=d||{},l=r(i=i||"td",o),t&&(m=m?'class="'+m+'"':"",l.colSpan=t),d)l.style[c]=d[c];for(var c in p)l.setAttribute(c,p[c]);return 0!==s&&Math.abs(s)<=2&&(l.className+=" nav"),t&&l.addEventListener("mousedown",e._dayMouseDown,!0),l.calendar=n,l.navtype=s,0!==s&&Math.abs(s)<=2?l.innerHTML="<a "+m+" style='display:inline;padding:2px 6px;cursor:pointer;text-decoration:none;' unselectable='on'>"+a+"</a>":(l.innerHTML=t?"<div unselectable='on'"+m+">"+a+"</div>":a,!t&&m&&(l.className=m)),l};!1===this.params.compressedHeader&&((o=r("tr",i)).className="calendar-head-row",this._nav_py=d("‹",1,-2,"",{"text-align":"center","font-size":"18px","line-height":"18px"},"js-btn btn-prev-year"),this.title=d('<div style="text-align:center;font-size:18px"><span></span></div>',this.params.weekNumbers?6:5,300),this.title.className="title",this._nav_ny=d(" ›",1,2,"",{"text-align":"center","font-size":"18px","line-height":"18px"},"js-btn btn-next-year")),(o=r("tr",i)).className="calendar-head-row",this._nav_pm=d("‹",1,-1,"",{"text-align":"center","font-size":"2em","line-height":"1em"},"js-btn btn-prev-month"),this._nav_month=d('<div style="text-align:center;font-size:1.2em"><span></span></div>',this.params.weekNumbers?6:5,888,"td",{textAlign:"center"}),this._nav_month.className="title",this._nav_nm=d(" ›",1,1,"",{"text-align":"center","font-size":"2em","line-height":"1em"},"js-btn btn-next-month"),(o=r("tr",i)).className=e.params.weekNumbers?"daynames wk":"daynames",this.params.weekNumbers&&((l=r("td",o)).className="day-name wn",l.innerHTML=JoomlaCalLocale.wk);for(var m=7;m>0;--m)l=r("td",o),m||(l.calendar=e);this.firstdayname=this.params.weekNumbers?o.firstChild.nextSibling:o.firstChild;var p=this.params.firstDayOfWeek,c=(l=this.firstdayname,JoomlaCalLocale.weekend);for(m=0;m<7;++m){var h=(m+p)%7;l.classList.add("day-name"),this.params.weekNumbers&&l.classList.add("day-name-week"),m&&(l.calendar=e,l.fdow=h),-1!==c.indexOf(c)&&l.classList.add("weekend"),l.innerHTML=JoomlaCalLocale.shortDays[(m+p)%7],l=l.nextSibling}var u=r("tbody",t);for(this.tbody=u,m=6;m>0;--m){o=r("tr",u),this.params.weekNumbers&&(l=r("td",o));for(var y=7;y>0;--y)(l=r("td",o)).calendar=this,l.addEventListener("mousedown",this._dayMouseDown,!0)}if(this.params.showsTime){(o=r("tr",u)).className="time",(l=r("td",o)).className="time time-title",l.colSpan=1,l.style.verticalAlign="middle",l.innerHTML=" ";var v=r("td",o);v.className="time hours-select",v.colSpan=2;var g=r("td",o);g.className="time minutes-select",g.colSpan=2,function(){function a(a,t,s,i,l){var o,n=r("select",l);n.calendar=e,n.className=a,n.setAttribute("data-chosen",!0),n.style.width="100%",n.navtype=50,n._range=[];for(var d=s;d<=i;++d){var m,p="";d===t&&(p=!0),d<10&&i>=10?(o="0"+d,m=Date.convertNumbers("0")+Date.convertNumbers(d)):(o=""+d,m=""+Date.convertNumbers(d)),n.options.add(new Option(m,o,p,p))}return n}var t=e.date.getHours(),s=e.date.getMinutes(),i=!e.params.time24,n=e.date.getHours()>12;i&&n&&(t-=12);var d=a("time time-hours",t,i?1:0,i?12:23,v),m=a("time time-minutes",s,0,59,g);if((l=r("td",o)).className="time ampm-select",l.colSpan=e.params.weekNumbers?1:2,i){n=Date.parseFieldDate(e.inputField.getAttribute("data-alt-value"),e.params.dateFormat,"gregorian").getHours()>=12;var p=r("select",l);p.className="time-ampm",p.style.width="100%",p.options.add(new Option(JoomlaCalLocale.PM,"pm",!!n||"",!!n||"")),p.options.add(new Option(JoomlaCalLocale.AM,"am",!n||"",!n||"")),p.addEventListener("change",function(a){e.updateTime(a.target.parentNode.parentNode.childNodes[1].childNodes[0].value,a.target.parentNode.parentNode.childNodes[2].childNodes[0].value,a.target.parentNode.parentNode.childNodes[3].childNodes[0].value)},!1)}else l.innerHTML=" ",l.colSpan=e.params.weekNumbers?3:2;d.addEventListener("change",function(a){e.updateTime(a.target.parentNode.parentNode.childNodes[1].childNodes[0].value,a.target.parentNode.parentNode.childNodes[2].childNodes[0].value,a.target.parentNode.parentNode.childNodes[3].childNodes[0].value)},!1),m.addEventListener("change",function(a){e.updateTime(a.target.parentNode.parentNode.childNodes[1].childNodes[0].value,a.target.parentNode.parentNode.childNodes[2].childNodes[0].value,a.target.parentNode.parentNode.childNodes[3].childNodes[0].value)},!1)}()}((o=r("div",this.wrapper)).className="buttons-wrapper btn-group",this._nav_clear=d(JoomlaCalLocale.clear,"",100,"button","","js-btn btn btn-clear",{type:"button","data-action":"clear"}),o.querySelector('[data-action="clear"]').addEventListener("click",function(a){a.preventDefault();for(var t=e.table.querySelectorAll("td"),s=0;s<t.length;s++)if(t[s].classList.contains("selected")){t[s].classList.remove("selected");break}e.inputField.setAttribute("data-alt-value","0000-00-00 00:00:00"),e.inputField.setAttribute("value",""),e.inputField.value="",e.inputField.onchange&&e.inputField.onchange()}),this.params.showsTodayBtn)&&(this._nav_now=d(JoomlaCalLocale.today,"",0,"button","","js-btn btn btn-today",{type:"button","data-action":"today"}),this.wrapper.querySelector('[data-action="today"]').addEventListener("click",function(a){a.preventDefault(),e.date.setLocalDateOnly("gregorian",new Date),e.dateClicked=!0,e.callHandler(),e.close()}));this._nav_exit=d(JoomlaCalLocale.exit,"",999,"button","","js-btn btn btn-exit",{type:"button","data-action":"exit"}),this.wrapper.querySelector('[data-action="exit"]').addEventListener("click",function(a){a.preventDefault(),e.dateClicked||(e.inputField.value?("gregorian"!==e.params.dateType&&e.inputField.setAttribute("data-local-value",e.inputField.value),void 0===e.dateClicked?e.inputField.setAttribute("data-alt-value",Date.parseFieldDate(e.inputField.value,e.params.dateFormat,e.params.dateType).print(e.params.dateFormat,"gregorian",!1)):e.inputField.setAttribute("data-alt-value",e.date.print(e.params.dateFormat,"gregorian",!1))):e.inputField.setAttribute("data-alt-value","0000-00-00 00:00:00"),e.date=Date.parseFieldDate(e.inputField.getAttribute("data-alt-value"),e.params.dateFormat,e.params.dateType)),e.close()}),this.processCalendar()},t.prototype.processCalendar=function(){this.table.style.visibility="hidden";var e=this.params.firstDayOfWeek,a=this.date,t=new Date,s=t.getLocalFullYear(this.params.dateType),r=t.getLocalMonth(this.params.dateType),i=t.getLocalDate(this.params.dateType),l=a.getOtherFullYear(this.params.dateType),o=a.getHours(),n=a.getMinutes(),d=(a.getSeconds(),!this.params.time24);l<this.params.minYear?(l=this.params.minYear,a.setOtherFullYear(this.params.dateType,l)):l>this.params.maxYear&&(l=this.params.maxYear,a.setOtherFullYear(this.params.dateType,l)),this.params.firstDayOfWeek=e,this.date=new Date(a);var m=a.getLocalMonth(this.params.dateType),p=a.getLocalDate(this.params.dateType);a.setLocalDate(this.params.dateType,1);var c=(a.getLocalDay(this.params.dateType)-this.params.firstDayOfWeek)%7;c<0&&(c+=7),a.setLocalDate(this.params.dateType,-c),a.setLocalDate(this.params.dateType,a.getLocalDate(this.params.dateType)+1);for(var h=this.tbody.firstChild,u=this.ar_days=new Array,y=JoomlaCalLocale.weekend,v=parseInt(a.getLocalWeekDays(this.params.dateType)),g=0;g<v;++g,h=h.nextSibling){var b=h.firstChild;this.params.weekNumbers&&(b.className="day wn",b.innerHTML=a.getLocalWeekNumber(this.params.dateType),b=b.nextSibling),h.className=this.params.weekNumbers?"daysrow wk":"daysrow";for(var f,L=!1,C=u[g]=[],w=v+1,T=0;T<w;++T,b=b.nextSibling,a.setLocalDate(this.params.dateType,f+1)){b.className="day",b.style.textAlign="center",f=a.getLocalDate(this.params.dateType);var N=a.getLocalDay(this.params.dateType);b.pos=g<<4|T,C[T]=b;var D=a.getLocalMonth(this.params.dateType)===m;if(D)b.otherMonth=!1,L=!0,b.style.cursor="pointer";else{if(!this.params.showsOthers){b.className+=" emptycell",b.innerHTML=" ",b.disabled=!0;continue}b.className+=" disabled othermonth ",b.otherMonth=!0}b.disabled=!1,b.innerHTML=this.params.debug?f:Date.convertNumbers(f),b.disabled||(b.caldate=new Date(a),D&&f===p&&(b.className+=" selected",this.currentDateEl=b),a.getLocalFullYear(this.params.dateType)===s&&a.getLocalMonth(this.params.dateType)===r&&f===i&&(b.className+=" today"),-1!==y.indexOf(N)&&(b.className+=" weekend"))}L||this.params.showsOthers?h.style.display="":(h.style.display="none",h.className="emptyrow")}if(this.params.showsTime){o>12&&d&&(o-=12),o=o<10?"0"+o:o,n=n<10?"0"+n:n;var F=this.table.querySelector(".time-hours"),k=this.table.querySelector(".time-minutes");if(this.resetSelected(F),this.params.time24?F.value=o:F.value="00"==o?"12":o,this.resetSelected(k),k.value=n,!this.params.time24){var J=new Date(this.inputField.getAttribute("data-alt-value")),A=this.table.querySelector(".time-ampm");J.getHours()>12&&(this.resetSelected(A),A.value="pm")}}if(this.params.compressedHeader){var M=Date.convertNumbers(l.toString());this._nav_month.getElementsByTagName("span")[0].innerHTML=this.params.monthBefore?M+" - "+JoomlaCalLocale.months[m]:JoomlaCalLocale.months[m]+" - "+M}else this._nav_month.getElementsByTagName("span")[0].innerHTML=this.params.debug?m+" "+JoomlaCalLocale.months[m]:JoomlaCalLocale.months[m],this.title.getElementsByTagName("span")[0].innerHTML=this.params.debug?l+" "+Date.convertNumbers(l.toString()):Date.convertNumbers(l.toString());this.table.style.visibility="visible"},t.prototype._bindEvents=function(){var e=this;this.inputField.addEventListener("blur",function(a){var s=t.getCalObject(this)._joomlaCalendar;if("block"!==s.dropdownElement.style.display){if(s){if(s.inputField.value)if(void 0===s.params.dateClicked)if(s.inputField.setAttribute("data-local-value",s.inputField.value),"gregorian"!==s.params.dateType){var r,i=Date.parseFieldDate(s.inputField.value,s.params.dateFormat,s.params.dateType);r=Date.localCalToGregorian(i.getFullYear(),i.getMonth(),i.getDate()),i.setFullYear(r[0]),i.setMonth(r[1]),i.setDate(r[2]),s.inputField.setAttribute("data-alt-value",i.print(s.params.dateFormat,"gregorian",!1))}else s.inputField.setAttribute("data-alt-value",Date.parseFieldDate(s.inputField.value,s.params.dateFormat,s.params.dateType).print(s.params.dateFormat,"gregorian",!1));else s.inputField.setAttribute("data-alt-value",s.date.print(s.params.dateFormat,"gregorian",!1));else s.inputField.setAttribute("data-alt-value","0000-00-00 00:00:00");s.date=Date.parseFieldDate(s.inputField.getAttribute("data-alt-value"),s.params.dateFormat,s.params.dateType)}e.close()}else a.preventDefault()},!0),this.button.addEventListener("click",function(){e.show()},!1)};var s=function(a){return a||(a=e.event),a.preventDefault(),a.stopPropagation(),!1},r=function(e,t){var s;return s=a.createElement(e),void 0!==t&&t.appendChild(s),s},i=function(e){return!isNaN(e)&&(0|(a=parseFloat(e)))===a;var a},l=function(e,a){return(new Date).getLocalFullYear(a)+e};Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var a=this.length>>>0,t=Number(arguments[1])||0;for((t=t<0?Math.ceil(t):Math.floor(t))<0&&(t+=a);t<a;t++)if(t in this&&this[t]===e)return t;return-1}),t.getCalObject=function(e){if(!e)return!1;for(;e.parentNode;)if((e=e.parentNode).classList.contains("field-calendar"))return e;return!1},t.prototype.setAltValue=function(){var e=this.inputField;e.getAttribute("disabled")||(e.value=e.getAttribute("data-alt-value")?e.getAttribute("data-alt-value"):"")},t.onSubmit=function(){if(Joomla=e.Joomla||{},!Joomla.calendarProcessed){Joomla.calendarProcessed=!0;for(var t=a.querySelectorAll(".field-calendar"),s=0;s<t.length;s++){var r=t[s]._joomlaCalendar;r&&r.setAltValue()}}},t.init=function(a,s){e.JoomlaCalLocale=e.JoomlaCalLocale?JoomlaCalLocale:{},JoomlaCalLocale.today=JoomlaCalLocale.today?JoomlaCalLocale.today:"today",JoomlaCalLocale.weekend=JoomlaCalLocale.weekend?JoomlaCalLocale.weekend:[0,6],JoomlaCalLocale.localLangNumbers=JoomlaCalLocale.localLangNumbers?JoomlaCalLocale.localLangNumbers:[0,1,2,3,4,5,6,7,8,9],JoomlaCalLocale.wk=JoomlaCalLocale.wk?JoomlaCalLocale.wk:"wk",JoomlaCalLocale.AM=JoomlaCalLocale.AM?JoomlaCalLocale.AM:"AM",JoomlaCalLocale.PM=JoomlaCalLocale.PM?JoomlaCalLocale.PM:"PM",JoomlaCalLocale.am=JoomlaCalLocale.am?JoomlaCalLocale.am:"am",JoomlaCalLocale.pm=JoomlaCalLocale.pm?JoomlaCalLocale.pm:"pm",JoomlaCalLocale.dateType=JoomlaCalLocale.dateType?JoomlaCalLocale.dateType:"gregorian",JoomlaCalLocale.time=JoomlaCalLocale.time?JoomlaCalLocale.time:"time",JoomlaCalLocale.days=JoomlaCalLocale.days?JoomlaCalLocale.days:'["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]',JoomlaCalLocale.shortDays=JoomlaCalLocale.shortDays?JoomlaCalLocale.shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"],JoomlaCalLocale.months=JoomlaCalLocale.months?JoomlaCalLocale.months:["January","February","March","April","May","June","July","August","September","October","November","December"],JoomlaCalLocale.shortMonths=JoomlaCalLocale.shortMonths?JoomlaCalLocale.shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],JoomlaCalLocale.minYear=JoomlaCalLocale.minYear?JoomlaCalLocale.minYear:1900,JoomlaCalLocale.maxYear=JoomlaCalLocale.maxYear?JoomlaCalLocale.maxYear:2100,JoomlaCalLocale.exit=JoomlaCalLocale.exit?JoomlaCalLocale.exit:"Cancel",JoomlaCalLocale.clear=JoomlaCalLocale.clear?JoomlaCalLocale.clear:"Clear";var r=a._joomlaCalendar;r?r.recreate():new t(a),a&&a.getElementsByTagName("input")[0]&&a.getElementsByTagName("input")[0].form&&!a.getElementsByTagName("input")[0].disabled&&a.getElementsByTagName("input")[0].form.addEventListener("submit",t.onSubmit)},e.JoomlaCalendar=t,a.addEventListener("DOMContentLoaded",function(){var s,r;for(s=a.querySelectorAll(".field-calendar"),r=0;r<s.length;r++)t.init(s[r]);e.jQuery&&jQuery(a).on("subform-row-add",function(e,a){for(s=a.querySelectorAll(".field-calendar"),r=0;r<s.length;r++)t.init(s[r])}),e.Calendar={},Calendar.setup=function(e){if(e.inputField&&a.getElementById(e.inputField)){var s=a.getElementById(e.inputField),r=s.parentNode.querySelectorAll("button")[0];for(var i in e)if(e.hasOwnProperty(i))switch(i){case"ifFormat":r&&r.setAttribute("data-dayformat",e.ifFormat);break;case"firstDay":r&&r.setAttribute("data-firstday",parseInt(e.firstDay));break;case"weekNumbers":r&&r.setAttribute("data-week-numbers","true"===e.weekNumbers||!0===e.weekNumbers?"1":"0");break;case"showOthers":r&&r.setAttribute("data-show-others","true"===e.showOthers||!0===e.showOthers?"1":"0");break;case"showsTime":r&&r.setAttribute("data-show-time","true"===e.showsTime||!0===e.showsTime?"1":"0");break;case"timeFormat":r&&r.setAttribute("data-time-24",parseInt(e.timeFormat))}t.init(s.parentNode.parentNode)}return null}})}(window,document);