/**************************************************************************************** * * CORE DYNAMIC DIALOG FUNCTIONS * Version 1.0 * Code dependancies: None * Type library * Author: Oliver Ammann * *****************************************************************************************/ /** * Function: preLoad(images) * Image preload function to load a variable number of images * This function will be moved to webUtils * @param type: array. Description: Passes image array to function */ function preLoad(images) { imgArr = new Array(images.length); for (i = 0; i < images.length; i++) { imgArr[i] = new Image(); imgArr[i].src = images[i]; } } /** * Function: doPopUp() * General function to generate a popup window * This function will be moved to webUtils */ function doPopUp(getUrl,getWidth,getHeight,getScrollVal) { if (getScrollVal.toLowerCase() == "y") { getScrollVal = "yes"; } else if (getScrollVal.toLowerCase() == "n") { getScrollVal.toLowerCase() = "no"; } else { getScrollVal = "yes" } win = window.open(getUrl,"myWin","width="+getWidth+",height="+getHeight+ ",resizable=0,menubar=1,scrollbars="+getScrollVal+",left=100,top=20"); } /** * Function: doUpdateState(id) * Due to IE6's bad DOM implementation we have to build a custom state * management function for the opt in checkbox. We cannot rely on the * checked attribute to determine if a user has checked or unchecked * the checkbox. This function keeps track of the state by updating * a hidden form field with the appropriate state. * @param type: string name: id Description: Passes the element id to the function */ function doUpdateState(id) { var getState = document.getElementById(id).value; if (getState == 'false') { document.getElementById(id).value = 'true'; } else { document.getElementById(id).value = 'false'; } } /** * Function: closeIframe() * Dynamically removes the first iframe on the page */ function closeIframe() { var ifrm = document.getElementsByTagName('iframe')[0]; ifrm.parentNode.removeChild(ifrm); } /** * Function: removeChildNodes(parentNode) * Dynamically removes all childeren from a parent node */ function removeChildNodes(parentNode) { if (parentNode.hasChildNodes()) { while (parentNode.childNodes.length >= 1) { parentNode.removeChild(parentNode.firstChild); } } } /** * Function: attachProgressToElement(element, cssClass, msgStr, textColor) * Attaches a progress indicator to a dom element */ function attachProgressToElement(element, cssClass, msgStr, textColor) { try { element.className = cssClass; element.style.color = textColor; element.appendChild(document.createTextNode(msgStr)); } catch(error) { return true; } return false; } /** * Function: closeDialog(dialog) * This function closes the dialog box and removes * the dropsheet */ function closeDialog(dialog, cssClass) { var dropSheet = document.getElementById(cssClass); dropSheet.parentNode.removeChild(dropSheet); dialog.parentNode.removeChild(dialog); return true; } /** * Function: addLoadListener(fn) * This function implements a crossbrowser version * of the evenListener */ function addLoadListener(fn) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', fn, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener('load', fn, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', fn); } else { var oldfn = window.onload; if (typeof window.onload != 'function') { window.onload = fn; } else { window.onload = function() { oldfn(); fn(); }; } } } /** * Function: attachEventListener(target, eventType, functionRef, capture) * This function binds functions to target elements */ function attachEventListener(target, eventType, functionRef, capture) { if (typeof target.addEventListener != "undefined") { target.addEventListener(eventType, functionRef, capture); } else if (typeof target.attachEvent != "undefined") { target.attachEvent("on" + eventType, functionRef); } else { eventType = "on" + eventType; if (typeof target[eventType] == "function") { var oldListener = target[eventType]; target[eventType] = function() { oldListener(); return functionRef(); } } else { target[eventType] = functionRef; } } return true; } /** * Function: getEventTarget(event) * Helper function for dialogClick(event) */ function getEventTarget(event) { var targetElement = null; if (typeof event.target != "undefined") { targetElement = event.target; } else { targetElement = event.srcElement; } while (targetElement.nodeType == 3 && targetElement.parentNode != null) { targetElement = targetElement.parentNode; } return targetElement; } /** * Function: getScrollingPosition() * Gets the scrolling position of the parent page */ function getScrollingPosition() { //array for X and Y scroll position var position = [0, 0]; //if the window.pageYOffset property is supported if (typeof window.pageYOffset != 'undefined') { //store position values position = [window.pageXOffset, window.pageYOffset]; } //if the documentElement.scrollTop property is supported //and the value is greater than zero if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) { //store position values position = [document.documentElement.scrollLeft, document.documentElement.scrollTop]; //if the body.scrollTop property is supported } else if(typeof document.body.scrollTop != 'undefined') { //store position values position = [document.body.scrollLeft, document.body.scrollTop]; } //return the array return position; } /** * Function: getViewportSize() * Gets the available viewport size */ function getViewportSize() { var size = [0,0]; if (typeof window.innerWidth != 'undefined') { size = [window.innerWidth, window.innerHeight]; } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { size = [document.documentElement.clientWidth, document.documentElement.clientHeight]; } else { size = [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight]; } return size; } /** * Function: getPageDimensions() * Gets the page dimension */ function getPageDimensions() { var body = document.getElementsByTagName("body")[0]; var bodyOffsetWidth = 0; var bodyOffsetHeight = 0; var bodyScrollWidth = 0; var bodyScrollHeight = 0; var pageDimensions = [0, 0]; if (typeof document.documentElement != "undefined" && typeof document.documentElement.scrollWidth != "undefined") { pageDimensions[0] = document.documentElement.scrollWidth; pageDimensions[1] = document.documentElement.scrollHeight; } bodyOffsetWidth = body.offsetWidth; bodyOffsetHeight = body.offsetHeight; bodyScrollWidth = body.scrollWidth; bodyScrollHeight = body.scrollHeight; if (bodyOffsetWidth > pageDimensions[0]) { pageDimensions[0] = bodyOffsetWidth; } if (bodyOffsetHeight > pageDimensions[1]) { pageDimensions[1] = bodyOffsetHeight; } if (bodyScrollWidth > pageDimensions[0]) { pageDimensions[0] = bodyScrollWidth; } if (bodyScrollHeight > pageDimensions[1]) { pageDimensions[1] = bodyScrollHeight; } return pageDimensions; }