Google Answers Logo
View Question
 
Q: Global Javascript Question ( No Answer,   8 Comments )
Question  
Subject: Global Javascript Question
Category: Computers > Programming
Asked by: scottpes-ga
List Price: $20.00
Posted: 15 Jul 2003 09:24 PDT
Expires: 17 Jul 2003 07:43 PDT
Question ID: 231256
I have a dropdown navigation menu on my website www.pesquality.com. 
There is a very lengthy script for the menu copied on all the pages of
the website.  If I were to add or delete a page I would need to edit
the script as necessary and re-copy it onto all pages.  My question is
this:  Is there a way to use this script globally such as in a .js or
other file that would only need to be changed in one place and all
pages would not need to be updated?  If so, could you let me know how
to do this?

Request for Question Clarification by sgtcory-ga on 15 Jul 2003 13:55 PDT
Hello scottpes,

I think I understand the question correctly. You can create a single
Javascript file, and upload it to your server. You would then need to
link to this file in the header of each HTML document, like this :


<script type='text/javascript' src='YOUR_FILE_NAME_HERE.js'></script>


Is this what you are trying to accomplish? If not, can you offer a
little more insight. If this is indeed what you need to do, I can make
the Javascript file for you, and all you would need to do is add it to
your server, and link to it from each HTML page.

This would then make changes in navigation as simple as changing the
one file. Thanks in advance for the clarification.

SgtCory

Request for Question Clarification by sgtcory-ga on 15 Jul 2003 13:57 PDT
I just noticed I essentially repeated the instructions given by
stephenvakil. Should you still need further assistance, I will do all
I can to help. Sorry about the confusion -

SgtCory

Clarification of Question by scottpes-ga on 16 Jul 2003 06:49 PDT
Hi Sgtcory,

That is what I'd like to do but I just can't seem to make it work. 
Even after creating the newer file suggested by stephenvakil. If you
could create the file I need and let me know the exact onload or
bodyload tag I need to put into my code I would be very appreciative.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Global Javascript Question
From: stephenvakil-ga on 15 Jul 2003 09:43 PDT
 
I didn't read through the code fully, so forgive me if you've already
thought of this... but could you place all of the code that is outside
of functions into a single function such as BodyLoad and call that
function in the body onload event?

If this is possible you could then externalize the entire javascript
block into a js file.
Subject: Re: Global Javascript Question
From: scottpes-ga on 15 Jul 2003 10:26 PDT
 
I had not thought of the bodyload thing.  But that's because I didn't
(and still don't) know how to do it.  I got the code from a script
library on the web and edited it to fit what I needed.  There were
also pretty good instructions on how to put it into your HTML.  I
really only know enough about HTML programming to be dangerous.  I
understand the concept but I do not know HOW to go about doing what
you're talking about.  I certainly would appreciate some instruction. 
Thanks.
Subject: Re: Global Javascript Question
From: rohaab-ga on 15 Jul 2003 11:22 PDT
 
I use the Milonic DHTML menu; it has EVERYTHING in JavaScript; you
only have to INCLUDE the files.

Let me know if you want more information.
Subject: Re: Global Javascript Question
From: stephenvakil-ga on 15 Jul 2003 11:27 PDT
 
Well the code is a little messy right now.  The basic idea is to take
all of the lines of code that are within a function block and put them
into a text file that you save with a .js extention.

so basically, save the text below as a .js file then in your <HEAD>
tag before the title put this:

<script language=javascript src="{the filename that you just
saved}"></script>


The file would look something like this:

-----Begin .js File-----
function BodyLoad() {
	var isDOM = (document.getElementById ? true : false); 
	var isIE4 = ((document.all && !isDOM) ? true : false);
	var isNS4 = (document.layers ? true : false);

	var popTimer = 0;
	var litNow = new Array();

	var menu = new Array();

	var defOver = '#336699', defBack = '#003366';

	var defLength = 22;

	menu[0] = new Array();
	menu[0][0] = new Menu(false, '', 5, 0, 17, '#669999', '#006666', '',
'itemText');
	menu[0] = new Array();
	menu[0][0] = new Menu(false, '', 10, 0, 17, '#669999', '#006666', '',
'itemText');
	menu[0][1] = new Item(' Home', 'index.html', '', 30, 56, 0);
	menu[0][2] = new Item(' Manufacturers We Repair', '#', '', 150, 56,
2);
	menu[0][3] = new Item(' Other Services', '#', '', 88, 56, 3);
	menu[0][4] = new Item(' Information', '#', '', 58, 56, 1);
	menu[0][5] = new Item(' Downloads', 'literature.html', '', 50, 56,
0);
	menu[0][6] = new Item(' Helpful Formulas', 'formulas.html', '', 103,
56, 0);


	menu[1] = new Array();
	menu[1][0] = new Menu(true, '>', 0, 22, 110, defOver, defBack,
'itemBorder', 'itemText');
	menu[1][1] = new Item('About PES', 'aboutpes.html', '', defLength, 0,
0);
	menu[1][2] = new Item('Experience', 'experience.html', '', defLength,
0, 0);
	menu[1][3] = new Item('Policies/Warranty', 'policy.html', '',
defLength, 0, 0);
	menu[1][4] = new Item('FAQ', 'faqs.html', '', defLength, 0, 0);
	menu[1][5] = new Item('Testimonials', 'testimonials.html', '',
defLength, 0, 0);
	menu[1][6] = new Item('Directions', 'map.html', '', defLength, 0, 0);
	menu[1][7] = new Item('Employment', 'employment.html', '', defLength,
0, 0);
	menu[1][8] = new Item('Contact Us', 'support.html', '', defLength, 0,
0);

	menu[2] = new Array();
	menu[2][0] = new Menu(true, '>', 0, 22, 200, defOver, defBack,
'itemBorder', 'itemText');
	menu[2][1] = new Item('Factory Authorized', '#', '', defLength, 0,
4);
	menu[2][2] = new Item('Brands We Frequently Repair', '#', '',
defLength, 0, 6);
	menu[2][3] = new Item('All Manufacturers', '#', '', defLength, 0, 5);

	menu[3] = new Array();
	menu[3][0] = new Menu(true, '<', 0, 22, 90, defOver, defBack,
'itemBorder', 'itemText');
	menu[3][1] = new Item('Field Service', 'service.html', '', defLength,
0, 0);
	menu[3][2] = new Item('Engineering', 'surplus.html', '', defLength,
0, 0);

	menu[4] = new Array();
	menu[4][0] = new Menu(true, '>', 200, 0, 70, '#333366', '#666699',
'itemBorder', 'itemText');
	menu[4][1] = new Item('ABB', 'abb.html', '', defLength, 0, 0);
	menu[4][2] = new Item('Baldor', 'baldor.html', '', defLength, 0, 0);
	menu[4][3] = new Item('Danfoss', 'danfoss.html', '', defLength, 0,
0);
	menu[4][4] = new Item('Eurotherm', 'eurotherm.html', '', defLength,
0, 0);
	menu[4][5] = new Item('Fincor', 'fincor.html', '', defLength, 0, 0);
	menu[4][6] = new Item('Magnetek', 'magnetek.html', '', defLength, 0,
0);
	menu[4][7] = new Item('Saftronics', 'saftronics.html', '', defLength,
0, 0);
	menu[4][8] = new Item('Yaskawa', 'yaskawa.html', '', defLength, 0,
0);
	menu[4][9] = new Item('All', 'auth.html', '', defLength, 0, 0);


	menu[5] = new Array();
	menu[5][0] = new Menu(true, '>', 200, 0, 45, '#333366', '#666699',
'itemBorder', 'itemText');
	menu[5][1] = new Item('A - D', 'repair.html', '', defLength, 0, 0);
	menu[5][2] = new Item('E - I', 'repair2.html', '', defLength, 0, 0);
	menu[5][3] = new Item('J - N', 'repair3.html', '', defLength, 0, 0);
	menu[5][4] = new Item('O - S', 'repair4.html', '', defLength, 0, 0);
	menu[5][5] = new Item('T - Z', 'repair5.html', '', defLength, 0, 0);

	menu[6] = new Array();
	menu[6][0] = new Menu(true, '>', 200, 0, 100, '#333366', '#666699',
'itemBorder', 'itemText');
	menu[6][1] = new Item('Allen Bradley', 'allen_bradley.html', '',
defLength, 0, 0);
	menu[6][2] = new Item('Lenze', 'lenze.html', '', defLength, 0, 0);
	menu[6][3] = new Item('Modicon', 'squared.html', '', defLength, 0,
0);
	menu[6][4] = new Item('Powertec', 'powertec.html', '', defLength, 0,
0);
	menu[6][5] = new Item('Reliance', 'reliance.html', '', defLength, 0,
0);
	menu[6][6] = new Item('Siemens', 'siemens.html', '', defLength, 0,
0);
	menu[6][7] = new Item('Square D', 'squared.html', '', defLength, 0,
0);
	menu[6][8] = new Item('Telemecanique', 'squared.html', '', defLength,
0, 0);
	menu[6][9] = new Item('Toshiba', 'toshiba.html', '', defLength, 0,
0);






	var popOldWidth = window.innerWidth;
	nsResizeHandler = new Function('if (popOldWidth != window.innerWidth)
location.reload()');



	if (isNS4) document.captureEvents(Event.CLICK);
	document.onclick = clickHandle;
}

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}
function getSty(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
} 
function popOver(menuNum, itemNum) {
	clearTimeout(popTimer);
	hideAllBut(menuNum);
	litNow = getTree(menuNum, itemNum);
	changeCol(litNow, true);
	targetNum = menu[menuNum][itemNum].target;
	if (targetNum > 0) {
		thisX = parseInt(menu[menuNum][0].ref.left) +
parseInt(menu[menuNum][itemNum].ref.left);
		thisY = parseInt(menu[menuNum][0].ref.top) +
parseInt(menu[menuNum][itemNum].ref.top);
	with (menu[targetNum][0].ref) {
		left = parseInt(thisX + menu[targetNum][0].x);
		top = parseInt(thisY + menu[targetNum][0].y);
		visibility = 'visible';
      }
   }
}
function popOut(menuNum, itemNum) {
	if ((menuNum == 0) && !menu[menuNum][itemNum].target)
		hideAllBut(0)
	else
		popTimer = setTimeout('hideAllBut(0)', 500);
}
function getTree(menuNum, itemNum) {
	itemArray = new Array(menu.length);

	while(1) {
		itemArray[menuNum] = itemNum;
		if (menuNum == 0) return itemArray;
		itemNum = menu[menuNum][0].parentItem;
		menuNum = menu[menuNum][0].parentMenu;
	}
}

function changeCol(changeArray, isOver) {
	for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
		if (changeArray[menuCount]) {
			newCol = isOver ? menu[menuCount][0].overCol :
menu[menuCount][0].backCol;
			with (menu[menuCount][changeArray[menuCount]].ref) {
				if (isNS4) bgColor = newCol;
				else backgroundColor = newCol;
			}
		}
	}
}
function hideAllBut(menuNum) {
	var keepMenus = getTree(menuNum, 1);
	for (count = 0; count < menu.length; count++)
		if (!keepMenus[count])
			menu[count][0].ref.visibility = 'hidden';
	changeCol(litNow, false);
}


function Menu(isVert, popInd, x, y, width, overCol, backCol,
borderClass, textClass) {
	this.isVert = isVert;
	this.popInd = popInd
	this.x = x;
	this.y = y;
	this.width = width;
	this.overCol = overCol;
	this.backCol = backCol;
	this.borderClass = borderClass;
	this.textClass = textClass;
	this.parentMenu = null;
	this.parentItem = null;
	this.ref = null;
}

function Item(text, href, frame, length, spacing, target) {
	this.text = text;
	this.href = href;
	this.frame = frame;
	this.length = length;
	this.spacing = spacing;
	this.target = target;
	this.ref = null;
}

function writeMenus() {
	if (!isDOM && !isIE4 && !isNS4) return;

	for (currMenu = 0; currMenu < menu.length; currMenu++) with
(menu[currMenu][0]) {
	var str = '', itemX = 0, itemY = 0;

	for (currItem = 1; currItem < menu[currMenu].length; currItem++) with
(menu[currMenu][currItem]) {
	var itemID = 'menu' + currMenu + 'item' + currItem;

	var w = (isVert ? width : length);
	var h = (isVert ? length : width);

	if (isDOM || isIE4) {
	str += '<div id="' + itemID + '" style="position: absolute; left: ' +
itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + ';
visibility: inherit; ';
	if (backCol) str += 'background: ' + backCol + '; ';
	str += '" ';
	}
	if (isNS4) {
	str += '<layer id="' + itemID + '" left="' + itemX + '" top="' +
itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit"
';
	if (backCol) str += 'bgcolor="' + backCol + '" ';
	}
	if (borderClass) str += 'class="' + borderClass + '" ';

	str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')"
onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';


	str += '<table width="' + (w - 8) + '" border="0" cellspacing="0"
cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td
align="left" height="' + (h - 7) + '">' + '<a class="' + textClass +
'" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') +
text + '</a></td>';
	if (target > 0) {

	menu[target][0].parentMenu = currMenu;
	menu[target][0].parentItem = currItem;

	if (popInd) str += '<td class="' + textClass + '" align="right">' +
popInd + '</td>';
	}
	str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
	if (isVert) itemY += length + spacing;
	else itemX += length + spacing;
	}
	if (isDOM) {
	var newDiv = document.createElement('div');
	document.getElementsByTagName('body').item(0).appendChild(newDiv);
	newDiv.innerHTML = str;
	ref = newDiv.style;
	ref.position = 'absolute';
	ref.visibility = 'hidden';
	}

	if (isIE4) {
	document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' +
currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">'
+ str + '</div>');
	ref = getSty('menu' + currMenu + 'div');
	}

	if (isNS4) {
	ref = new Layer(0);
	ref.document.write(str);
	ref.document.close();
	}

	for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
	itemName = 'menu' + currMenu + 'item' + currItem;
	if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
	if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
	}
	}
	with(menu[0][0]) {
	ref.left = x;
	ref.top = y;
	ref.visibility = 'visible';
	}
}


function clickHandle(evt)
{
 if (isNS4) document.routeEvent(evt);
 hideAllBut(0);
}



function moveRoot()
{
 with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
}

-----End .js File-----
Subject: Re: Global Javascript Question
From: scottpes-ga on 15 Jul 2003 12:40 PDT
 
Stephen,

I copied from the beginning to the end of the .js file and converted
into a .js file.  I put the file into my web(I use MS FrontPage).  I
deleted all of the script that I had before and put the script
language tag where you said to.  I must still be missing something
because I can't get it to work.
Subject: Re: Global Javascript Question
From: stephenvakil-ga on 15 Jul 2003 14:34 PDT
 
I forgot the step for body onload.  Sorry!  I looked at the source for
your home page again and noticed it already has a body onload.  So you
probably don't need that extra BodyLoad function.  Try this .js
instead, and it should work... (I assume you currently get a script
error?)

If not, then I am mostly out of ideas.. you should in theory be able
to copy everything between your <script> and </script> tags into a
separate .js file and link to this (which is all I've done really,
plus moved the code around a slight bit).

--Begin .JS File--
var isDOM = (document.getElementById ? true : false);  
 var isIE4 = ((document.all && !isDOM) ? true : false); 
 var isNS4 = (document.layers ? true : false); 
 
 var popTimer = 0; 
 var litNow = new Array(); 
 
 var menu = new Array(); 
 
 var defOver = '#336699', defBack = '#003366'; 
 
 var defLength = 22; 
 
 menu[0] = new Array(); 
 menu[0][0] = new Menu(false, '', 5, 0, 17, '#669999', '#006666', '',
'itemText');
 menu[0] = new Array(); 
 menu[0][0] = new Menu(false, '', 10, 0, 17, '#669999', '#006666', '',
'itemText');
 menu[0][1] = new Item(' Home', 'index.html', '', 30, 56, 0); 
 menu[0][2] = new Item(' Manufacturers We Repair', '#', '', 150, 56,
2);
 menu[0][3] = new Item(' Other Services', '#', '', 88, 56, 3); 
 menu[0][4] = new Item(' Information', '#', '', 58, 56, 1); 
 menu[0][5] = new Item(' Downloads', 'literature.html', '', 50, 56,
0);
 menu[0][6] = new Item(' Helpful Formulas', 'formulas.html', '', 103,
56, 0);
 
 
 menu[1] = new Array(); 
 menu[1][0] = new Menu(true, '>', 0, 22, 110, defOver, defBack,
'itemBorder', 'itemText');
 menu[1][1] = new Item('About PES', 'aboutpes.html', '', defLength, 0,
0);
 menu[1][2] = new Item('Experience', 'experience.html', '', defLength,
0, 0);
 menu[1][3] = new Item('Policies/Warranty', 'policy.html', '',
defLength, 0, 0);
 menu[1][4] = new Item('FAQ', 'faqs.html', '', defLength, 0, 0); 
 menu[1][5] = new Item('Testimonials', 'testimonials.html', '',
defLength, 0, 0);
 menu[1][6] = new Item('Directions', 'map.html', '', defLength, 0, 0);
 menu[1][7] = new Item('Employment', 'employment.html', '', defLength,
0, 0);
 menu[1][8] = new Item('Contact Us', 'support.html', '', defLength, 0,
0);
 
 menu[2] = new Array(); 
 menu[2][0] = new Menu(true, '>', 0, 22, 200, defOver, defBack,
'itemBorder', 'itemText');
 menu[2][1] = new Item('Factory Authorized', '#', '', defLength, 0,
4);
 menu[2][2] = new Item('Brands We Frequently Repair', '#', '',
defLength, 0, 6);
 menu[2][3] = new Item('All Manufacturers', '#', '', defLength, 0, 5);
 
 menu[3] = new Array(); 
 menu[3][0] = new Menu(true, '<', 0, 22, 90, defOver, defBack,
'itemBorder', 'itemText');
 menu[3][1] = new Item('Field Service', 'service.html', '', defLength,
0, 0);
 menu[3][2] = new Item('Engineering', 'surplus.html', '', defLength,
0, 0);
 
 menu[4] = new Array(); 
 menu[4][0] = new Menu(true, '>', 200, 0, 70, '#333366', '#666699',
'itemBorder', 'itemText');
 menu[4][1] = new Item('ABB', 'abb.html', '', defLength, 0, 0); 
 menu[4][2] = new Item('Baldor', 'baldor.html', '', defLength, 0, 0);
 menu[4][3] = new Item('Danfoss', 'danfoss.html', '', defLength, 0,
0);
 menu[4][4] = new Item('Eurotherm', 'eurotherm.html', '', defLength,
0, 0);
 menu[4][5] = new Item('Fincor', 'fincor.html', '', defLength, 0, 0);
 menu[4][6] = new Item('Magnetek', 'magnetek.html', '', defLength, 0,
0);
 menu[4][7] = new Item('Saftronics', 'saftronics.html', '', defLength,
0, 0);
 menu[4][8] = new Item('Yaskawa', 'yaskawa.html', '', defLength, 0,
0);
 menu[4][9] = new Item('All', 'auth.html', '', defLength, 0, 0); 
 
 
 menu[5] = new Array(); 
 menu[5][0] = new Menu(true, '>', 200, 0, 45, '#333366', '#666699',
'itemBorder', 'itemText');
 menu[5][1] = new Item('A - D', 'repair.html', '', defLength, 0, 0); 
 menu[5][2] = new Item('E - I', 'repair2.html', '', defLength, 0, 0);
 menu[5][3] = new Item('J - N', 'repair3.html', '', defLength, 0, 0);
 menu[5][4] = new Item('O - S', 'repair4.html', '', defLength, 0, 0);
 menu[5][5] = new Item('T - Z', 'repair5.html', '', defLength, 0, 0);
 
 menu[6] = new Array(); 
 menu[6][0] = new Menu(true, '>', 200, 0, 100, '#333366', '#666699',
'itemBorder', 'itemText');
 menu[6][1] = new Item('Allen Bradley', 'allen_bradley.html', '',
defLength, 0, 0);
 menu[6][2] = new Item('Lenze', 'lenze.html', '', defLength, 0, 0); 
 menu[6][3] = new Item('Modicon', 'squared.html', '', defLength, 0,
0);
 menu[6][4] = new Item('Powertec', 'powertec.html', '', defLength, 0,
0);
 menu[6][5] = new Item('Reliance', 'reliance.html', '', defLength, 0,
0);
 menu[6][6] = new Item('Siemens', 'siemens.html', '', defLength, 0,
0);
 menu[6][7] = new Item('Square D', 'squared.html', '', defLength, 0,
0);
 menu[6][8] = new Item('Telemecanique', 'squared.html', '', defLength,
0, 0);
 menu[6][9] = new Item('Toshiba', 'toshiba.html', '', defLength, 0,
0);
 
 
 
 
 
 
 var popOldWidth = window.innerWidth; 
 nsResizeHandler = new Function('if (popOldWidth != window.innerWidth)
location.reload()');
 
 
 
 if (isNS4) document.captureEvents(Event.CLICK); 
 document.onclick = clickHandle; 
 
 
function getRef(id) { 
 if (isDOM) return document.getElementById(id); 
 if (isIE4) return document.all[id]; 
 if (isNS4) return document.layers[id]; 
} 
function getSty(id) { 
 return (isNS4 ? getRef(id) : getRef(id).style); 
}  
function popOver(menuNum, itemNum) { 
 clearTimeout(popTimer); 
 hideAllBut(menuNum); 
 litNow = getTree(menuNum, itemNum); 
 changeCol(litNow, true); 
 targetNum = menu[menuNum][itemNum].target; 
 if (targetNum > 0) { 
  thisX = parseInt(menu[menuNum][0].ref.left) +
parseInt(menu[menuNum][itemNum].ref.left);
  thisY = parseInt(menu[menuNum][0].ref.top) +
parseInt(menu[menuNum][itemNum].ref.top);
 with (menu[targetNum][0].ref) { 
  left = parseInt(thisX + menu[targetNum][0].x); 
  top = parseInt(thisY + menu[targetNum][0].y); 
  visibility = 'visible'; 
      } 
   } 
} 
function popOut(menuNum, itemNum) { 
 if ((menuNum == 0) && !menu[menuNum][itemNum].target) 
  hideAllBut(0) 
 else 
  popTimer = setTimeout('hideAllBut(0)', 500); 
} 
function getTree(menuNum, itemNum) { 
 itemArray = new Array(menu.length); 
 
 while(1) { 
  itemArray[menuNum] = itemNum; 
  if (menuNum == 0) return itemArray; 
  itemNum = menu[menuNum][0].parentItem; 
  menuNum = menu[menuNum][0].parentMenu; 
 } 
} 
 
function changeCol(changeArray, isOver) { 
 for (menuCount = 0; menuCount < changeArray.length; menuCount++) { 
  if (changeArray[menuCount]) { 
   newCol = isOver ? menu[menuCount][0].overCol :
menu[menuCount][0].backCol;
   with (menu[menuCount][changeArray[menuCount]].ref) { 
    if (isNS4) bgColor = newCol; 
    else backgroundColor = newCol; 
   } 
  } 
 } 
} 
function hideAllBut(menuNum) { 
 var keepMenus = getTree(menuNum, 1); 
 for (count = 0; count < menu.length; count++) 
  if (!keepMenus[count]) 
   menu[count][0].ref.visibility = 'hidden'; 
 changeCol(litNow, false); 
} 
 
 
function Menu(isVert, popInd, x, y, width, overCol, backCol,
borderClass, textClass) {
 this.isVert = isVert; 
 this.popInd = popInd 
 this.x = x; 
 this.y = y; 
 this.width = width; 
 this.overCol = overCol; 
 this.backCol = backCol; 
 this.borderClass = borderClass; 
 this.textClass = textClass; 
 this.parentMenu = null; 
 this.parentItem = null; 
 this.ref = null; 
} 
 
function Item(text, href, frame, length, spacing, target) { 
 this.text = text; 
 this.href = href; 
 this.frame = frame; 
 this.length = length; 
 this.spacing = spacing; 
 this.target = target; 
 this.ref = null; 
} 
 
function writeMenus() { 
 if (!isDOM && !isIE4 && !isNS4) return; 
 
 for (currMenu = 0; currMenu < menu.length; currMenu++) with
(menu[currMenu][0]) {
 var str = '', itemX = 0, itemY = 0; 
 
 for (currItem = 1; currItem < menu[currMenu].length; currItem++) with
(menu[currMenu][currItem]) {
 var itemID = 'menu' + currMenu + 'item' + currItem; 
 
 var w = (isVert ? width : length); 
 var h = (isVert ? length : width); 
 
 if (isDOM || isIE4) { 
 str += '<div id="' + itemID + '" style="position: absolute; left: ' +
itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + ';
visibility: inherit; ';
 if (backCol) str += 'background: ' + backCol + '; '; 
 str += '" '; 
 } 
 if (isNS4) { 
 str += '<layer id="' + itemID + '" left="' + itemX + '" top="' +
itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit"
';
 if (backCol) str += 'bgcolor="' + backCol + '" '; 
 } 
 if (borderClass) str += 'class="' + borderClass + '" '; 
 
 str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')"
onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';
 
 
 str += '<table width="' + (w - 8) + '" border="0" cellspacing="0"
cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td
align="left" height="' + (h - 7) + '">' + '<a class="' + textClass +
'" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') +
text + '</a></td>';
 if (target > 0) { 
 
 menu[target][0].parentMenu = currMenu; 
 menu[target][0].parentItem = currItem; 
 
 if (popInd) str += '<td class="' + textClass + '" align="right">' +
popInd + '</td>';
 } 
 str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>'); 
 if (isVert) itemY += length + spacing; 
 else itemX += length + spacing; 
 } 
 if (isDOM) { 
 var newDiv = document.createElement('div'); 
 document.getElementsByTagName('body').item(0).appendChild(newDiv); 
 newDiv.innerHTML = str; 
 ref = newDiv.style; 
 ref.position = 'absolute'; 
 ref.visibility = 'hidden'; 
 } 
 
 if (isIE4) { 
 document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' +
currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">'
+ str + '</div>');
 ref = getSty('menu' + currMenu + 'div'); 
 } 
 
 if (isNS4) { 
 ref = new Layer(0); 
 ref.document.write(str); 
 ref.document.close(); 
 } 
 
 for (currItem = 1; currItem < menu[currMenu].length; currItem++) { 
 itemName = 'menu' + currMenu + 'item' + currItem; 
 if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
 if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName]; 
 } 
 } 
 with(menu[0][0]) { 
 ref.left = x; 
 ref.top = y; 
 ref.visibility = 'visible'; 
 } 
} 
 
 
function clickHandle(evt) 
{ 
 if (isNS4) document.routeEvent(evt); 
 hideAllBut(0); 
} 
 
 
 
function moveRoot() 
{ 
 with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5); 
} 
 

--End .JS File--
Subject: Re: Global Javascript Question
From: stephenvakil-ga on 16 Jul 2003 07:07 PDT
 
Sorry, I'm making this too complicated.  Ignore everything I've
written and do this, which is simpler, and I've tested it:

1. Open your home page file.  There will be a <SCRIPT
LANGUAGE="javascript> tag, and then a couple of lines down is <!--
Begin.  Cut everything between the <!-- Begin and the // End --> (not
including them) and put it into a new text file, save it as menu.js,
and put this file in the same directory as your home page.

2. Now you should have something like:

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
//  End -->

</script>

Delete all of this and replace it with:

<SCRIPT language=JavaScript src="menu.js"></SCRIPT>

Save it and see if it works...
Subject: Re: Global Javascript Question
From: scottpes-ga on 16 Jul 2003 08:25 PDT
 
YES!!!!!   It worked.  You, stephenvakil, are "THE MAN".  Thank You!!!!!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy