Teen Programmers Unite  
 

 

Return to forum top

JavaScript Help

Posted by akubabe [send private reply] at May 14, 2002, 08:44:02 PM

can someone help me interpret this script i picked up on the internet somewhere?

<SCRIPT language=JavaScript>
<!-- // Hide from old browsers

// Maryanna Nesina
// mar@mail.bio.pu.ru
// http://www.bio.pu.ru/~mar
// http://www.webprogramming.boom.ru
// This script allows to show and hide layes for a set of main brousers
// And can be used to construct pull-down menus

// All the Layers get names from menu0 to menu_vith_nomber_m
// If we want to hide all the layers
// we call showmenu() function without parametrs
// i.e. using onMouseOver evant

function DOMGetElement(xx)
{
// This function returns document's elemtnt acording it's name
// Using Document Object Model
if (document.getElementById) return document.getElementById(xx);
return nul;
}

function showmenu(name)
{
// This is the main function that hide all the layers but the only one,
// which name was delivered to the function as a parametr

var ii; // cicle variable
var m=2; // variable that shows maximum nomber in layers' names
var qq; // here we store the name of a layer that we must show
var nen; // here we store the names of all layers (in a cicle)

NeMenu = new Array(m+1); // an array to store the objects - all the layers that should be hidden
nename = new Array(m+1); // an array to store the names of all the layers that should be hidden

// cicle to store the names of all the layers that should be hidden an array
for (ii=0; ii<=m; ii++) {
nen="menu" + ii;
nename[ii]=nen;
if (name) { // this
if (nen==name) qq=ii; // flag on - if it's a name of a layer hat should be shown
}
}

// than we should show one layer and hide all the others (in a cicle)
// we do it for all the main types of brousers

if (document.getElementById) {
// Type 1: IE5,6; NN6; Mozilla
// if our brouser supports DOM and we can get an object according to it's name
if (name) { // if there was a parametr
var Menu = DOMGetElement(name); // get an object
Menu.style.visibility='visible'; // and show it, changing the style
}
for (ii=0; ii<=m; ii++) { // for all the layers
if (ii!=qq) { // but one that should be shown
NeMenu[ii] = DOMGetElement(nename[ii]); // get an object that we do NOT show
NeMenu[ii].style.visibility='hidden'; // and hide it, changing the style
}
}
return true; // exit function
} // that's all for the first type of brousers

if(document.all) {
// Type 2: For document.all stands IE4-6 and Opera5, but IE5,6 were gone as the 1-st type
if (name) document.all[name].style.visibility= 'visible'; //if there was a parametr, show that layer using style
for (ii=0; ii<=m; ii++) {
// hide all the layers but one that should be shown - using style
if (ii!=qq) document.all[nename[ii]].style.visibility= 'hidden';
}
return true; // exit function
} // that's all for the second type of brousers

if (document.layers) {
//Type 2: NN4
if (name) document.layers[name].visibility='show'; // if there was a parametr, show that layer using layer
for (ii=0; ii<=m; ii++) {
// hide all the layers but one that should be shown - using layer
if (ii!=qq) document.layers[nename[ii]].visibility='hide';
}
return true; // exit function
} // that's all for the second type of brousers (NN4)
}
//-->
</script>







<a href onMouseOver="showmenu('menu0')" onMouseOut="showmenu()">Link #1</a><br />
<div id="menu0" style="position:absolute; left:490px; top:35px; width:211px; height:95px; z-index:1; background-color: #006633; layer-background-color: #006633; border: 1px none #000000; visibility: hidden">
<p>That is the first layer</p>
<p>It is green</p>
</div>
<a href onMouseOver="showmenu('menu1')" onMouseOut="showmenu()">Link #2</a><br />
<div id="menu1" style="position:absolute; left:57px; top:75px; width:204px; height:94px; z-index:2; background-color: #3300FF; layer-background-color: #3300FF; border: 1px none #000000; visibility: hidden">
<p>That is the second layer</p>
<p>It is blue</p>
</div>
<a href onMouseOver="showmenu('menu2')" onMouseOut="showmenu()">Link #3</a><br />
<div id="menu2" style="position:absolute; left:157px; top:125px; width:204px; height:94px; z-index:3; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000; visibility: hidden">
<p>That is the third layer</p>
<p>Can your see it?</p>
</div>

Posted by vikram_1982 [send private reply] at May 15, 2002, 12:07:33 AM

omg,

Did u try reading the comments? I didnt go thru the whole program but the comments seem to be self describing....

Posted by buzgub [send private reply] at May 15, 2002, 01:11:23 AM

Yet another person who fails to ask a coherent question. What did you want to know? What about it do you want interpreted?

Posted by taubz [send private reply] at May 15, 2002, 10:17:39 AM

Yes, we can help you. :)

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.