2022-02-21 17:46:35 +00:00
|
|
|
// Core JavaScript helper functions
|
2020-10-24 02:58:05 +00:00
|
|
|
'use strict';
|
2018-10-12 03:11:57 +00:00
|
|
|
|
|
|
|
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
|
|
|
|
function quickElement() {
|
2020-10-24 02:58:05 +00:00
|
|
|
const obj = document.createElement(arguments[0]);
|
2018-10-12 03:11:57 +00:00
|
|
|
if (arguments[2]) {
|
2020-10-24 02:58:05 +00:00
|
|
|
const textNode = document.createTextNode(arguments[2]);
|
2018-10-12 03:11:57 +00:00
|
|
|
obj.appendChild(textNode);
|
|
|
|
}
|
2020-10-24 02:58:05 +00:00
|
|
|
const len = arguments.length;
|
|
|
|
for (let i = 3; i < len; i += 2) {
|
2018-10-12 03:11:57 +00:00
|
|
|
obj.setAttribute(arguments[i], arguments[i + 1]);
|
|
|
|
}
|
|
|
|
arguments[1].appendChild(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "a" is reference to an object
|
|
|
|
function removeChildren(a) {
|
|
|
|
while (a.hasChildNodes()) {
|
|
|
|
a.removeChild(a.lastChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Find-position functions by PPK
|
2019-02-24 13:50:42 +00:00
|
|
|
// See https://www.quirksmode.org/js/findpos.html
|
2018-10-12 03:11:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function findPosX(obj) {
|
2020-10-24 02:58:05 +00:00
|
|
|
let curleft = 0;
|
2018-10-12 03:11:57 +00:00
|
|
|
if (obj.offsetParent) {
|
|
|
|
while (obj.offsetParent) {
|
|
|
|
curleft += obj.offsetLeft - obj.scrollLeft;
|
2020-10-24 02:58:05 +00:00
|
|
|
obj = obj.offsetParent;
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
|
|
|
} else if (obj.x) {
|
|
|
|
curleft += obj.x;
|
|
|
|
}
|
|
|
|
return curleft;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findPosY(obj) {
|
2020-10-24 02:58:05 +00:00
|
|
|
let curtop = 0;
|
2018-10-12 03:11:57 +00:00
|
|
|
if (obj.offsetParent) {
|
|
|
|
while (obj.offsetParent) {
|
|
|
|
curtop += obj.offsetTop - obj.scrollTop;
|
2020-10-24 02:58:05 +00:00
|
|
|
obj = obj.offsetParent;
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
|
|
|
} else if (obj.y) {
|
|
|
|
curtop += obj.y;
|
|
|
|
}
|
|
|
|
return curtop;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Date object extensions
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-10-24 02:58:05 +00:00
|
|
|
{
|
2018-10-12 03:11:57 +00:00
|
|
|
Date.prototype.getTwelveHours = function() {
|
2020-01-04 14:37:42 +00:00
|
|
|
return this.getHours() % 12 || 12;
|
2018-10-12 03:11:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitMonth = function() {
|
|
|
|
return (this.getMonth() < 9) ? '0' + (this.getMonth() + 1) : (this.getMonth() + 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitDate = function() {
|
|
|
|
return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate();
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitTwelveHour = function() {
|
|
|
|
return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours();
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitHour = function() {
|
|
|
|
return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours();
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitMinute = function() {
|
|
|
|
return (this.getMinutes() < 10) ? '0' + this.getMinutes() : this.getMinutes();
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.getTwoDigitSecond = function() {
|
|
|
|
return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds();
|
|
|
|
};
|
|
|
|
|
2021-04-11 19:51:12 +00:00
|
|
|
Date.prototype.getAbbrevMonthName = function() {
|
|
|
|
return typeof window.CalendarNamespace === "undefined"
|
|
|
|
? this.getTwoDigitMonth()
|
|
|
|
: window.CalendarNamespace.monthsOfYearAbbrev[this.getMonth()];
|
|
|
|
};
|
|
|
|
|
2018-10-12 03:11:57 +00:00
|
|
|
Date.prototype.getFullMonthName = function() {
|
|
|
|
return typeof window.CalendarNamespace === "undefined"
|
|
|
|
? this.getTwoDigitMonth()
|
|
|
|
: window.CalendarNamespace.monthsOfYear[this.getMonth()];
|
|
|
|
};
|
|
|
|
|
|
|
|
Date.prototype.strftime = function(format) {
|
2020-10-24 02:58:05 +00:00
|
|
|
const fields = {
|
2021-04-11 19:51:12 +00:00
|
|
|
b: this.getAbbrevMonthName(),
|
2018-10-12 03:11:57 +00:00
|
|
|
B: this.getFullMonthName(),
|
|
|
|
c: this.toString(),
|
|
|
|
d: this.getTwoDigitDate(),
|
|
|
|
H: this.getTwoDigitHour(),
|
|
|
|
I: this.getTwoDigitTwelveHour(),
|
|
|
|
m: this.getTwoDigitMonth(),
|
|
|
|
M: this.getTwoDigitMinute(),
|
|
|
|
p: (this.getHours() >= 12) ? 'PM' : 'AM',
|
|
|
|
S: this.getTwoDigitSecond(),
|
|
|
|
w: '0' + this.getDay(),
|
|
|
|
x: this.toLocaleDateString(),
|
|
|
|
X: this.toLocaleTimeString(),
|
|
|
|
y: ('' + this.getFullYear()).substr(2, 4),
|
|
|
|
Y: '' + this.getFullYear(),
|
|
|
|
'%': '%'
|
|
|
|
};
|
2020-10-24 02:58:05 +00:00
|
|
|
let result = '', i = 0;
|
2018-10-12 03:11:57 +00:00
|
|
|
while (i < format.length) {
|
|
|
|
if (format.charAt(i) === '%') {
|
2023-05-03 00:55:26 +00:00
|
|
|
result += fields[format.charAt(i + 1)];
|
2018-10-12 03:11:57 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else {
|
2023-05-03 00:55:26 +00:00
|
|
|
result += format.charAt(i);
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2019-07-11 02:25:40 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// String object extensions
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-10-12 03:11:57 +00:00
|
|
|
String.prototype.strptime = function(format) {
|
2020-10-24 02:58:05 +00:00
|
|
|
const split_format = format.split(/[.\-/]/);
|
|
|
|
const date = this.split(/[.\-/]/);
|
|
|
|
let i = 0;
|
|
|
|
let day, month, year;
|
2018-10-12 03:11:57 +00:00
|
|
|
while (i < split_format.length) {
|
|
|
|
switch (split_format[i]) {
|
2019-07-11 02:25:40 +00:00
|
|
|
case "%d":
|
|
|
|
day = date[i];
|
|
|
|
break;
|
|
|
|
case "%m":
|
|
|
|
month = date[i] - 1;
|
|
|
|
break;
|
|
|
|
case "%Y":
|
|
|
|
year = date[i];
|
|
|
|
break;
|
|
|
|
case "%y":
|
2020-10-24 02:58:05 +00:00
|
|
|
// A %y value in the range of [00, 68] is in the current
|
|
|
|
// century, while [69, 99] is in the previous century,
|
|
|
|
// according to the Open Group Specification.
|
|
|
|
if (parseInt(date[i], 10) >= 69) {
|
|
|
|
year = date[i];
|
|
|
|
} else {
|
|
|
|
year = (new Date(Date.UTC(date[i], 0))).getUTCFullYear() + 100;
|
|
|
|
}
|
2019-07-11 02:25:40 +00:00
|
|
|
break;
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
// Create Date object from UTC since the parsed value is supposed to be
|
|
|
|
// in UTC, not local time. Also, the calendar uses UTC functions for
|
|
|
|
// date extraction.
|
|
|
|
return new Date(Date.UTC(year, month, day));
|
|
|
|
};
|
2020-10-24 02:58:05 +00:00
|
|
|
}
|