home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2006 May
/
PCWMAY06.iso
/
javascript
/
menuItem.js
< prev
Wrap
Text File
|
2003-09-22
|
19KB
|
609 lines
// MOUSEOVER AND MENU OPENING FUNCTIONS
function menuMouse(n)
{
var myObj = getObject("menubox" + n);
var theobj;
if (menu[n].opened)
{
if (IE4 && (testEventElement(n) || !old) || NN6)
{
myObj.clip = "rect(0px " + menu[n].width + "px " + menu[n].height + "px 0px)";
if (NN6)
{
for (var i = 0; i < menu[n].subnames.length; i++ )
{
theobj = getObject(stripUnderscores(menu[n].subnames[i],"space"));
theobj.visibility = "hidden";
}
theobj = getObject("nn6bg" + n);
theobj.visibility = "hidden";
}
loLight(n);
menu[n].opened = false;
}
} else if (NN6 || window.event.type == "mouseover")
{
var h = (menu[n].subnames.length * (menu[n].subheight + menu[n].subvspace)) + menu[n].height + menu[n].vspace;
var w = menu[n].width;
if (menu[n].subwidth > menu[n].width)
{
w = menu[n].subwidth;
}
myObj.clip = "rect(0px " + w + "px " + h + "px 0px)";
if (NN6)
{
for (var i = 0; i < menu[n].subnames.length; i++ )
{
theobj = getObject(stripUnderscores(menu[n].subnames[i],"space"));
theobj.visibility = "visible";
}
theobj = getObject("nn6bg" + n);
theobj.visibility = "visible";
}
hiLight(n);
menu[n].opened = true;
}
}
function testEventElement(n)
{
if (!window.event.toElement)
return true;
else if (!window.event.toElement.parentElement)
return true;
else if (!window.event.toElement.parentElement.parentElement)
return true;
else if ((window.event.toElement.parentElement.parentElement && window.event.toElement.parentElement.parentElement.id != "menubox" + n) && (window.event.toElement.parentElement && window.event.toElement.parentElement.id != "menubox" + n))
return true;
else
return false;
}
function moveAct(evt)
{
var clickX = evt.pageX;
var clickY = evt.pageY;
for (var i = document.layers.length-1; i > 0; i--)
{
var testObj = document.layers[i];
if (testObj.id.indexOf("menubox") == -1)
{
continue;
}
else if ((clickX > testObj.left) && (clickX < testObj.left + testObj.clip.width) && (clickY > testObj.top) && (clickY < testObj.top + testObj.clip.height))
{
if (menuCheck(parseInt(testObj.id.charAt(testObj.id.length-1))))
{
break;
}
}
else
{
closeMenu(testObj.id.charAt(testObj.id.length-1));
}
}
}
function menuCheck(n)
{
if (!menu[n].opened)
{
if (!(menu[n+1] && menu[n+1].opened))
{
openMenu(n);
return true;
}
else
{
return true;
}
}
else if (menu[n+1] && menu[n+1].opened)
{
closeMenu(n);
return true;
}
return false;
}
function closeMenu(n)
{
loLight(n);
myObj = getObject("menubox" + n);
myObj.clip.bottom = menu[n].height;
menu[n].opened = false;
}
function openMenu(n)
{
hiLight(n);
myObj = getObject("menubox" + n);
var c = menu[n].height + menu[n].vspace;
for (var i = 0; i < menu[n].subnames.length; i++)
{
c += menu[n].subheight + menu[n].subvspace;
}
if (menu[n].subwidth > menu[n].width)
{
myObj.clip.width = menu[n].subwidth;
}
myObj.clip.bottom = c;
menu[n].opened = true;
}
function hiLight(i,j)
{
var myimage,pic;
if (j == 0 || j)
{
var myObj = getObject(stripUnderscores(menu[i].subnames[j],"space"),"menubox"+i);
if (NN4)
{
myObj.visibility = "show";
}
else if (IE4 || NN6)
{
myObj.cursor = "hand";
myObj.backgroundColor = "#686AAC";
if (NN6)
{
myObj = getObject(stripUnderscores(menu[i].subnames[j],"space") + "ff");
if (menu[i].sublow)
{
pic = findImage("arrow_" + stripUnderscores(menu[i].subnames[j],"space"));
pic.src = menu[i].subhigh.src;
}
}
else
{
if (menu[i].sublow)
{
pic = getObject("arrow_" + stripUnderscores(menu[i].subnames[j],"space"));
pic.visibility = "hidden";
}
}
myObj.color = "#DADDEF";
}
}
else if (IE4 || NN6)
{
myObj = getObject(menu[i].name + "imagehi","menubox"+i);
myObj.visibility = "visible";
}
else
{
myimage = findImage(menu[i].name);
myimage.src = menu[i].highlight.src;
}
}
function loLight(i,j)
{
var myimage,pic;
if (j == 0 || j)
{
var myObj = getObject(stripUnderscores(menu[i].subnames[j],"space"),"menubox"+i);
if (NN4)
{
myObj.visibility = "hide";
}
else if (IE4 || NN6)
{
myObj.backgroundColor = "#DADDEF";
if (NN6)
{
myObj = getObject(stripUnderscores(menu[i].subnames[j],"space") + "ff");
if (menu[i].sublow)
{
pic = findImage("arrow_" + stripUnderscores(menu[i].subnames[j],"space"));
pic.src = menu[i].sublow.src;
}
}
else
{
if (menu[i].sublow)
{
pic = getObject("arrow_" + stripUnderscores(menu[i].subnames[j],"space"));
pic.visibility = "visible";
}
}
myObj.color = "#686AAC";
}
}
else if (IE4 || NN6)
{
myObj = getObject(menu[i].name + "imagehi","menubox"+i);
myObj.visibility = "hidden";
}
else
{
myimage = findImage(menu[i].name);
myimage.src = menu[i].img.src;
}
}
// END MENU OPENING ETC FUNCTIONS
// CREATE AN ARRAY OF MENU OBJECTS
var menu = [];
function menuItem(imgLo,imgHigh,name,action)
{
// Set menu item action
if (action)
{
this.action = action;
}
else if (name)
{
this.action = "/" + globalPath + "/" + stripUnderscores(name,"%20");
}
// Set closed image
if (imgLo)
{
this.img = new Image();
this.img.src = imgPath + imgLo;
}
// Set highlighted image
if (imgHigh)
{
this.highlight = new Image();
this.highlight.src = imgPath + imgHigh;
}
if (name)
{
this.name = stripUnderscores(name,"space");
}
menu[menu.length] = this;
this.subactions = [];
this.subnames = [];
}
function addSubMenu(name,action)
{
if (name)
{
this.subnames[this.subnames.length] = name;
if (action)
{
this.subactions[this.subactions.length] = action;
}
else
{
this.subactions[this.subactions.length] = this.action + "/" + stripUnderscores(name,"%20");
}
}
else
{
this.subnames[this.subnames.length] = null;
this.subactions[this.subactions.length] = null;
}
}
menuItem.prototype.opened = false;
menuItem.prototype.action = null;
menuItem.prototype.img = null;
menuItem.prototype.name = null;
menuItem.prototype.sublow = null;
menuItem.prototype.addSubMenu = addSubMenu;
function setOptionalSubmenuImages(hi,lo,w,h)
{
menuItem.prototype.subhigh = new Image();
menuItem.prototype.subhigh.src = imgPath + hi;
menuItem.prototype.subimgwidth = w;
menuItem.prototype.subimgheight = h;
menuItem.prototype.sublow = new Image();
menuItem.prototype.sublow.src = imgPath + lo;
}
function setGlobalMainSizes(w,h)
{
if (w)
{
menuItem.prototype.width = w;
}
else
{
menuItem.prototype.width = null;
}
if (h)
{
menuItem.prototype.height = h;
}
else
{
menuItem.prototype.height = null;
}
}
function setGlobalSubSizes(w,h)
{
if (w)
{
menuItem.prototype.subwidth = w;
}
else
{
menuItem.prototype.subwidth = null;
}
if (h)
{
menuItem.prototype.subheight = h;
}
else
{
menuItem.prototype.subheight = null;
}
}
function setGlobalSpaces(h,v,subv,space)
{
menuItem.prototype.hspace = h;
menuItem.prototype.vspace = v;
menuItem.prototype.subvspace = subv;
if (space)
{
menuItem.prototype.space = space;
}
else
{
menuItem.prototype.space = null;
}
}
// END MENU OBJECT ARRAY CREATION
// PAGE INITIALISATION FUNCTIONS
function HMenuInit()
{
var xpos = 0;
var maxheight = 0;
for (var i = 0; i < menu.length; i++)
{
myObj = getObject("menubox" + i);
if (IE4 || NN6)
{
myObj.clip = "rect(0px " + menu[i].width + "px " + menu[i].height + "px 0px)";
if (NN6)
{
myObj.left = (xpos + nn6_posX) + "px";
myObj.top = nn6_posY + "px";
for (var j = 0; j < menu[i].subnames.length; j++)
{
subobj = getObject(stripUnderscores(menu[i].subnames[j],"space"));
subobj.top = (menu[i].height + (menu[i].subheight * j) + menu[i].vspace + (menu[i].subvspace * j)) + "px";
}
}
else
{
myObj.left = xpos + "px";
}
if (menu[i].height > maxheight)
{
maxheight = menu[i].height;
}
myObj.visibility = "visible";
}
else if (NN4)
{
myObj.width = menu[i].subwidth;
myObj.height = menu[i].height;
myObj.left = document.posItem.pageX + xpos;
myObj.moveToAbsolute(myObj.pageX,document.posItem.pageY);
myObj.visibility = "show";
}
xpos += menu[i].width
if (i < menu.length-1)
{
xpos += menu[i].hspace;
}
}
if (!NN6)
{
myObj = getObject("posItem");
if (IE4)
{
myObj.height = maxheight;
myObj.width = xpos - menu[menu.length-1].hspace;
}
else if (NN4)
{
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = moveAct;
}
myObj.visibility = "visible";
}
}
// END INITIALISATION FUNCTIONS
// WRITE THE NAVBAR
function renderHMenu()
{
var w = 0;
var xx = "";
var sp;
var maxheight = 0;
if (IE4)
{
xx += "<div id=\"posItem\">\n";
}
for (var i = 0; i < menu.length; i++)
{
w += menu[i].width;
if (i < menu.length)
{
w += menu[i].hspace;
}
if (IE4)
{
xx += "<span id=\"menubox"+ i + "\" class=\"menuholder\" onMouseover=\"menuMouse(" + i + ")\" onMouseout=\"menuMouse(" + i + ")\">\n<a href=\"" + menu[i].action + "\" target=\"_top\"><img id=\"" + menu[i].name + "imagelo\" class=\"hmMainImageLo\" src=\"" + menu[i].img.src + "\" border=0 width=" + menu[i].width + " height=" + menu[i].height + " alt=\"\"></a>\n<a href=\"" + menu[i].action + "\" target=\"_top\"><img id=\"" + menu[i].name + "imagehi\" class=\"hmMainImageHi\" src=\"" + menu[i].highlight.src + "\" border=0 width=" + menu[i].width + " height=" + menu[i].height + " alt=\"\"></a>\n";
}
else if (NN6)
{
xx += "<span id=\"menubox"+ i + "\" class=\"menuholder\" onMouseover=\"menuMouse(" + i + ")\" onMouseout=\"menuMouse(" + i + ")\">\n<div id=\"" + menu[i].name + "imagelo\" class=\"hmMainImageLo\"><a href=\"" + menu[i].action + "\" target=\"_top\"><img src=\"" + menu[i].img.src + "\" border=0 width=" + menu[i].width + " height=" + menu[i].height + " alt=\"\"></a></div>\n<div id=\"" + menu[i].name + "imagehi\" class=\"hmMainImageHi\"><a href=\"" + menu[i].action + "\" target=\"_top\"><img SRC=\"" + menu[i].highlight.src + "\" border=0 width=" + menu[i].width + " height=" + menu[i].height + " alt=\"\"></a></div>\n";
}
else if (NN4)
{
xx += "<layer id=\"menubox"+ i + "\" class=\"menuholderNN4\" visibility=\"hide\" clip=\"" + menu[i].width + "," + menu[i].height +"\">\n<a href=\"" + menu[i].action + "\" target=\"_top\"><img name=\"" + menu[i].name + "\" src=\"" + menu[i].img.src + "\" border=0 width=" + menu[i].width + " height=" + menu[i].height + " alt=\"\"></a><br>\n";
}
if (menu[i].vspace)
{
menu[i].subwidth > menu[i].width ? sp = menu[i].width : sp = menu[i].subwidth;
if (!NN6)
{
xx += "<img style=\"filter:alpha(opacity=" + opacity + ")\" src=\"" + imgPath + menu[i].space + "\" height=\"" + menu[i].vspace + "\" width=\"" + sp + "\" border=0><br>\n";
}
else if (NN6)
{
var nn6h = menu[i].vspace + ((menu[i].subvspace + menu[i].subheight) * menu[i].subnames.length);
xx += "<div id=\"nn6bg" + i + "\" class=\"nn6bghide\"><img src=\"" + imgPath + menu[i].space + "\" height=\"" + nn6h + "\" width=\"" + menu[i].subwidth + "\" border=0></div>\n";
}
}
for (var j = 0; j < menu[i].subnames.length; j++)
{
if (IE4)
{
xx += "<div id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "\" class=\"hmSubitem\" style=\"width:" + menu[i].subwidth + "; height:" + menu[i].subheight + "\" onMouseover=\"hiLight(" + i + "," + j + ")\" onMouseout=\"loLight(" + i + "," + j + ")\" onClick=\"top.location='" + menu[i].subactions[j] + "'\">\n";
if (menu[i].sublow)
{
xx += "<img id=\"arrow2_" + stripUnderscores(menu[i].subnames[j],"space") + "\" style=\"position:absolute; left:" + (menu[i].subwidth - menu[i].subimgwidth) + "px\" src=\"" + menu[i].subhigh.src + "\" width=" + menu[i].subimgwidth + " height=" + menu[i].subimgheight + " border=0 alt=\"\">\n<img id=\"arrow_" + stripUnderscores(menu[i].subnames[j],"space") + "\" style=\"position:absolute; left:" + (menu[i].subwidth - menu[i].subimgwidth) + "px\" src=\"" + menu[i].sublow.src + "\" width=" + menu[i].subimgwidth + " height=" + menu[i].subimgheight + " border=0 alt=\"\">";
}
xx += menu[i].subnames[j] + "</div>\n";
}
else if (NN6)
{
xx += "<a href=\"" + menu[i].subactions[j] + "\" onMouseover=\"hiLight(" + i + "," + j + ")\" onMouseout=\"loLight(" + i + "," + j + ")\" target=\"_top\"><div id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "\" class=\"imgbox\" style=\"width:" + menu[i].subwidth + "px; height:" + menu[i].subheight + "px\">\n";
if (menu[i].sublow)
{
xx += "<img id=\"arrow_" + stripUnderscores(menu[i].subnames[j],"space") + "\" src=\"" + menu[i].sublow.src + "\" width=" + menu[i].subimgwidth + " height=" + menu[i].subimgheight + " border=0 align=RIGHT alt=\"\">";
}
xx += "<nobr><a class=\"lowlit\" id= \"" + stripUnderscores(menu[i].subnames[j],"space") + "ff\" href=\"" + menu[i].subactions[j] + "\" target=\"_top\">" + menu[i].subnames[j] + "</a></nobr><br></div></a>\n";
}
else if (NN4)
{
xx += "<ilayer id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "\" class=\"nn4Layer\" width=" + menu[i].subwidth + " height=" + menu[i].subheight + " clip=\"" + menu[i].subwidth + "," + menu[i].subheight + "\">\n";
xx += "<layer id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "xx\" class=\"nn4Layer\" bgcolor=\"#DADDEF\" width=" + menu[i].subwidth + " height=" + menu[i].subheight + " clip=\"" + menu[i].subwidth + "," + menu[i].subheight + "\">";
if (menu[i].sublow)
{
xx += "<img src=\"" + menu[i].sublow.src + "\" width=" + menu[i].subimgwidth + " height=" + menu[i].subimgheight + " border=0 align=RIGHT alt=\"\">";
}
xx += "<a class=\"lowlit\"><nobr> " + menu[i].subnames[j] + "</nobr></a></layer>\n";
xx += "<layer id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "x\" class=\"nn4Layer\" bgcolor=\"#686AAC\" width=" + menu[i].subwidth + " height=" + menu[i].subheight + " visibility=\"hide\">";
if (menu[i].sublow)
{
xx += "<img src=\"" + menu[i].subhigh.src + "\" width=" + menu[i].subimgwidth + " height=" + menu[i].subimgheight + " border=0 align=RIGHT alt=\"\">";
}
xx += "<a class=\"highlit\"><nobr> " + menu[i].subnames[j] + "</nobr></a></layer>\n";
xx += "<layer id=\"" + stripUnderscores(menu[i].subnames[j],"space") + "xxx\" class=\"nn4Layer\" width=" + menu[i].subwidth + " height=" + menu[i].subheight + " clip=\"" + menu[i].subwidth + "," + menu[i].subheight + "\" Z-INDEX=\"99\"><a href=\"" + menu[i].subactions[j] + "\" onMouseover=\"hiLight(" + i + "," +j + ")\" onMouseout=\"loLight(" + i + "," +j + ")\" target=\"_top\"><img src=\"" + imgPath + "v6_trans.gif\" width=" + menu[i].subwidth + " height=" + menu[i].subheight + " border=0 alt=\"\"></a></layer>\n";
xx += "</ilayer><br>\n";
}
if (menu[i].subvspace && !NN6)
{
xx += "<img style=\"filter:alpha(opacity=" + opacity + ")\" src=\"" + imgPath + menu[i].space + "\" height=\"" + menu[i].subvspace + "\" width=\"" + menu[i].subwidth + "\" border=0><br>\n";
}
}
if (IE4 || NN6)
{
xx += "</span>\n";
}
else if (NN4)
{
xx += "</layer>\n";
if (menu[i].height > maxheight)
{
maxheight = menu[i].height;
}
}
}
if (IE4)
{
xx += "</div>";
}
else if (NN4)
{
xx = "<div id=\"posItem\"><img src=\"" + imgPath + menu[0].space + "\" width=" + (w - menu[menu.length-1].hspace) + " height=" + maxheight + " border=0></div>\n" + xx;
}
document.write(xx);
document.close();
}
function stripUnderscores(str,rplc)
{
if (!rplc)
{
rplc = " ";
}
if (rplc == "space")
{
while (str.indexOf(" ") != -1)
{
str = str.substring(0,str.indexOf(" ")) + "" + str.substring(str.indexOf(" ")+1);
}
}
while (str.indexOf("_") != -1)
{
str = str.substring(0,str.indexOf("_")) + rplc + str.substring(str.indexOf("_")+1);
}
while (str.indexOf("$$") != -1)
{
str = str.substring(0,str.indexOf("$$")) + "-" + str.substring(str.indexOf("$$")+2);
}
while (str.indexOf("xxyxx") != -1)
{
str = str.substring(0,str.indexOf("xxyxx")) + "'" + str.substring(str.indexOf("xxyxx")+5);
}
while (str.indexOf(" and ") != -1)
{
str = str.substring(0,str.indexOf(" and ")) + " & " + str.substring(str.indexOf(" and ")+5);
}
while (str.indexOf(".") != -1)
{
str = str.substring(0,str.indexOf(".")) + str.substring(str.indexOf(".")+1);
}
return str;
}
var subject;
var forumid = [1,2,3,4,5,6,8];
function renderSubjectMenu()
{
var sm = "";
var bs = "";
var bh = "";
for (var i = 0; i < menu.length; i++)
{
var n = stripUnderscores(menu[i].name);
if (n == subject)
break;
}
sm += "<div class=\"largegap\"><div class=\"largemauvebold\">" + n + "</div></div><table width=\"100%\" CELLPADDING=2 CELLSPACING=0 border=0>";
for (var j = 0; j < menu[i].subnames.length; j++)
{
sm += "<tr><td width=11 valign=TOP><a href=\"" + menu[i].subactions[j] + "\"><img src=\"" + imgPath + "v6_arrow_vnu.gif\" width=7 height=7 VSPACE=3 border=0 alt=\"\"></a></td><td><a class=\"midmauvelink\" href=\"" + menu[i].subactions[j] + "\">" + menu[i].subnames[j] + "</a></td></tr>";
}
if (!(n == "Personal computing" || n == "Gaming"))
{
bs += "<tr><td width=11 valign=TOP><a class=\"midmauvelink\" href=\"/CSS/index.jsp\"><img src=\"" + imgPath + "v6_arrow_vnu.gif\" width=7 height=7 VSPACE=3 border=0 alt=\"\"></a></td><td><div class=\"midmauve\" style=\"font-size:12px\"><a class=\"midmauvelink\" href=\"/CSS/index.jsp\">Service locator</a></div></td></tr>";
}
bh += "<tr><td width=11 valign=TOP><a class=\"midmauvelink\" href=\"/Registration/index.jsp?regSource=NEWSLETTER\"><img src=\"" + imgPath + "v6_arrow_vnu.gif\" width=7 height=7 VSPACE=3 border=0 alt=\"\"></a></td><td><div class=\"midmauve\" style=\"font-size:12px\"><a class=\"midmauvelink\" href=\"/Registration/index.jsp?regSource=NEWSLETTER\">" + n + " Newsletter</a></div></td></tr><tr><td width=11 valign=TOP><a class=\"midmauvelink\" href=\"/forums/forum.jsp?forum=" + forumid[i] + "\"><img src=\"" + imgPath + "v6_arrow_vnu.gif\" width=7 height=7 VSPACE=3 border=0 alt=\"\"></a></td><td><div class=\"midmauve\" style=\"font-size:12px\"><a class=\"midmauvelink\" href=\"/forums/forum.jsp?forum=" + forumid[i] + "\">" + n + " forum</a></div></td></tr></table>";
sm += bs + bh;
document.writeln(sm);
}