521 lines
12 KiB
JavaScript
521 lines
12 KiB
JavaScript
/** \file html\javascript\java.js
|
|
* \brief ZKL webinterface general javascript functions.
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version 1.0
|
|
* \date 17-10-2008
|
|
*
|
|
* This file contains the general framework javascript functions.
|
|
*/
|
|
|
|
/**
|
|
* Return element ID (Browser independend)
|
|
*
|
|
* Inputs:
|
|
* - aID: Element ID
|
|
*
|
|
* Return: ID
|
|
*/
|
|
function getElement(id) {
|
|
if (document.getElementById(id) || (!document.getElementById(id) && document.getElementsByName(id).length==0)) {
|
|
// IF An ID attribute is assigned
|
|
// OR No ID attribute is assigned but using IE and Opera
|
|
// (which will find the NAME attribute value using getElementById)
|
|
// OR No element has this ID or NAME attribute value
|
|
// (used internally by the script)
|
|
// THEN Return the required element.
|
|
|
|
return document.getElementById(id);
|
|
}
|
|
else {
|
|
if (document.getElementsByName(id).length==1) {
|
|
// IF No ID attribute is assigned
|
|
// AND Using a standards-based browser
|
|
// AND Only one element has the NAME attribute set to the value
|
|
// THEN Return the required element (using the NAME attribute value).
|
|
return document.getElementsByName(id)[0];
|
|
}
|
|
else {
|
|
if (document.getElementsByName(id).length>1) {
|
|
// IF No ID attribute is assigned
|
|
// AND using a standards-based browser
|
|
// AND more than one element has the NAME attribute set to the value
|
|
// THEN alert developer to fix the fault.
|
|
return (document.getElementsByName(id)[0]);
|
|
}
|
|
else return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Return elements by class name
|
|
*
|
|
* Inputs:
|
|
* - oElm: Element name
|
|
* - strTagName: Tag name
|
|
* - oClassNames: Class name
|
|
*
|
|
* Return: Array containing elements
|
|
*/
|
|
function getElementsByClassName(oElm, strTagName, oClassNames) {
|
|
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
|
|
var arrReturnElements = new Array();
|
|
var arrRegExpClassNames = new Array();
|
|
if(typeof oClassNames == "object"){
|
|
for(var i=0; i<oClassNames.length; i++){
|
|
arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
|
|
}
|
|
}
|
|
else{
|
|
arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
|
|
}
|
|
var oElement;
|
|
var bMatchesAll;
|
|
for(var j=0; j<arrElements.length; j++){
|
|
oElement = arrElements[j];
|
|
bMatchesAll = true;
|
|
for(var k=0; k<arrRegExpClassNames.length; k++){
|
|
if(!arrRegExpClassNames[k].test(oElement.className)){
|
|
bMatchesAll = false;
|
|
break;
|
|
}
|
|
}
|
|
if(bMatchesAll){
|
|
arrReturnElements.push(oElement);
|
|
}
|
|
}
|
|
return (arrReturnElements)
|
|
}
|
|
|
|
|
|
/**
|
|
* Catch enter/tab event
|
|
*/
|
|
function noenter(arg1,arg2)
|
|
{
|
|
var k;
|
|
|
|
if ("which" in arg1) {
|
|
k = arg1.which
|
|
}
|
|
else if ("keyCode" in arg1) {
|
|
k = arg1.keyCode
|
|
}
|
|
else if ("keyCode" in window.event) {
|
|
k = window.event.keyCode
|
|
}
|
|
else if ("which" in window.event) {
|
|
k=arg1.which
|
|
}
|
|
else {
|
|
return true
|
|
}
|
|
|
|
// Catch TAB
|
|
// if (k == 9) {
|
|
// arg2.value = arg2.value + "\t";
|
|
// setTimeout("arg2.focus()",1)
|
|
// return false;
|
|
// }
|
|
|
|
// Catch ENTER
|
|
if (k == 13) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Get current value of y-position scrollbar
|
|
*/
|
|
function getScrollY() {
|
|
var scrOfY = 0;
|
|
if( typeof( window.pageYOffset ) == 'number' ) {
|
|
//Netscape compliant
|
|
scrOfY = window.pageYOffset;
|
|
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
|
|
//DOM compliant
|
|
scrOfY = document.body.scrollTop;
|
|
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
|
|
//IE6 standards compliant mode
|
|
scrOfY = document.documentElement.scrollTop;
|
|
}
|
|
return scrOfY;
|
|
}
|
|
|
|
|
|
/**
|
|
* Get current value of x-position scrollbar
|
|
*/
|
|
function getScrollX() {
|
|
var scrOfX = 0;
|
|
if( typeof( window.pageXOffset ) == 'number' ) {
|
|
//Netscape compliant
|
|
scrOfX = window.pageXOffset;
|
|
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
|
|
//DOM compliant
|
|
scrOfX = document.body.scrollLeft;
|
|
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
|
|
//IE6 standards compliant mode
|
|
scrOfX = document.documentElement.scrollLeft;
|
|
}
|
|
return scrOfX;
|
|
}
|
|
|
|
/**
|
|
* Set current value of y-position scrollbar
|
|
*
|
|
* Inputs:
|
|
* - y: The new Y position
|
|
*
|
|
*/
|
|
function setScrollY(y) {
|
|
document.body.scrollTop = y;
|
|
document.documentElement.scrollTop = y;
|
|
}
|
|
|
|
|
|
/**
|
|
* Write cookie
|
|
*
|
|
*/
|
|
function write_cookie(cookie_data, ExpiresAfterDays)
|
|
{
|
|
var the_cookie_date;
|
|
if (typeof(ExpiresAfterDays) == 'undefined') {
|
|
the_cookie_date = 0;
|
|
}
|
|
else {
|
|
var the_date = new Date();
|
|
the_date.setDate(the_date.getDate() + ExpiresAfterDays);
|
|
the_cookie_date = the_date.toGMTString();
|
|
}
|
|
document.cookie = cookie_data + ";expires=" + the_cookie_date + ";secure";
|
|
}
|
|
|
|
|
|
/**
|
|
* Get url parameter ($_GET)
|
|
*
|
|
*/
|
|
function getURLParam(strParamName){
|
|
var strReturn = "";
|
|
var strHref = window.location.href;
|
|
if ( strHref.indexOf("?") > -1 ){
|
|
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
|
|
var aQueryString = strQueryString.split("&");
|
|
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
|
|
if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
|
|
var aParam = aQueryString[iParam].split("=");
|
|
strReturn = aParam[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return unescape(strReturn);
|
|
}
|
|
|
|
/**
|
|
* Submit form and follow link
|
|
*/
|
|
function submitFormAndFollow(url)
|
|
{
|
|
if( typeof(onSubmit) == 'function' && document.form ) {
|
|
onSubmit('follow_link' + escape("=") + escape(url), '', 1);
|
|
}
|
|
else {
|
|
window.open(url,'_self');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Open window
|
|
*
|
|
*/
|
|
function windowOpener(url, name, args)
|
|
{
|
|
if (typeof(popupWin) != "object"){
|
|
popupWin = window.open(url,name,args);
|
|
}
|
|
else {
|
|
if (!popupWin.closed){
|
|
popupWin.location.href = url;
|
|
}
|
|
else {
|
|
popupWin = window.open(url, name,args);
|
|
}
|
|
}
|
|
popupWin.focus();
|
|
}
|
|
|
|
|
|
/**
|
|
* screen width?
|
|
*
|
|
*/
|
|
function ScreenWidth() {
|
|
var myWidth = 0;
|
|
if( typeof( window.innerWidth ) == 'number' ) {
|
|
//Non-IE
|
|
myWidth = window.innerWidth;
|
|
} else if( document.documentElement && document.documentElement.clientWidth ) {
|
|
//IE 6+ in 'standards compliant mode'
|
|
myWidth = document.documentElement.clientWidth;
|
|
} else if( document.body && document.body.clientWidth ) {
|
|
//IE 4 compatible
|
|
myWidth = document.body.clientWidth;
|
|
}
|
|
return myWidth;
|
|
}
|
|
|
|
|
|
/**
|
|
* screen height?
|
|
*
|
|
*/
|
|
function ScreenHeight() {
|
|
var myHeight = 0;
|
|
if( typeof( window.innerHeight ) == 'number' ) {
|
|
//Non-IE
|
|
myHeight = window.innerHeight;
|
|
} else if( document.documentElement && document.documentElement.clientHeight ) {
|
|
//IE 6+ in 'standards compliant mode'
|
|
myHeight = document.documentElement.clientHeight;
|
|
} else if( document.body && document.body.clientHeight ) {
|
|
//IE 4 compatible
|
|
myHeight = document.body.clientHeight;
|
|
}
|
|
return myHeight;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Support function: use a default when the value is undefined
|
|
*/
|
|
function useDefault(value, dflt_value)
|
|
{
|
|
if( typeof value == 'undefined' )
|
|
return dflt_value;
|
|
else
|
|
return value;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Add or remove a CSS class
|
|
*/
|
|
// Highlight the drop target; primarily used for Safari (which has a bug) and
|
|
// mobile browsers, but it gives a nice effect in other browsers as well
|
|
function changeClass(element, css_action, highlight)
|
|
{
|
|
if( highlight ) {
|
|
if( element.className.indexOf(" " + css_action) == -1 )
|
|
element.className += " " + css_action;
|
|
}
|
|
else {
|
|
element.className = element.className.replace(" " + css_action,"");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Redirect parent
|
|
*
|
|
*/
|
|
function goParent(url)
|
|
{
|
|
parent.location.href = url;
|
|
}
|
|
|
|
/**
|
|
* Get current datetime
|
|
*
|
|
*/
|
|
function getDateTime()
|
|
{
|
|
// Get date object
|
|
var d = new Date();
|
|
|
|
d_month = d.getMonth();
|
|
if (d_month < 10) {
|
|
var d_month = '0' + d_month;
|
|
}
|
|
|
|
d_date = d.getDate();
|
|
if (d_date < 10) {
|
|
var d_date = '0' + d_date;
|
|
}
|
|
|
|
d_hour = d.getHours();
|
|
if (d_hour < 10) {
|
|
var d_hour = '0' + d_hour;
|
|
}
|
|
|
|
d_min = d.getMinutes();
|
|
if (d_min < 10) {
|
|
var d_min = '0' + d_min;
|
|
}
|
|
|
|
d_sec = d.getSeconds();
|
|
if (d_sec < 10) {
|
|
var d_sec = '0' + d_sec
|
|
}
|
|
|
|
return d.getFullYear() + '-' + d_month + '-' + d_date + ' ' + d_hour + ':' + d_min + ':' + d_sec;
|
|
}
|
|
|
|
/**
|
|
* Get current time
|
|
*
|
|
*/
|
|
function getTime()
|
|
{
|
|
// Get date object
|
|
var d = new Date();
|
|
|
|
d_hour = d.getHours();
|
|
if (d_hour < 10) {
|
|
var d_hour = '0' + d_hour;
|
|
}
|
|
|
|
d_min = d.getMinutes();
|
|
if (d_min < 10) {
|
|
var d_min = '0' + d_min;
|
|
}
|
|
|
|
d_sec = d.getSeconds();
|
|
if (d_sec < 10) {
|
|
var d_sec = '0' + d_sec
|
|
}
|
|
|
|
return d_hour + ':' + d_min + ':' + d_sec;
|
|
}
|
|
|
|
/**
|
|
* Get current date
|
|
*
|
|
*/
|
|
function getDate()
|
|
{
|
|
// Get date object
|
|
var d = new Date();
|
|
|
|
d_month = d.getMonth();
|
|
if (d_month < 10) {
|
|
var d_month = '0' + d_month;
|
|
}
|
|
|
|
d_date = d.getDate();
|
|
if (d_date < 10) {
|
|
var d_date = '0' + d_date;
|
|
}
|
|
|
|
return d.getFullYear() + '-' + d_month + '-' + d_date;
|
|
}
|
|
|
|
/*
|
|
* Sort array associative
|
|
*/
|
|
function sortAssoc(aInput){
|
|
var aTemp = [];
|
|
for (var sKey in aInput)
|
|
aTemp.push([sKey, aInput[sKey]]);
|
|
aTemp.sort(function () {return arguments[0][1] < arguments[1][1]});
|
|
|
|
var aOutput = [];
|
|
for (var nIndex = aTemp.length-1; nIndex >=0; nIndex--)
|
|
aOutput[aTemp[nIndex][0]] = aTemp[nIndex][1];
|
|
|
|
return aOutput;
|
|
}
|
|
|
|
|
|
/*
|
|
* Show elements by Class name
|
|
*/
|
|
function showClass(className) {
|
|
var x = getElementsByClassName(document, '*', className);
|
|
|
|
for (i = 0; i < x.length; i++) {
|
|
x[i].style.visibility = "visible";
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Hide elements by Class name
|
|
*/
|
|
function hideClass(className) {
|
|
var x = getElementsByClassName(document, '*', className);
|
|
|
|
for (i = 0; i < x.length; i++) {
|
|
x[i].style.visibility = "hidden";
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Active window height
|
|
*/
|
|
function ActiveWindowHeight() {
|
|
if (parseInt(navigator.appVersion) > 3) {
|
|
if (navigator.appName=="Netscape") {
|
|
return window.innerHeight - 16;
|
|
}
|
|
if (navigator.appName.indexOf("Microsoft") != -1) {
|
|
return document.body.offsetHeight - 20;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Active window window
|
|
*/
|
|
function ActiveWindowWidth() {
|
|
if (parseInt(navigator.appVersion) > 3) {
|
|
if (navigator.appName=="Netscape") {
|
|
return window.innerWidth - 16;
|
|
}
|
|
if (navigator.appName.indexOf("Microsoft") != -1) {
|
|
return document.body.offsetWidth - 20;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Print layout (hide skin items)
|
|
*/
|
|
function PrintLayout() {
|
|
// Store old values to restore
|
|
var header_height = getElement('header').style.height;
|
|
var led_height = getElement('greenled').style.height;
|
|
var body_background = document.body.style.background;
|
|
|
|
getElement('content_table_col1').style.visibility = 'hidden';
|
|
getElement('header').style.visibility = 'hidden';
|
|
getElement('header').style.height = '150px';
|
|
getElement('svg_logo').style.visibility = 'visible';
|
|
getElement('footer_container').style.visibility = 'hidden';
|
|
getElement('greenled').style.height = '0px';
|
|
getElement('redled').style.height = '0px';
|
|
document.body.style.background = '#ffffff';
|
|
|
|
// Show print popup
|
|
window.print();
|
|
|
|
getElement('content_table_col1').style.visibility = 'visible';
|
|
getElement('header').style.visibility = 'visible';
|
|
getElement('header').style.height = header_height;
|
|
getElement('svg_logo').style.visibility = 'visible';
|
|
getElement('footer_container').style.visibility = 'visible';
|
|
getElement('greenled').style.height = led_height;
|
|
getElement('redled').style.height = led_height;
|
|
document.body.style.background = body_background;
|
|
} |