CoreFiles by mySites.guru
calendar.js1,415 lines, 50,352 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
0f415105ccdad92fee77693755906b78
sha1
f3b615d92452caec182ef27d82d2471b3e573bfc
sha256
f2f7df6fd75db1181c6e1f850db6fd3382d9a2c644257c25f4f35be07ba2f0ba
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
/**
 * @copyright  (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
!(function(window, document){
	'use strict';

	var JoomlaCalendar = function (element) {

		// Initialize only if the element exists
		if (!element) {
			throw new Error("Calendar setup failed:\n  No valid element found, Please check your code");
		}

		if (typeof Date.parseFieldDate !== 'function') {
			throw new Error("Calendar setup failed:\n  No valid date helper, Please check your code");
		}

		if (element._joomlaCalendar) {
			throw new Error('JoomlaCalendar instance already exists for the element');
		}

		element._joomlaCalendar = this;

		var self = this;

		this.writable   = true;
		this.hidden     = true;
		this.params     = {};
		this.element    = element;
		this.inputField = element.getElementsByTagName('input')[0];
		this.button     = element.getElementsByTagName('button')[0];

		if (!this.inputField) {
			throw new Error("Calendar setup failed:\n  No valid input found, Please check your code");
		}

		// Prepare the parameters
		this.params = {
			debug: false,
			clicked: false,
			element: {style: {display: "none"}},
			writable: true,
		};

		// Localisation strings
		var _t = Joomla.Text._;
		this.strings = {
			today: _t('JLIB_HTML_BEHAVIOR_TODAY', 'Today'),
			wk: _t('JLIB_HTML_BEHAVIOR_WK', 'wk'),
			// ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
			days: ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'],
			// ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
			shortDays: ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'],
			// ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
			months: ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'],
			// ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
			shortMonths: ['JANUARY_SHORT', 'FEBRUARY_SHORT', 'MARCH_SHORT', 'APRIL_SHORT', 'MAY_SHORT', 'JUNE_SHORT',
				'JULY_SHORT', 'AUGUST_SHORT', 'SEPTEMBER_SHORT', 'OCTOBER_SHORT', 'NOVEMBER_SHORT', 'DECEMBER_SHORT',],
			am: _t('JLIB_HTML_BEHAVIOR_AM', 'am'),
			pm: _t('JLIB_HTML_BEHAVIOR_PM', 'pm'),
			exit: _t('JCLOSE', 'Close'),
			clear: _t('JCLEAR', 'Clear')
		};

		// Translate lists of Days, Months
		this.strings.days = this.strings.days.map(function (c){
			return _t(c);
		});
		this.strings.shortDays = this.strings.shortDays.map(function (c){
			return _t(c);
		});
		this.strings.months = this.strings.months.map(function (c){
			return _t(c);
		});
		this.strings.shortMonths = this.strings.shortMonths.map(function (c){
			return _t(c);
		});

		var btn = this.button,
			instanceParams = {
				inputField      : this.inputField,
				dateType        : btn.dataset.dateType || 'gregorian',
				direction       : document.dir ? document.dir : document.getElementsByTagName("html")[0].getAttribute("dir"),
				firstDayOfWeek  : btn.dataset.firstday ? parseInt(btn.dataset.firstday, 10) : 0,
				dateFormat      : btn.dataset.dateFormat || "%Y-%m-%d %H:%M:%S",
				weekend         : [0,6],
				minYear         : 1000,
				maxYear         : 2100,
				time24          : true,
				showsOthers     : true,
				showsTime       : true,
				weekNumbers     : true,
				showsTodayBtn   : true,
				compressedHeader: false,
			};

		if ('showOthers' in btn.dataset) {
			instanceParams.showsOthers = parseInt(btn.dataset.showOthers, 10) === 1;
		}

		if ('weekNumbers' in btn.dataset) {
			instanceParams.weekNumbers = parseInt(btn.dataset.weekNumbers, 10) === 1;
		}

		if ('onlyMonthsNav' in btn.dataset) {
			instanceParams.compressedHeader = parseInt(btn.dataset.onlyMonthsNav, 10) === 1;
		}

		if ('time24' in btn.dataset) {
			instanceParams.time24 = parseInt(btn.dataset.time24 , 10) === 24;
		}

		if ('showTime' in btn.dataset) {
			instanceParams.showsTime = parseInt(btn.dataset.showTime, 10) === 1;
		}

		if ('todayBtn' in btn.dataset) {
			instanceParams.showsTodayBtn = parseInt(btn.dataset.todayBtn, 10) === 1;
		}

		// Merge the parameters
		for (var param in instanceParams) {
			this.params[param] = instanceParams[param];
		}

		// Evaluate the min year
		if (btn.dataset.minYear) {
			self.params.minYear = getBoundary(parseInt(btn.dataset.minYear, 10), self.params.dateType);
		}
		// Evaluate the max year
		if (btn.dataset.maxYear) {
			self.params.maxYear = getBoundary(parseInt(btn.dataset.maxYear, 10), self.params.dateType);
		}
		// Evaluate the weekend days
		if (btn.dataset.weekend) {
			self.params.weekend = btn.dataset.weekend.split(',').map(function(item) { return parseInt(item, 10); });
		}

		// Legacy thing, days for RTL is reversed
		if (this.params.direction === 'rtl') {
			this.strings.days = this.strings.days.reverse();
			this.strings.shortDays = this.strings.shortDays.reverse();
		}

		// Other calendar may have a different order for months
		this.strings.months = Date.monthsToLocalOrder(this.strings.months, this.params.dateType);
		this.strings.shortMonths = Date.monthsToLocalOrder(this.strings.shortMonths, this.params.dateType);

		// Event handler need to define here, to be able access in current context
		this._dayMouseDown = function(event) {
			return self._handleDayMouseDown(event);
		};
		this._calKeyEvent = function(event) {
			return self._handleCalKeyEvent(event);
		};
		this._documentClick = function(event) {
			return self._handleDocumentClick(event);
		};
		this._focusOut = function (event) {
			return self._handleFocusOut(event);
		};

		// Set it up
		this.checkInputs();

		// For the fields with readonly tag calendar will not initiate fully
		if (this.inputField.getAttribute('readonly')) {
			return;
		}

		this._create();
		this._bindEvents();
	};

	JoomlaCalendar.prototype.checkInputs = function () {
		// Get the date from the input
		var inputAltValueDate = Date.parseFieldDate(this.inputField.getAttribute('data-alt-value'), this.params.dateFormat, 'gregorian', this.strings, false);

		if (this.inputField.value !== '') {
			this.date = inputAltValueDate;
			this.inputField.value = inputAltValueDate.print(this.params.dateFormat, this.params.dateType, true, this.strings);
		} else {
			this.date = new Date();
		}
	};

	/** Removes the calendar object from the DOM tree and destroys it and then recreates it. */
	JoomlaCalendar.prototype.recreate = function () {
		var element = this.element, el = element.querySelector('.js-calendar');
		if (el) {
			element._joomlaCalendar = null;
			el.parentNode.removeChild(el);
			new JoomlaCalendar(element);
		}
	};

	/** Time Control */
	JoomlaCalendar.prototype.updateTime = function (hours, mins, secs) {
		var self = this,
			date = self.date;

		var d = self.date.getLocalDate(self.params.dateType),
			m = self.date.getLocalMonth(self.params.dateType),
			y = self.date.getLocalFullYear(self.params.dateType),
			ampm = this.inputField.parentNode.parentNode.querySelectorAll('.time-ampm')[0];

		if (!self.params.time24) {
			if (/pm/i.test(ampm.value) && hours < 12) {
				hours = parseInt(hours) + 12;
			} else if (/am/i.test(ampm.value) && hours == 12) {
				hours = 0;
			}
		}

		date.setHours(hours);
		date.setMinutes(parseInt(mins, 10));
		date.setSeconds(date.getSeconds());
		date.setLocalFullYear(self.params.dateType, y);
		date.setLocalMonth(self.params.dateType, m);
		date.setLocalDate(self.params.dateType, d);
		self.dateClicked = false;

		this.callHandler();
	};

	/** Method to set the date to the given date object */
	JoomlaCalendar.prototype.setDate = function (date) {
		if (!date.equalsTo(this.date)) {
			this.date = date;
			this.processCalendar(this.params.firstDayOfWeek, date);
		}
	};

	/** Method to set the current date by a number, step */
	JoomlaCalendar.prototype.moveCursorBy = function (step) {
		var date = new Date(this.date);
		date.setDate(date.getDate() - step);
		if (!date.equalsTo(this.date)) {
			this.date = date;
			this.callHandler();
		}
	};

	/** Reset select element */
	JoomlaCalendar.prototype.resetSelected = function (element) {
		var options = element.options;
		var i = options.length;
		while (i--) {
			var current = options[i];
			if (current.selected) {
				current.selected = false;
			}
		}
	};

	/** Method to set the value for the input field */
	JoomlaCalendar.prototype.callHandler = function () {
		/** Output the date **/
		this.inputField.setAttribute('data-alt-value', this.date.print(this.params.dateFormat, 'gregorian', false, this.strings));

		if (this.inputField.getAttribute('data-alt-value') && this.inputField.getAttribute('data-alt-value') !== '0000-00-00 00:00:00') {
			this.inputField.value = this.date.print(this.params.dateFormat, this.params.dateType, true, this.strings);
			if (this.params.dateType !== 'gregorian') {
				this.inputField.setAttribute('data-local-value', this.date.print(this.params.dateFormat, this.params.dateType, true, this.strings));
			}
		}
		this.inputField.value = this.date.print(this.params.dateFormat, this.params.dateType, true, this.strings);

		if (this.dateClicked && typeof this.params.onUpdate === "function") {
			this.params.onUpdate(this);
		}

		this.inputField.dispatchEvent(new CustomEvent('change', {bubbles: true, cancelable: true}));

		if (this.dateClicked) {
			this.close();
		} else {
			this.processCalendar();
		}
	};

	/** Method to close/hide the calendar */
	JoomlaCalendar.prototype.close = function () {
		this.hide();
	};

	/** Method to show the calendar. */
	JoomlaCalendar.prototype.show = function () {
		this.checkInputs();
		this.inputField.focus();
		this.dropdownElement.classList.add('open');
		this.dropdownElement.removeAttribute('hidden');
		this.hidden = false;

		document.addEventListener("keydown", this._calKeyEvent, true);
		document.addEventListener("mousedown", this._documentClick, true);
		document.addEventListener("focusout", this._focusOut, true);

		/** Move the calendar to top position if it doesn't fit below. */
		var containerTmp = this.element.querySelector('.js-calendar');

		if (window.innerHeight < containerTmp.getBoundingClientRect().bottom + 20) {
			containerTmp.style.marginTop = - (containerTmp.getBoundingClientRect().height + this.inputField.getBoundingClientRect().height) + "px";
		} else {
			containerTmp.style.marginTop = 'initial';
		}

		this.processCalendar();
	};

	/** Method to hide the calendar. */
	JoomlaCalendar.prototype.hide = function () {
		document.removeEventListener("keydown", this._calKeyEvent, true);
		document.removeEventListener("mousedown", this._documentClick, true);
		document.removeEventListener("focusout", this._focusOut, true);

		this.dropdownElement.classList.remove('open');
		this.dropdownElement.setAttribute('hidden', '');
		this.hidden = true;
	};

	/** Method to catch clicks outside of the calendar (used as close call) */
	JoomlaCalendar.prototype._handleDocumentClick = function (ev) {
		var el = ev.target;

		if (el !== null && !el.classList.contains('time')) {
			for (; el !== null && el !== this.element; el = el.parentNode);
		}

		if (el === null) {
			document.activeElement.blur();
			this.hide();
			return stopCalEvent(ev);
		}
	};

	JoomlaCalendar.prototype._handleFocusOut = function (ev) {
		var relatedTarget = ev.relatedTarget;

		// Focus is still somewhere inside the calendar field.
		if (relatedTarget && this.element.contains(relatedTarget)) {
			return;
		}

		this.hide();
	};

	/** Method to handle mouse click events (menus, buttons) **/
	JoomlaCalendar.prototype._handleDayMouseDown = function (ev) {
		var self = this,
			el = ev.currentTarget,
			target = ev.target || ev.srcElement;

		if (target && target.hasAttribute('data-action')) {
			return;
		}

		if (el.nodeName !== 'TD') {                         // A bootstrap inner button was pressed?
			var testel = el.getParent('TD');
			if (testel.nodeName === 'TD') {                 // Yes so use that element's td
				el = testel;
			} else {                                        // No - try to find the table this way
				el = el.getParent('TD');
				if (el.classList.contains('js-calendar')) {
					el = el.getElementsByTagName('table')[0];
				}
			}
		} else {                                            // Check that doesn't have a button and is not a day td
			if (!(target.classList.contains('js-btn')) && !el.classList.contains('day') && !el.classList.contains('title')) {
				return;
			}
		}

		if (!el || el.disabled) {
			return false;
		}

		if (typeof el.navtype === "undefined" || el.navtype !== 300) {
			if (el.navtype === 50) { el._current = el.innerHTML; }

			if (target === el || target.parentNode === el) { self.cellClick(el, ev); }

			var mon = null;
			if (typeof el.month !== "undefined") {
				mon = el;
			}
			if (typeof el.parentNode.month !== "undefined") {
				mon = el.parentNode;
			}
			var date = null;
			if (mon) {
				date = new Date(self.date);
				if (mon.month !== date.getLocalMonth(self.params.dateType)) {
					date.setLocalMonth(self.params.dateType, mon.month);
					self.setDate(date);
					self.dateClicked = false;
					this.callHandler();
				}
			} else {
				var year = null;
				if (typeof el.year !== "undefined") {
					year = target;
				}
				if (typeof el.parentNode.year !== "undefined") {
					year = target.parentNode;
				}
				if (year) {
					date = new Date(self.date);
					if (year.year !== date.getLocalFullYear(self.params.dateType)) {
						date.setFullYear(self.params.dateType, year.year);
						self.setDate(date);
						self.dateClicked = false;
						this.callHandler();
					}
				}
			}
		}

		return stopCalEvent(ev);
	};

	/** Method to handle mouse click events (dates) **/
	JoomlaCalendar.prototype.cellClick = function (el, ev) {
		var self = this,
			closing = false,
			newdate = false,
			date = null;

		if (typeof el.navtype === "undefined") {
			if (self.currentDateEl) {
				el.classList.add("selected");
				self.currentDateEl = el.caldate;
				closing = (self.currentDateEl === el.caldate);
				if (!closing) {
					self.currentDateEl = el.caldate;
				}
			}
			self.date.setLocalDateOnly('gregorian', el.caldate);
			var other_month = !(self.dateClicked = !el.otherMonth);
			if (self.currentDateEl) { newdate = !el.disabled; }
			if (other_month) {
				this.processCalendar();
			}
		} else {
			date = new Date(self.date);
			self.dateClicked = false;
			var year = date.getOtherFullYear(self.params.dateType), mon = date.getLocalMonth(self.params.dateType);
			switch (el.navtype) {
				case 400:
					break;
				case -2:                                                                             // Prev year
					if (!self.params.compressedHeader) {
						if (year > self.params.minYear) {
							date.setOtherFullYear(self.params.dateType, year - 1);
						}
					}
					break;
				case -1:                                                                             // Prev month
					var day = date.getLocalDate(self.params.dateType);
					if (mon > 0) {
						var max = date.getLocalMonthDays(self.params.dateType, mon - 1);
						if (day > max) {
							date.setLocalDate(self.params.dateType, max);
						}
						date.setLocalMonth(self.params.dateType, mon - 1);
					} else if (year-- > self.params.minYear) {
						date.setOtherFullYear(self.params.dateType, year);
						var max = date.getLocalMonthDays(self.params.dateType, 11);
						if (day > max) {
							date.setLocalDate(self.params.dateType, max);
						}
						date.setLocalMonth(self.params.dateType, 11);
					}
					break;
				case 1:                                                                             // Next month
					var day = date.getLocalDate(self.params.dateType);
					if (mon < 11) {
						var max = date.getLocalMonthDays(self.params.dateType, mon + 1);
						if (day > max) {
							date.setLocalDate(self.params.dateType, max);
						}
						date.setLocalMonth(self.params.dateType, mon + 1);
					} else if (year < self.params.maxYear) {
						date.setOtherFullYear(self.params.dateType, year + 1);
						var max = date.getLocalMonthDays(self.params.dateType, 0);
						if (day > max) {
							date.setLocalDate(self.params.dateType, max);
						}
						date.setLocalMonth(self.params.dateType, 0);
					}
					break;
				case 2:                                                                             // Next year
					if (!self.params.compressedHeader)
						if (year < self.params.maxYear) {
							date.setOtherFullYear(self.params.dateType, year + 1);
						}
					break;
				case 0:                                                                             // Today
					break;
			}

			if (!date.equalsTo(self.date)) {
				this.setDate(date);
				newdate = true;
			} else if (el.navtype === 0) {
				newdate = closing = true;
			}
		}

		if (newdate) {
			if (self.params.showsTime) {
				this.dateClicked = false;
			}
			ev && this.callHandler();
		}

		el.classList.remove("hilite");

		if (closing && !self.params.showsTime) {
			self.dateClicked = false;
			ev && this.close();
		}
	};

	/** Method to handle keyboard click events **/
	JoomlaCalendar.prototype._handleCalKeyEvent = function (ev) {
		var self = this,
			code = ev.code;

		// Tab from the calendar input moves into the time controls.
		if (ev.target === this.inputField && (code === 'Enter' || code === 'Tab')) {
			if (code === 'Tab' && !ev.shiftKey && self.params.showsTime) {
				var hoursEl = this.table.querySelector('.time-hours');

				if (hoursEl) {
					ev.preventDefault();
					hoursEl.focus();
					return;
				}
			}

			this.close();
		}

		// Handle keyboard navigation and focus within the time controls.
		if (
			ev.target.matches &&
			ev.target.matches('.time-hours, .time-minutes')
		) {
			// Shift+Tab from Hours returns to the calendar input.
			if (code === 'Tab' && ev.shiftKey && ev.target.matches('.time-hours')) {
				ev.preventDefault();
				this.inputField.focus();
				return;
			}

			// Let the time selects handle arrow keys and Tab natively.
			if (
				code === 'ArrowUp' ||
				code === 'ArrowDown' ||
				code === 'ArrowLeft' ||
				code === 'ArrowRight' ||
				code === 'Tab'
			) {
				return;
			}
		}

		if (self.params.direction === 'rtl') {
			if (code === 'ArrowLeft') {
				code = 'ArrowRight';
			} else if (code === 'ArrowRight') {
				code = 'ArrowLeft';
			}
		}

		// Select the currently highlighted date.
		if (code === 'Enter' && self.currentDateEl) {
			self.cellClick(self.currentDateEl, ev);
			return;
		}

		if (ev.shiftKey && code === 'Space') {
			ev.preventDefault();
			this.cellClick(self._nav_now, ev);
			self.close();
		}

		if (code === 'Escape') {
			this.close();
		}

		if (code === 'ArrowUp') {
			this.moveCursorBy(7);
		}

		if (code === 'ArrowDown') {
			this.moveCursorBy(-7);
		}

		if (code === 'ArrowLeft') {
			this.moveCursorBy(1);
		}

		if (code === 'ArrowRight') {
			this.moveCursorBy(-1);
		}
	};

	/** Method to create the html structure of the calendar */
	JoomlaCalendar.prototype._create = function () {
		var self   = this,
			parent = this.element,
			table  = createElement("table"),
			div    = createElement("div");

		this.table = table;
		table.className = 'table';
		table.style.marginBottom = 0;

		this.dropdownElement = div;
		parent.appendChild(div);

		if (this.params.direction) {
			div.style.direction = this.params.direction;
		}

		div.className = 'js-calendar';
		div.style.position = "absolute";
		div.style.boxShadow = "0 0 70px 0 rgba(0,0,0,0.67)";
		div.style.minWidth = this.inputField.width;
		div.style.padding = '0';
		div.setAttribute('hidden', '');
		div.style.left = "auto";
		div.style.top = "auto";
		div.style.zIndex = 1060;
		div.style.borderRadius = "20px";

		this.wrapper = createElement('div');
		this.wrapper.className = 'calendar-container';
		div.appendChild(this.wrapper);
		this.wrapper.appendChild(table);

		var thead = createElement("thead", table);
		thead.className = 'calendar-header';

		var cell = null,
			row  = null,
			cal  = this,
			hh   = function (text, cs, navtype, node, styles, classes, attributes) {
				node = node ? node : "td";
				styles = styles ? styles : {};
				cell = createElement(node, row);
				if (cs) {
					classes = classes ? 'class="' + classes + '"' : '';
				cell.colSpan = cs;
				}

				for (var key in styles) {
					cell.style[key] = styles[key];
				}
				for (var key in attributes) {
					cell.setAttribute(key, attributes[key]);
				}
				if (navtype !== 0 && Math.abs(navtype) <= 2) {
					cell.className += " nav";
				}

				if (cs) {
					cell.addEventListener("mousedown", self._dayMouseDown, true);
				}

				cell.calendar = cal;
				cell.navtype = navtype;
				if (navtype !== 0 && Math.abs(navtype) <= 2) {
					cell.innerHTML = Joomla.sanitizeHtml("<a " + classes + " style='display:inline;padding:2px 6px;cursor:pointer;text-decoration:none;' unselectable='on'>" + text + "</a>");
				} else {
					cell.innerHTML = cs ? Joomla.sanitizeHtml("<div unselectable='on'" + classes + ">" + text + "</div>") : Joomla.sanitizeHtml(text);
					if (!cs && classes) {
						cell.className = classes;
					}
				}
				return cell;
			};

		if (this.params.compressedHeader === false) {                                                        // Head - year
			row = createElement("tr", thead);
			row.className = "calendar-head-row";
			this._nav_py = hh("&lsaquo;", 1, -2, '', {"text-align": "center", "font-size": "18px", "line-height": "18px"}, 'js-btn btn-prev-year');                   // Previous year button
			this.title = hh('<div style="text-align:center;font-size:18px"><span></span></div>', this.params.weekNumbers ? 6 : 5, 300);
			this.title.className = "title title-year";
			this._nav_ny = hh(" &rsaquo;", 1, 2, '', {"text-align": "center", "font-size": "18px", "line-height": "18px"}, 'js-btn btn-next-year');                   // Next year button
		}

		row = createElement("tr", thead);                                                                   // Head - month
		row.className = "calendar-head-row";
		this._nav_pm = hh("&lsaquo;", 1, -1, '', {"text-align": "center", "font-size": "2em", "line-height": "1em"}, 'js-btn btn-prev-month');                       // Previous month button
		this._nav_month = hh('<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 title-month";
		this._nav_nm = hh(" &rsaquo;", 1, 1, '', {"text-align": "center", "font-size": "2em", "line-height": "1em"}, 'js-btn btn-next-month');                       // Next month button

		row = createElement("tr", thead);                                                                   // day names
		row.className = self.params.weekNumbers ? "daynames wk" : "daynames";
		if (this.params.weekNumbers) {
			cell = createElement("td", row);
			cell.className = "day-name wn";
			cell.textContent = self.strings.wk;
		}
		for (var i = 7; i > 0; --i) {
			cell = createElement("td", row);
			if (!i) {
				cell.calendar = self;
			}
		}
		this.firstdayname = (this.params.weekNumbers) ? row.firstChild.nextSibling : row.firstChild;

		// Check if the direction is 'rtl' and reverse the shortDays array if true
		if (this.params.direction === 'rtl') {
			this.strings.shortDays.reverse();
		}

		var fdow = this.params.firstDayOfWeek,
			cell = this.firstdayname,
			weekend = this.params.weekend;

		for (var i = 0; i < 7; ++i) {
			var realday = (i + fdow) % 7;
			cell.classList.add("day-name");
			this.params.weekNumbers ? cell.classList.add('day-name-week') : '';

			if (i) {
				cell.calendar = self;
				cell.fdow = realday;
			}
			if (weekend.indexOf(weekend) !== -1) {
				cell.classList.add("weekend");
			}

			cell.textContent = this.strings.shortDays[(i + fdow) % 7];
			cell = cell.nextSibling;
		}

		var tbody = createElement("tbody", table);
		this.tbody = tbody;
		for (i = 6; i > 0; --i) {
			row = createElement("tr", tbody);
			if (this.params.weekNumbers) {
				cell = createElement("td", row);
			}

			for (var j = 7; j > 0; --j) {
				cell = createElement("td", row);
				cell.calendar = this;
				cell.addEventListener("mousedown", this._dayMouseDown, true);
			}
		}

		if (this.params.showsTime) {
			row = createElement("tr", tbody);
			row.className = "time";
			row.classList.add('calendar-time-row'); // New: mark row for LTR

			var cell = createElement("td", row);
			cell.className = "time time-title";
			cell.colSpan = 1;
			cell.style.verticalAlign = 'middle';
			cell.innerHTML = " ";

			var hoursCell = createElement("td", row);
			hoursCell.className = "time hours-select";
			hoursCell.colSpan = self.params.time24 ? 3 : 2;

			var minutesCell = createElement("td", row);
			minutesCell.className = "time minutes-select";
			minutesCell.colSpan = self.params.time24 ? 3 : 2;

			// Swap DOM order in RTL so visual order remains Hours | Minutes
			if (this.params.direction === 'rtl') {
				row.insertBefore(minutesCell, hoursCell);
			}

			(function () {
				function makeTimePart(className, selected, range_start, range_end, cellTml) {
					var part = createElement("select", cellTml), num;
					part.calendar  = self;
					part.className =  className;
					part.setAttribute('data-chosen', true); // avoid Chosen, hack
					part.style.width = '100%';
					part.navtype = 50;
					part._range = [];
					for (var i = range_start; i <= range_end; ++i) {
						var txt, selAttr = '';
						if (i === selected) {
							selAttr = true;
						}
						if (i < 10 && range_end >= 10) {
							num = '0' + i;
							txt = Date.convertNumbers('0') + Date.convertNumbers(i);
						} else {
							num = '' + i;
							txt = '' + Date.convertNumbers(i);
						}
						part.options.add(new Option(txt, num, selAttr, selAttr));
					}
					return part;
				}
				var hrs  = self.date.getHours(),
					mins = self.date.getMinutes(),
					t12  = !self.params.time24,
					pm   = (self.date.getHours() > 12);

				if (t12 && pm) {
					hrs -= 12;
				}

				var H = makeTimePart("time time-hours form-control form-select", hrs, t12 ? 1 : 0, t12 ? 12 : 23, hoursCell),
					M = makeTimePart("time time-minutes form-control form-select", mins, 0, 59, minutesCell),
					AP = null;


				if (t12) {
					cell = createElement("td", row);
					cell.className = "time ampm-select";
					cell.colSpan = self.params.weekNumbers ? 3 : 2;

					var selAttr = true,
						altDate = Date.parseFieldDate(self.inputField.getAttribute('data-alt-value'), self.params.dateFormat, 'gregorian', self.strings, false);
					pm = (altDate.getHours() >= 12);

					var part = createElement("select", cell);
					part.className = "time-ampm";
					part.style.width = '100%';
					part.options.add(new Option(self.strings.pm, "pm", pm ? selAttr : '', pm ? selAttr : ''));
					part.options.add(new Option(self.strings.am, "am", pm ? '' : selAttr, pm ? '' : selAttr));
					AP = part;

					// AM/PM change handler — apply the same RTL swap as H/M
					AP.addEventListener("change", function (event) {
						var c = event.target.parentNode.parentNode.childNodes;
						if (self.params.direction === 'rtl') {
							self.updateTime(c[2].childNodes[0].value, c[1].childNodes[0].value, c[3].childNodes[0].value);
						} else {
							self.updateTime(c[1].childNodes[0].value, c[2].childNodes[0].value, c[3].childNodes[0].value);
						}
					}, false);
				} else if (self.params.weekNumbers) {
					cell = createElement("td", row);
					cell.innerHTML = "&#160;";
					cell.colSpan = 1;
				}

				if (self.params.weekNumbers) {
					// Since the DOM order is reversed in RTL, we must reverse the order of child nodes.
					if (self.params.direction === 'rtl') {
						H.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[3].childNodes[0].value);
						}, false);
						M.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[3].childNodes[0].value);
						}, false);
					} else {
						H.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[3].childNodes[0].value);
						}, false);
						M.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[3].childNodes[0].value);
						}, false);
					}
				} else {
					// Since the DOM order is reversed in RTL, we must reverse the order of child nodes.
					if (self.params.direction === 'rtl') {
						H.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[1].childNodes[0].value);
						}, false);
						M.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[2].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[1].childNodes[0].value);
						}, false);
					} else {
						H.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[2].childNodes[0].value);
						}, false);
						M.addEventListener("change", function (event) {
							self.updateTime(event.target.parentNode.parentNode.childNodes[1].childNodes[0].value,
								event.target.parentNode.parentNode.childNodes[2].childNodes[0].value);
						}, false);
					}
				}
			})();
		}

		row = createElement("div", this.wrapper);
		row.className = "buttons-wrapper btn-group";

		this._nav_clear = hh(this.strings.clear, '', 100, 'button', '', 'js-btn btn btn-clear', {"type": "button", "data-action": "clear"});

			var cleara = row.querySelector('[data-action="clear"]');
			cleara.addEventListener("click", function (e) {
				e.preventDefault();
				var days = self.table.querySelectorAll('td');
				for (var i = 0; i < days.length; i++) {
					if (days[i].classList.contains('selected')) {
						days[i].classList.remove('selected');
						break;
					}
				}
				self.inputField.setAttribute('data-alt-value', "0000-00-00 00:00:00");
				self.inputField.setAttribute('value', '');
				self.inputField.value = '';
				self.inputField.dispatchEvent(new CustomEvent('change', {bubbles: true, cancelable: true}));
			});

		if (this.params.showsTodayBtn) {
			this._nav_now = hh(this.strings.today, '', 0, 'button', '', 'js-btn btn btn-today', {"type": "button", "data-action": "today"});

			var todaya = this.wrapper.querySelector('[data-action="today"]');
			todaya.addEventListener('click', function (e) {
				e.preventDefault();
				self.date.setLocalDateOnly('gregorian', new Date());                                  // TODAY
				self.dateClicked = true;
				self.callHandler();
				self.close();
			});
		}

		this._nav_exit = hh(this.strings.exit, '', 999, 'button', '', 'js-btn btn btn-exit', {"type": "button", "data-action": "exit"});
		var exita = this.wrapper.querySelector('[data-action="exit"]');
		exita.addEventListener('click', function (e) {
			e.preventDefault();
			if (!self.dateClicked) {
				if (self.inputField.value) {
					if (self.params.dateType !== 'gregorian') {
						self.inputField.setAttribute('data-local-value', self.inputField.value);
					}
					if (typeof self.dateClicked === 'undefined') {
						// Value needs to be validated. Just like in the "input" and "blur" listeners,
						// the value displayed to the user may be in local calendar (eg. Jalali)
						// and must go through Date.localCalToGregorian() before being stored,
						// otherwise the raw local y/m/d digits get saved mislabeled as a Gregorian date.
						var date = Date.parseFieldDate(self.inputField.value, self.params.dateFormat, self.params.dateType, self.strings, false);

						if (self.params.dateType !== 'gregorian') {
							// Use date.rawYear/rawMonth/rawDay: custom, non-native properties.
							// See the "input" listener for why they're needed instead
							// of getFullYear()/getMonth()/getDate(), and why +1/-1.
							var ndate = Date.localCalToGregorian(date.rawYear, date.rawMonth + 1, date.rawDay);

							// Rebuild atomically - see the "input" listener for why
							// setFullYear()/setMonth()/setDate() in sequence is unsafe here.
							date = new Date(ndate[0], ndate[1] - 1, ndate[2], date.getHours(), date.getMinutes(), date.getSeconds());
						}
						self.inputField.setAttribute('data-alt-value', date.print(self.params.dateFormat, 'gregorian', false, self.strings));
					} else {
						self.inputField.setAttribute('data-alt-value', self.date.print(self.params.dateFormat, 'gregorian', false, self.strings));
					}
				} else {
					self.inputField.setAttribute('data-alt-value', '0000-00-00 00:00:00');
				}
				self.date = Date.parseFieldDate(self.inputField.getAttribute('data-alt-value'), self.params.dateFormat, self.params.dateType, self.strings, false);
			}
			self.close();
		});

		// Validate the date and time when they are manually entered in the input field.
		self.inputField.addEventListener('input', function (e) {
			if (self.inputField.value) {
				if (self.params.dateType !== 'gregorian') {
					self.inputField.setAttribute('data-local-value', self.inputField.value);
					// We need to transform the date for the data-alt-value.
					// ## Strict parsing ##
					// While the user is still typing, the string is necessarily incomplete for most keystrokes.
					// So we bail out until we have a genuinely complete, valid date, leaving data-alt-value untouched.
					var date = Date.parseFieldDate(self.inputField.value, self.params.dateFormat, self.params.dateType, self.strings, true);

					if (!date) {
						return;
					}

					// ## Custom Properties ##
					// Use date.rawYear/rawMonth/rawDay, custom, non-native properties (see non-gregorian local calendar date-helper.js) -
					// Do not use date.getFullYear()/getMonth()/getDate(): the Date object built by parseFieldDate() may already
					// have silently rolled over if the typed day doesn't exist in the *native Gregorian* month at that index
					// (e.g. Jalali day 31 landing on native April, which only have 30 days).
					// ## Month +1/-1 ##
					// Date.localCalToGregorian() (JalaliDate.jalaliToGregorian) expects a 1-indexed month
					// (rawMonth is 0-indexed like getMonth()), and its returned month is 1-indexed too,
					// while setMonth() (the Date constructor) expects 0-indexed.
					// Forgetting either conversion causes an off-by-one day (or month) error.
					var ndate = Date.localCalToGregorian(date.rawYear, date.rawMonth + 1, date.rawDay);

					// Rebuild the Date atomically (year/month/day in one constructor call) instead of calling
					// setFullYear()/setMonth()/setDate() in sequence:
					// mutating month before day meant the OLD day (e.g. 31) could briefly clash with
					// the NEW month (e.g. a 30-day month), causing JS to silently roll over into the
					// following month before setDate() even ran (e.g. day 31 becomes day 30 of the next month).
					date = new Date(ndate[0], ndate[1] - 1, ndate[2], date.getHours(), date.getMinutes(), date.getSeconds());
					self.inputField.setAttribute('data-alt-value', date.print(self.params.dateFormat, 'gregorian', false, self.strings));
				} else {
					// Value needs to be validated
					var gdate = Date.parseFieldDate(self.inputField.value, self.params.dateFormat, self.params.dateType, self.strings, true);
					if (!gdate) {
						return;
					}
					self.inputField.setAttribute('data-alt-value', gdate.print(self.params.dateFormat, 'gregorian', false, self.strings));
				}
			} else {
				self.inputField.setAttribute('data-alt-value', '0000-00-00 00:00:00');
			}
			self.date = Date.parseFieldDate(self.inputField.getAttribute('data-alt-value'), self.params.dateFormat, self.params.dateType, self.strings, false);

			// Keep the picker's day grid and time selectors (hours/minutes/am-pm)
			// in sync with what was just typed, without touching inputField.value
			// (processCalendar() only redraws the picker, it never rewrites the input).
			if (!self.hidden) {
				self.processCalendar();
			}
		});

		this.processCalendar();
	};

	/** Method to append numbers to the calendar table */
	JoomlaCalendar.prototype.processCalendar = function () {
		this.table.style.visibility = "hidden";

		var firstDayOfWeek = this.params.firstDayOfWeek,
			date  = this.date,
			today = new Date(),
			TY    = today.getLocalFullYear(this.params.dateType),
			TM    = today.getLocalMonth(this.params.dateType),
			TD    = today.getLocalDate(this.params.dateType),
			year  = date.getOtherFullYear(this.params.dateType),
			hrs   = date.getHours(),
			mins  = date.getMinutes(),
			secs  = date.getSeconds(),
			t12   = !this.params.time24;

		if (year < this.params.minYear) {                                                                   // Check min,max year
			year = this.params.minYear;
			date.setOtherFullYear(this.params.dateType, year);
		} else if (year > this.params.maxYear) {
			year = this.params.maxYear;
			date.setOtherFullYear(this.params.dateType, year);
		}

		this.params.firstDayOfWeek = firstDayOfWeek;
		this.date = new Date(date);

		var month = date.getLocalMonth(this.params.dateType);
		var mday  = date.getLocalDate(this.params.dateType);

		// Compute the first day that would actually be displayed in the calendar, even if it's from the previous month.
		date.setLocalDate(this.params.dateType, 1);
		var day1 = (date.getLocalDay(this.params.dateType) - this.params.firstDayOfWeek) % 7;

		if (day1 < 0) {
			day1 += 7;
		}

		date.setLocalDate(this.params.dateType, - day1);
		date.setLocalDate(this.params.dateType, date.getLocalDate(this.params.dateType) + 1);

		var row = this.tbody.firstChild,
			ar_days = this.ar_days = new Array(),
			weekend = this.params.weekend,
			monthDays = parseInt(date.getLocalWeekDays(this.params.dateType));

		/** Fill the table **/
		for (var i = 0; i < monthDays; ++i, row = row.nextSibling) {
			var cell = row.firstChild;
			if (this.params.weekNumbers) {
				cell.className = "day wn";
				cell.textContent = date.getLocalWeekNumber(this.params.dateType);
				cell = cell.nextSibling;
			}

			row.className = this.params.weekNumbers ? "daysrow wk" : "daysrow";
			var hasdays = false, iday,
				dpos = ar_days[i] = [],
				totalDays = monthDays + 1;

			for (var j = 0; j < totalDays; ++j, cell = cell.nextSibling, date.setLocalDate(this.params.dateType, iday + 1)) {
				cell.className = "day";
				cell.style['textAlign'] = 'center';
				iday = date.getLocalDate(this.params.dateType);
				var wday = date.getLocalDay(this.params.dateType);
				cell.pos = i << 4 | j;
				dpos[j] = cell;
				var current_month = (date.getLocalMonth(this.params.dateType) === month);
				if (!current_month) {
					if (this.params.showsOthers) {
						cell.className += " disabled othermonth ";
						cell.otherMonth = true;
					} else {
						cell.className += " emptycell";
						cell.innerHTML = "&#160;";
						cell.disabled = true;
						continue;
					}
				} else {
					cell.otherMonth = false;
					hasdays = true;
					cell.style.cursor = "pointer";
				}
				cell.disabled = false;
				cell.textContent = this.params.debug ? iday : Date.convertNumbers(iday); // translated day number for each cell
				if (!cell.disabled) {
					cell.caldate = new Date(date);
					if (current_month && iday === mday) {
						cell.className += " selected";
						this.currentDateEl = cell;
					}
					if (date.getLocalFullYear(this.params.dateType) === TY && date.getLocalMonth(this.params.dateType) === TM && iday === TD) {
						cell.className += " today";
					}
					if (weekend.indexOf(wday) !== -1)
						cell.className += " weekend";
				}
			}
			if (!(hasdays || this.params.showsOthers)) {
				row.classList.add('hidden');
				row.setAttribute('hidden', '');
				row.className = "emptyrow";
			} else {
				row.classList.remove('hidden');
				row.removeAttribute('hidden', '');
			}
		}

		/* Set the time */
		if (this.params.showsTime) {
			if (hrs > 12 && t12) {
				hrs -= 12;
			}

			hrs = (hrs < 10) ? "0" + hrs : hrs;
			mins = (mins < 10) ? "0" + mins : mins;

			var hoursEl = this.table.querySelector('.time-hours'),
				minsEl = this.table.querySelector('.time-minutes');

			/* remove the selected class  for the hours*/
			this.resetSelected(hoursEl);
			if (!this.params.time24) {
				hoursEl.value = (hrs == "00") ? "12" : hrs;
			} else {
				hoursEl.value = hrs;
			}

			/* remove the selected class  for the minutes*/
			this.resetSelected(minsEl);
			minsEl.value = mins;

			if (!this.params.time24) {
				var dateAlt = new Date(this.inputField.getAttribute('data-alt-value')),
					ampmEl = this.table.querySelector('.time-ampm'),
					hrsAlt = dateAlt.getHours();

				if (hrsAlt > 12) {
					/* remove the selected class  for the am-pm*/
					this.resetSelected(ampmEl);
					ampmEl.value = 'pm';
				}
			}
		}

		if (!this.params.compressedHeader) {
			this._nav_month.getElementsByTagName('span')[0].textContent = this.params.debug ? month + ' ' + this.strings.months[month] : this.strings.months[month];
			this.title.getElementsByTagName('span')[0].textContent = this.params.debug ? year + ' ' +  Date.convertNumbers(year.toString()) : Date.convertNumbers(year.toString());
		} else {
			var tmpYear = Date.convertNumbers(year.toString());
			this._nav_month.getElementsByTagName('span')[0].textContent = !this.params.monthBefore  ? this.strings.months[month] + ' - ' + tmpYear : tmpYear + ' - ' + this.strings.months[month] ;
		}
		this.table.style.visibility = "visible";
	};

	/** Method to listen for the click event on the input button. **/
	JoomlaCalendar.prototype._bindEvents = function () {
		var self = this;
		this.inputField.addEventListener('blur', function(event) {
			var calObj = JoomlaCalendar.getCalObject(this)._joomlaCalendar;

			// If calendar is open we will handle the event elsewhere
			if (!calObj.dropdownElement.hasAttribute('hidden')) {
				event.preventDefault();
				return;
			}

			if (calObj) {
				if (calObj.inputField.value) {
					if (typeof calObj.params.dateClicked === 'undefined') {
						calObj.inputField.setAttribute('data-local-value', calObj.inputField.value);

						if (calObj.params.dateType !== 'gregorian') {
							// We need to transform the date for the data-alt-value.
							// ## Strict parsing ##
							// if the field was left with an incomplete or invalid value (e.g. the user clicked away mid-edit),
							// do not convert it as if it were a valid Jalali date - fall back to an empty value instead.
							var date = Date.parseFieldDate(calObj.inputField.value, calObj.params.dateFormat, calObj.params.dateType, calObj.strings, true);

							if (!date) {
								calObj.inputField.setAttribute('data-alt-value', '0000-00-00 00:00:00');
							} else {
								// Use date.rawYear/rawMonth/rawDay: custom, non-native properties.
								// See the "input" listener for why they're needed instead
								// of getFullYear()/getMonth()/getDate(), and why +1/-1.
								var ndate = Date.localCalToGregorian(date.rawYear, date.rawMonth + 1, date.rawDay);

								// Rebuild atomically - see the "input" listener for why
								// setFullYear()/setMonth()/setDate() in sequence is unsafe here.
								date = new Date(ndate[0], ndate[1] - 1, ndate[2], self.date.getHours(), self.date.getMinutes(), date.getSeconds());
								calObj.inputField.setAttribute('data-alt-value', date.print(calObj.params.dateFormat, 'gregorian', false, calObj.strings));
							}
						} else {
							var gdate = Date.parseFieldDate(calObj.inputField.value, calObj.params.dateFormat, calObj.params.dateType, calObj.strings, true);
							calObj.inputField.setAttribute('data-alt-value', gdate
								? gdate.print(calObj.params.dateFormat, 'gregorian', false, calObj.strings)
								: '0000-00-00 00:00:00');
						}
					} else {
						calObj.inputField.setAttribute('data-alt-value', calObj.date.print(calObj.params.dateFormat, 'gregorian', false, calObj.strings));
					}
				} else {
					calObj.inputField.setAttribute('data-alt-value', '0000-00-00 00:00:00');
				}
				calObj.date = Date.parseFieldDate(calObj.inputField.getAttribute('data-alt-value'), calObj.params.dateFormat, calObj.params.dateType, calObj.strings, false);
			}
			self.close();
		}, true);
		this.button.addEventListener('click', function() {
			self.show();
		}, false);
	};

	/** Helpers **/
	var stopCalEvent = function (ev) { ev || (ev = window.event);  ev.preventDefault(); ev.stopPropagation(); return false; };
	var createElement = function (type, parent) { var el = null; el = document.createElement(type); if (typeof parent !== "undefined") { parent.appendChild(el); } return el; };
	var isInt = function (input) { return !isNaN(input) && (function(x) { return (x | 0) === x; })(parseFloat(input)) };
	var getBoundary = function (input, type) { var date = new Date(); var y = date.getLocalFullYear(type); return y + input; };

	/** Method to get the active calendar element through any descendant element. */
	JoomlaCalendar.getCalObject = function(element) {
		if (!element) {
			return false;
		}
		while (element.parentNode) {
			element = element.parentNode;
			if (element.classList.contains('field-calendar')) {
				return element;
			}
		}
		return false;
	};

	/**
	 * Method to change input values with the data-alt-value values. This method is e.g. being called
	 * by the onSubmit handler of the calendar fields form.
	 */
	JoomlaCalendar.prototype.setAltValue = function() {
		var input = this.inputField;
		if (input.getAttribute('disabled')) return;

		// Set the value to the data-alt-value attribute, but only if it really has a value.
		input.value = (
			input.getAttribute('data-alt-value') && input.getAttribute('data-alt-value') !== '0000-00-00 00:00:00'
			? input.getAttribute('data-alt-value')
			: ''
		);
	};

	/** Method to change the inputs before submit. **/
	JoomlaCalendar.onSubmit = function() {
		Joomla = window.Joomla || {};
		if (!Joomla.calendarProcessed) {
			Joomla.calendarProcessed = true;
			var elements = document.querySelectorAll(".field-calendar");

			for (var i = 0; i < elements.length; i++) {
				var element  = elements[i],
					instance = element._joomlaCalendar;

				if (instance) {
					instance.setAltValue();
				}
			}
		}
	};

	/**
	 * Init the Calendars on the page
	 *
	 * @param {Node}        element    The element node
	 * @param {HTMLElement} container  The field container (optional)
	 */
	JoomlaCalendar.init = function (element, container) {

		var instance = element._joomlaCalendar;
		if (!instance) {
			new JoomlaCalendar(element);
		} else {
			instance.recreate();
		}

		if (element && element.getElementsByTagName('input')[0] && element.getElementsByTagName('input')[0].form && !element.getElementsByTagName('input')[0].disabled) {
			element.getElementsByTagName('input')[0].form.addEventListener('submit', JoomlaCalendar.onSubmit);
		}
	};

	window.JoomlaCalendar = JoomlaCalendar;

	/**
	 * Instantiate all the calendar fields when the document is ready/updated
	 * @param {Event} event
	 * @private
	 */
	function _initCalendars(event) {
		var elements = event.target.querySelectorAll(".field-calendar");

		for (var i = 0, l = elements.length; i < l; i++) {
			JoomlaCalendar.init(elements[i]);
		}
	}
	document.addEventListener("DOMContentLoaded", _initCalendars);
	document.addEventListener("joomla:updated", _initCalendars);

		/** B/C related code
		 *
		 *  @deprecated   4.0 will be removed in 7.0
		 *                Use JoomlaCalendar.init instead
		 */
		window.Calendar = {};

		/** B/C related code
		 *
		 *  @deprecated   4.0 will be removed in 7.0
		 *                Use JoomlaCalendar.init instead
		 */
		Calendar.setup = function(obj) {

			if (obj.inputField && document.getElementById(obj.inputField)) {
				var element = document.getElementById(obj.inputField),
					cal = element.parentNode.querySelectorAll('button')[0];

				for (var property in obj) {
					if (obj.hasOwnProperty(property)) {
						switch (property) {
							case 'ifFormat':
								if (cal) cal.setAttribute('data-dayformat', obj.ifFormat);
								break;

							case 'firstDay':
								if (cal) cal.setAttribute('data-firstday', parseInt(obj.firstDay));
								break;

							case 'weekNumbers':
								if (cal) cal.setAttribute('data-week-numbers', (obj.weekNumbers === "true" || obj.weekNumbers === true) ? '1' : '0');
								break;

							case 'showOthers':
								if (cal) cal.setAttribute('data-show-others', (obj.showOthers === "true" || obj.showOthers === true) ? '1' : '0');
								break;

							case 'showsTime':
								if (cal) cal.setAttribute('data-show-time', (obj.showsTime === "true" || obj.showsTime === true) ? '1' : '0');
								break;

							case 'timeFormat':
								if (cal) cal.setAttribute('data-time-24', parseInt(obj.timeFormat));
								break;

							case 'displayArea':
							case 'inputField':
							case 'button':
							case 'eventName':
							case 'daFormat':
							case 'disableFunc':
							case 'dateStatusFunc':
							case 'dateTooltipFunc':
							case 'dateText':
							case 'align':
							case 'range':
							case 'flat':
							case 'flatCallback':
							case 'onSelect':
							case 'onClose':
							case 'onUpdate':
							case 'date':
							case 'electric':
							case 'step':
							case 'position':
							case 'cache':
							case 'multiple':
								break;
						}


					}
				}
				JoomlaCalendar.init(element.parentNode.parentNode);
			}
			return null;
		};

})(window, document);

The same content is in 15 releases, Joomla 5.4.9-rc1 to 6.3.0-alpha1. See them all, or every version of this file.