/* Constants */ var AXIS_X = 0; var AXIS_Y = 1; /*Shortcut to getElementById*/ function grabId(elementId) { var object = document.getElementById(elementId); return object; } /* Another shortcut to getElementById */ function getNode(node) { return document.getElementById(node); } /* Destroy a node with the Death Star */ function killNode(nodeID) { var node = getNode(nodeID); var nodeParent = node.parentElement; if (typeof nodeParent != "undefined") { nodeParent.removeChild(node); } else { node.style.display = "none"; } } /* Replace text in a node. */ function swapTextNode(parentObject, newText) { parentObject.replaceChild(document.createTextNode(newText), parentObject.firstChild); } /* Replace text in a node. Has more protection than the previous version and will fall back on non-DOM techniques if it can't pick out the childNodes */ function replaceInnerText(node, text) { // replacement for node.innerHTML = text; which is apparently broken in Safari 1.2.4 if (typeof node.childNodes != "undefined" && node.childNodes.length > 0) { var newnode = document.createTextNode(text); node.replaceChild(newnode, node.firstChild); } else { // fall back on the old school just in case node.innerHTML = text; } } /* Cross browser solution to DOM getComputedStyle() (Safari doesn't currently support this) */ function grabComputedStyle(elementObject) { if (document.defaultView && document.defaultView.getComputedStyle ) { return document.defaultView.getComputedStyle(elementObject, null); } else if (elementObject.currentStyle) { return elementObject.currentStyle; } else { return null; } } /* Return the target node for an event. */ function getEventTarget(evt) { var tgt = evt.srcElement; if (!tgt) tgt = evt.target; return tgt; } /* Clear out any text that may have been selected (called "ranges") by dragging the mouse mid-click. */ function clearRanges(event) { if (isMacIE) { // Mac IE is blowing up } else if (document.selection) { // IE 6 document.selection.empty(); } else if (window.getSelection()) { // NS 6 window.getSelection().removeAllRanges(); } else { // Safari, etc. event.stopPropagation(); } } /* How much the document's been scrolled vertically. Needed for correcting position calculations. */ function getDocumentScrollAmount() { if (!isSafari) { return document.body.scrollTop; } else { return 0; } } /* Computes the total vertical offset of a node, the sum of the enclosing objects' vertical offset. */ function getElementOffsetY(element) { var totalOffset = 0; if (element.offsetTop != null) { totalOffset += element.offsetTop; while (element.offsetParent) { totalOffset += element.offsetParent.offsetTop; element = element.offsetParent; } } return totalOffset; } /* Computes the total horizontal offset of a node, the sum of the enclosing objects' horizontal offset. */ function getElementOffsetX(element) { var totalOffset = 0; if (element.offsetLeft != null) { totalOffset += element.offsetLeft; while (element.offsetParent) { totalOffset += element.offsetParent.offsetLeft; element = element.offsetParent; } } return totalOffset; } /* Gets the position of the top of a node. */ function getNodeTop(nodeId) { var itemOver = document.getElementById(nodeId); var itemOverTop = itemOver.style.top ? (itemOver.offsetTop - stripUnits(itemOver.style.top)) : itemOver.offsetTop; return itemOverTop; } /* Moves an object vertically. Pass in either the node or the node's ID. If amount is positive, move it down. Negative? Move it up. */ function moveNode(mover, amount) { if (typeof mover == "string") mover = getNode(mover); if (mover.style.top) { mover.style.top = stripUnits(mover.style.top) + amount + "px"; } else { mover.style.top = (amount) + "px"; } } /* Debug utility; displays all of the properties of an object in a popup */ function displayObject(obj) { var msg = ""; for (var prop in obj) { msg += prop; msg += ": "; msg += prop.value; msg += "\n"; } window.alert(msg); }