Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Modifying a navigation javascript

Modifying a navigation javascript

alvifarooq
11-24-2005, 06:11 AM
hi guys...

i have this finder javascript...currently it allows navigation through an unordered list...when a link is clicked it will show the entire path starting from the root link...

the way i want it work is that it should show only the child list on clicking and hide everything else...plz see if anyone can help me...this seems fairly easy but i'm not really good at javascript...

this is the relevant piece of javascript that i need to edit...


// loop through all links of inside finder
lis=document.getElementById('finder').getElementsByTagName('li');
for(i=0;i<lis.length;i++)
{
// if the li containing the link has no nested list, skip this one
if(!lis[i].getElementsByTagName('ul')[0])
{

continue;
}
var newa=document.createElement('a');
newa.href='#';
newa.appendChild(document.createTextNode(lis[i].firstChild.nodeValue));
lis[i].replaceChild(newa,lis[i].firstChild);
// otherwise apply the parent class
cssjs('add',newa,parentClass);

// if the user clicks on the link
lis[i].getElementsByTagName('a')[0].onclick=function()
{
// loop through all lists inside finder
for(var i=0;i<uls.length;i++)
{
// avoid the list connected to this link
var found=false;
for(j=0;j<uls[i].getElementsByTagName('ul').length;j++)
{
if(uls[i].getElementsByTagName('ul')[j] ==
this.parentNode.getElementsByTagName('ul')[0])
{
found=true;
break;
}
}
// and hide all others
if(!found)
{
cssjs('add',uls[i],hideClass)
cssjs('remove',uls[i],showClass)
cssjs('remove',uls[i].parentNode.getElementsByTagName('a')[0],openClass)
cssjs('add',uls[i].parentNode.getElementsByTagName('a')[0],parentClass)
}
}
// change the current link from parent to open
cssjs('swap',this,parentClass,openClass)
// show the current nested list
cssjs('add',this.parentNode.getElementsByTagName('ul')[0],showClass)

// don't follow the real HREF of the link
return false;
}
}




ive embedded the entire script in the webpage below...

thanks!



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">

body
{
margin:0;
padding:0;
font-family:arial,sans-serif;
}
.domenabled #finderparent
{
border:1px solid #000;
position:relative;
height:150px;
}
.domenabled #finder
{
position:absolute;
top:1em;
left:1em;
}
.domenabled ul#finder,
.domenabled ul#finder li,
.domenabled ul#finder ul
{
width:200px;
list-style-type:none;
margin:0;
padding:0;
}
.domenabled ul#finder ul.hidden
{
top:0px;
left:-2000px;
position:absolute;
}
.domenabled ul#finder ul.shown
{
top:0px;
left:200px;
position:absolute;
}
.domenabled #finder a.open
{
background:url(arrowon.gif) no-repeat 90% 50% #eee;
padding-right:16px;
padding-left:0px;
display:block;
}
.domenabled #finder a.parent
{
background:url(arrow.gif) no-repeat #fff 100% 50%;
padding-right:16px;
padding-left:0px;
}
.domenabled ul#finder li a
{
color:#000;
background:url(normal.gif) no-repeat #fff 0 50% ;
padding-left:16px;
text-decoration:none;
}


</style>


<script type="text/javascript">

/*
* ul2finder
* written by Christian Heilmann (http://icant.co.uk)
* turns the nested list with the ID "finder" into a dynamic list
* uses the CSS classes defined in the variables
*/
function ul2finder()
{
// Define variables used and classes to be applied/removed
var i,uls,als,finder;
var parentClass='parent';
var showClass='shown';
var hideClass='hidden';
var openClass='open';

// check if our finder list exists, if not, stop all activities
finder=document.getElementById('finder');
if(!finder){return;}

// add the class domenabled to the body
cssjs('add',document.body,'domenabled')

// loop through all lists inside finder, position and hide them
// by applying the class hidden
uls=document.getElementById('finder').getElementsByTagName('ul');
for(i=0;i<uls.length;i++)
{
cssjs('add',uls[i],hideClass);
}

// loop through all links of inside finder
lis=document.getElementById('finder').getElementsByTagName('li');
for(i=0;i<lis.length;i++)
{
// if the li containing the link has no nested list, skip this one
if(!lis[i].getElementsByTagName('ul')[0])
{

continue;
}
var newa=document.createElement('a');
newa.href='#';
newa.appendChild(document.createTextNode(lis[i].firstChild.nodeValue));
lis[i].replaceChild(newa,lis[i].firstChild);
// otherwise apply the parent class
cssjs('add',newa,parentClass);

// if the user clicks on the link
lis[i].getElementsByTagName('a')[0].onclick=function()
{
// loop through all lists inside finder
for(var i=0;i<uls.length;i++)
{
// avoid the list connected to this link
var found=false;
for(j=0;j<uls[i].getElementsByTagName('ul').length;j++)
{
if(uls[i].getElementsByTagName('ul')[j] ==
this.parentNode.getElementsByTagName('ul')[0])
{
found=true;
break;
}
}
// and hide all others
if(!found)
{
cssjs('add',uls[i],hideClass)
cssjs('remove',uls[i],showClass)
cssjs('remove',uls[i].parentNode.getElementsByTagName('a')[0],openClass)
cssjs('add',uls[i].parentNode.getElementsByTagName('a')[0],parentClass)
}
}
// change the current link from parent to open
cssjs('swap',this,parentClass,openClass)
// show the current nested list
cssjs('add',this.parentNode.getElementsByTagName('ul')[0],showClass)

// don't follow the real HREF of the link
return false;
}
}
/*
* cssjs
* written by Christian Heilmann (http://icant.co.uk)
* eases the dynamic application of CSS classes via DOM
* parameters: action a, object o and class names c1 and c2 (c2 optional)
* actions: swap exchanges c1 and c2 in object o
* add adds class c1 to object o
* remove removes class c1 from object o
* check tests if class c1 is applied to object o
* example: cssjs('swap',document.getElementById('foo'),'bar','baz');
*/
function cssjs(a,o,c1,c2)
{
switch (a){
case 'swap':
o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
break;
case 'add':
if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
break;
case 'remove':
var rep=o.className.match(' '+c1)?' '+c1:c1;
o.className=o.className.replace(rep,'');
break;
case 'check':
return new RegExp('\\b'+c1+'\\b').test(o.className)
break;
}
}
}

// Check if the browser supports DOM, and start the script if it does.
if(document.getElementById && document.createTextNode)
{
window.onload=ul2finder;
}


</script>

</head>
<body>
<div id="finderparent">
<ul id="finder">
<li>Main Courses
<ul>
<li>Burger Meals
<ul>
<li>Beef
<ul>
<li><a>Quarter Pounder</a></li>
<li><a>Half Pounder</a></li>
</ul>
</li>
<li>Chicken
<ul>
<li><a>Chargrilled Chicken</a></li>
<li><a>Chicken Burger</a></li>
</ul>
</li>
<li>Fish
<ul>
<li><a>Fish Burger</a></li>
<li><a>Fisherman's Delight</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>

alvifarooq
11-24-2005, 11:26 AM
here's the line that needs changing:


cssjs('add',this.parentNode.getElementsByTagName('ul')[0],showClass)


it shows the entire nested list...i don't want that...i just want it to show the child of the link that's been clicked and hide everything else...

thanks...


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Shake screen script
external javascript question...
Back and next Button below a fading Image
Navigation to a page after a date has passed
Please help me converting into variable names, or help me out any way you can...
Compare one value againt a set?
convert text to integer

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics