2015-03-14 22:38:12 +01:00
|
|
|
// Core javascript helper functions
|
|
|
|
|
|
|
|
// basic browser identification & version
|
2017-08-17 19:13:36 +02:00
|
|
|
var isOpera = (navigator.userAgent.indexOf("Opera") >= 0) && parseFloat(navigator.appVersion);
|
2015-03-14 22:38:12 +01:00
|
|
|
var isIE = ((document.all) && (!isOpera)) && parseFloat(navigator.appVersion.split("MSIE ")[1].split(";")[0]);
|
|
|
|
|
|
|
|
// Cross-browser event handlers.
|
|
|
|
function addEvent(obj, evType, fn) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
if (obj.addEventListener) {
|
|
|
|
obj.addEventListener(evType, fn, false);
|
|
|
|
return true;
|
|
|
|
} else if (obj.attachEvent) {
|
|
|
|
var r = obj.attachEvent("on" + evType, fn);
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeEvent(obj, evType, fn) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
if (obj.removeEventListener) {
|
|
|
|
obj.removeEventListener(evType, fn, false);
|
|
|
|
return true;
|
|
|
|
} else if (obj.detachEvent) {
|
|
|
|
obj.detachEvent("on" + evType, fn);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelEventPropagation(e) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
|
|
|
if (!e) {
|
|
|
|
e = window.event;
|
|
|
|
}
|
2015-03-14 22:38:12 +01:00
|
|
|
e.cancelBubble = true;
|
2017-08-17 19:13:36 +02:00
|
|
|
if (e.stopPropagation) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2015-03-14 22:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
|
|
|
|
function quickElement() {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
var obj = document.createElement(arguments[0]);
|
|
|
|
if (arguments[2]) {
|
|
|
|
var textNode = document.createTextNode(arguments[2]);
|
|
|
|
obj.appendChild(textNode);
|
|
|
|
}
|
|
|
|
var len = arguments.length;
|
|
|
|
for (var i = 3; i < len; i += 2) {
|
2017-08-17 19:13:36 +02:00
|
|
|
obj.setAttribute(arguments[i], arguments[i + 1]);
|
2015-03-14 22:38:12 +01:00
|
|
|
}
|
|
|
|
arguments[1].appendChild(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "a" is reference to an object
|
|
|
|
function removeChildren(a) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
|
|
|
while (a.hasChildNodes()) {
|
|
|
|
a.removeChild(a.lastChild);
|
2015-03-14 22:38:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Find-position functions by PPK
|
|
|
|
// See http://www.quirksmode.org/js/findpos.html
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function findPosX(obj) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
var curleft = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
while (obj.offsetParent) {
|
|
|
|
curleft += obj.offsetLeft - ((isOpera) ? 0 : obj.scrollLeft);
|
|
|
|
obj = obj.offsetParent;
|
|
|
|
}
|
|
|
|
// IE offsetParent does not include the top-level
|
2017-08-17 19:13:36 +02:00
|
|
|
if (isIE && obj.parentElement) {
|
2015-03-14 22:38:12 +01:00
|
|
|
curleft += obj.offsetLeft - obj.scrollLeft;
|
|
|
|
}
|
|
|
|
} else if (obj.x) {
|
|
|
|
curleft += obj.x;
|
|
|
|
}
|
|
|
|
return curleft;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findPosY(obj) {
|
2017-08-17 19:13:36 +02:00
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
var curtop = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
while (obj.offsetParent) {
|
|
|
|
curtop += obj.offsetTop - ((isOpera) ? 0 : obj.scrollTop);
|
|
|
|
obj = obj.offsetParent;
|
|
|
|
}
|
|
|
|
// IE offsetParent does not include the top-level
|
2017-08-17 19:13:36 +02:00
|
|
|
if (isIE && obj.parentElement) {
|
2015-03-14 22:38:12 +01:00
|
|
|
curtop += obj.offsetTop - obj.scrollTop;
|
|
|
|
}
|
|
|
|
} else if (obj.y) {
|
|
|
|
curtop += obj.y;
|
|
|
|
}
|
|
|
|
return curtop;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Date object extensions
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-08-17 19:13:36 +02:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
Date.prototype.getTwelveHours = function() {
|
|
|
|
var hours = this.getHours();
|
|
|
|
if (hours === 0) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return hours <= 12 ? hours : hours - 12;
|
|
|
|
}
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitMonth = function() {
|
|
|
|
return (this.getMonth() < 9) ? '0' + (this.getMonth() + 1) : (this.getMonth() + 1);
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitDate = function() {
|
|
|
|
return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitTwelveHour = function() {
|
|
|
|
return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitHour = function() {
|
|
|
|
return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitMinute = function() {
|
|
|
|
return (this.getMinutes() < 10) ? '0' + this.getMinutes() : this.getMinutes();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getTwoDigitSecond = function() {
|
|
|
|
return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getHourMinute = function() {
|
|
|
|
return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getHourMinuteSecond = function() {
|
|
|
|
return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond();
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
Date.prototype.getFullMonthName = function() {
|
|
|
|
return typeof window.CalendarNamespace === "undefined"
|
|
|
|
? this.getTwoDigitMonth()
|
|
|
|
: window.CalendarNamespace.monthsOfYear[this.getMonth()];
|
2015-03-14 22:38:12 +01:00
|
|
|
};
|
2017-08-17 19:13:36 +02:00
|
|
|
|
|
|
|
Date.prototype.strftime = function(format) {
|
|
|
|
var fields = {
|
|
|
|
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(),
|
|
|
|
'%': '%'
|
|
|
|
};
|
|
|
|
var result = '', i = 0;
|
|
|
|
while (i < format.length) {
|
|
|
|
if (format.charAt(i) === '%') {
|
|
|
|
result = result + fields[format.charAt(i + 1)];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = result + format.charAt(i);
|
|
|
|
}
|
2015-03-14 22:38:12 +01:00
|
|
|
++i;
|
|
|
|
}
|
2017-08-17 19:13:36 +02:00
|
|
|
return result;
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// String object extensions
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-08-17 19:13:36 +02:00
|
|
|
String.prototype.pad_left = function(pad_length, pad_string) {
|
|
|
|
var new_string = this;
|
|
|
|
for (var i = 0; new_string.length < pad_length; i++) {
|
|
|
|
new_string = pad_string + new_string;
|
|
|
|
}
|
|
|
|
return new_string;
|
|
|
|
};
|
|
|
|
|
|
|
|
String.prototype.strptime = function(format) {
|
|
|
|
var split_format = format.split(/[.\-/]/);
|
|
|
|
var date = this.split(/[.\-/]/);
|
|
|
|
var i = 0;
|
|
|
|
var day, month, year;
|
|
|
|
while (i < split_format.length) {
|
|
|
|
switch (split_format[i]) {
|
|
|
|
case "%d":
|
|
|
|
day = date[i];
|
|
|
|
break;
|
|
|
|
case "%m":
|
|
|
|
month = date[i] - 1;
|
|
|
|
break;
|
|
|
|
case "%Y":
|
|
|
|
year = date[i];
|
|
|
|
break;
|
|
|
|
case "%y":
|
|
|
|
year = date[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++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));
|
|
|
|
};
|
2015-03-14 22:38:12 +01:00
|
|
|
|
2017-08-17 19:13:36 +02:00
|
|
|
})();
|
2015-03-14 22:38:12 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Get the computed style for and element
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-08-17 19:13:36 +02:00
|
|
|
function getStyle(oElm, strCssRule) {
|
|
|
|
'use strict';
|
2015-03-14 22:38:12 +01:00
|
|
|
var strValue = "";
|
2017-08-17 19:13:36 +02:00
|
|
|
if(document.defaultView && document.defaultView.getComputedStyle) {
|
2015-03-14 22:38:12 +01:00
|
|
|
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
|
|
|
|
}
|
2017-08-17 19:13:36 +02:00
|
|
|
else if(oElm.currentStyle) {
|
|
|
|
strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
|
2015-03-14 22:38:12 +01:00
|
|
|
return p1.toUpperCase();
|
|
|
|
});
|
|
|
|
strValue = oElm.currentStyle[strCssRule];
|
|
|
|
}
|
|
|
|
return strValue;
|
|
|
|
}
|