/**** This needed to work in Mac IE, which has flakey support for document.getElementsByName so we'll use document.all if its supported. It still doesnt work terribly well on that platform...and the increasing amount of if(document.all) in the code was starting to turn my stomach so i decided to leave it as is for Mac IE. Ideally I'd like to see Mac IE go the way of NS4.x in terms of developer support...but sadly that's yet to happen. ****/ var activeNode = -1; var objLength; function init() { objLength = document.all?document.all.nContainer.length:document.getElementsByName("nContainer").length; } function doSwapNode(direction) { activeNode = findNode(); if(activeNode == -1) return alert("Please select an object to move."); mDIV = document.all?document.all.nContainer[activeNode].cloneNode(true):document.getElementsByName("nContainer")[activeNode].cloneNode(true); if(direction) { if(activeNode+1 == objLength)return; if(activeNode+2 == objLength) { if(document.all) { document.getElementById("mContainer").insertBefore(mDIV); document.getElementById("mContainer").removeChild(document.all.nContainer[activeNode]); } else { document.getElementById("mContainer").insertBefore(mDIV,document.getElementsByName("nContainer")[objLength+2]); document.getElementById("mContainer").removeChild(document.getElementsByName("nContainer")[activeNode]); } } else { if(document.all) { document.getElementById("mContainer").insertBefore(mDIV,document.all.nContainer[activeNode+2]); document.getElementById("mContainer").removeChild(document.all.nContainer[activeNode]); } else { document.getElementById("mContainer").insertBefore(mDIV,document.getElementsByName("nContainer")[activeNode+2]); document.getElementById("mContainer").removeChild(document.getElementsByName("nContainer")[activeNode]); } } } else { if(activeNode-1< 0)return; if(document.all) { document.getElementById("mContainer").insertBefore(mDIV,document.all.nContainer[activeNode-1]); document.getElementById("mContainer").removeChild(document.all.nContainer[activeNode+1]); } else { document.getElementById("mContainer").insertBefore(mDIV,document.getElementsByName("nContainer")[activeNode-1]); document.getElementById("mContainer").removeChild(document.getElementsByName("nContainer")[activeNode+1]); } } } function findNode() { for(i=0;i<objLength;i++) { if(document.all) { if(document.all.nContainer[i].style.backgroundColor == "blue") { return i; break; } } else { if(document.getElementsByName("nContainer")[i].style.backgroundColor == "blue") { return i; break; } } } return -1; } function setColor() { if(document.all) { for(i=0;i<objLength;i++)document.all.nContainer[i].style.backgroundColor="#FFFFFF"; } else { for(i=0;i<objLength;i++)document.getElementsByName("nContainer")[i].style.backgroundColor="#FFFFFF"; } }
swapNode v1.0 last revision: 06.23.2003 steve@slayeroffice.com http://slayeroffice.com |