lu__22
09-03-2010, 08:36 PM
I don't really know JS, I can find my way around code but can't add any new functionality.
I downloaded the JS code below wich basically handles events for a list-based (li, ul) accordeon menu. But it doesn't let you open a submenu automatically if the url is the same as the location, and I don't know how to add that :(
I tried quite a few other menus, some with this functionality I need (I couldn't "insert" it into this code, I just don't know enough JS for that), but none quite fit the design requirements (or in other cases links just simply did not "link" when clicked!). So I'm not looking for other menus I could download from the web, just the modifications I need to add to this code.
I you want it, I have the code for another menu that does this breadcrumb thing (though it's the one where links don't work and it just doesn't look right either). The website is already designed so I can't change requirements :(
Thank you for any help you can provide!
// This portion allows for insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// functionality in Netscape / Mozilla /Opera
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}
//---end insertAdjacent code---------
// :::: Global Variables :::
var firstLoad=0
var GlobalECState=0
// :::: Global Functions :::
window.onload=InitializePage;
function InitializePage()
{defineLayout(); createTopMenu(); prepareListStyles(); setLEVELs(); Icons(); attachEventhandlers();
}
function defineLayout()
{
// Set Page position
document.getElementById("MDME").style.position="relative";
document.getElementById('MDME').style.left= PagePositionLEFT+"px";
document.getElementById('MDME').style.top= PagePositionTOP+"px";
document.getElementById('MDME').style.zIndex=50;
}
function setLEVELs()
{
ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
ULCollection.item(0).setAttribute("level", 1);
// Initally set all LI to level 1
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
for (a=0; a<LICollection.length;a++)
{LICollection.item(a).setAttribute("level", 1);}
// Set all non-level 1 LI to respective levels
if (ULCollection!=null)
{
for (u=0; u<ULCollection.length; u++)
{
var ULChildrenCollection=ULCollection.item(u).getElementsByTagName("UL");
for (l=0; l<ULChildrenCollection.length; l++)
{
var previousLevel=parseInt(ULCollection.item(u).getAttribute("level"));
ULChildrenCollection.item(l).setAttribute("level", previousLevel+1);
var LIChildrenCollection=ULChildrenCollection.item(l).getElementsByTagName("LI");
for (m=0; m<LIChildrenCollection.length; m++)
{LIChildrenCollection.item(m).setAttribute("level", previousLevel+1);}
}
}
}
}
function createTopMenu()
{
if(showECOption=='yes' && oneBranch!='yes')
{
var str='';
str+='<TABLE border="0" cellpadding="2" cellspacing="0" class="topMenu">';
str+='<TR>';
str+='<TD id="expandAllMenuItem" onClick="ECALL(1)">';
if(imageEXPANDALL=="")
{str+='Expand ALL<\/TD>'; }
else
{str+='<IMG border="0" src="MDMEImages\/'+imageEXPANDALL+'" alt="Expand ALL"><\/TD>';}
str+='<TD id="collapseAllMenuItem" onClick="ECALL(0)">';
if(imageCOLLAPSEALL=="")
{str+='Collapse ALL<\/TD>';}
else
{str+='<IMG border="0" src="MDMEImages\/'+imageCOLLAPSEALL+'" alt="Collapse ALL"><\/TD>';}
str+='<\/TR>';
str+='<\/TABLE>';
document.getElementById("MDME").insertAdjacentHTML("afterBegin", str);
if(GlobalECState==0)
{document.getElementById("expandAllMenuItem").style.display='inline';
document.getElementById("collapseAllMenuItem").style.display='none';}
else
{document.getElementById("expandAllMenuItem").style.display='none';
document.getElementById("collapseAllMenuItem").style.display='inline'}
}
}
function prepareListStyles()
{
ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
if (ULCollection!=null)
{for (u=0; u<ULCollection.length; u++)
{ULCollection.item(u).style.listStyleType="none";
ULCollection.item(u).setAttribute("id", "ULID"+u);}}
}
function attachEventhandlers()
{
// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;}
}
// Set Transparency level
if(navigator.appName == 'Microsoft Internet Explorer')
{
document.getElementById('MDME').style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+TValue+")"
}
else
{
document.getElementById('MDME').style.MozOpacity=1;
TValue=parseFloat(TValue/100-.001); // .001 is fix for moz opacity/image bug
document.getElementById('MDME').style.MozOpacity=TValue;}
}
function ECALL(o) // Expand or Collapse "ALL" routine
{
//strip all images
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{
for (d=0; d<LICollection; d++)
{LICollection.item(i).style.listStyleImage="none";}}
firstLoad=0; GlobalECState=o; Icons();
if(showECOption=='yes' && oneBranch!='yes')
{
if(GlobalECState==0)
{document.getElementById("expandAllMenuItem").style.display='inline';
document.getElementById("collapseAllMenuItem").style.display='none';}
else
{document.getElementById("expandAllMenuItem").style.display='none';
document.getElementById("collapseAllMenuItem").style.display='inline'}
}
}
(rest of code in next post because of character number limit)
I downloaded the JS code below wich basically handles events for a list-based (li, ul) accordeon menu. But it doesn't let you open a submenu automatically if the url is the same as the location, and I don't know how to add that :(
I tried quite a few other menus, some with this functionality I need (I couldn't "insert" it into this code, I just don't know enough JS for that), but none quite fit the design requirements (or in other cases links just simply did not "link" when clicked!). So I'm not looking for other menus I could download from the web, just the modifications I need to add to this code.
I you want it, I have the code for another menu that does this breadcrumb thing (though it's the one where links don't work and it just doesn't look right either). The website is already designed so I can't change requirements :(
Thank you for any help you can provide!
// This portion allows for insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// functionality in Netscape / Mozilla /Opera
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}
//---end insertAdjacent code---------
// :::: Global Variables :::
var firstLoad=0
var GlobalECState=0
// :::: Global Functions :::
window.onload=InitializePage;
function InitializePage()
{defineLayout(); createTopMenu(); prepareListStyles(); setLEVELs(); Icons(); attachEventhandlers();
}
function defineLayout()
{
// Set Page position
document.getElementById("MDME").style.position="relative";
document.getElementById('MDME').style.left= PagePositionLEFT+"px";
document.getElementById('MDME').style.top= PagePositionTOP+"px";
document.getElementById('MDME').style.zIndex=50;
}
function setLEVELs()
{
ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
ULCollection.item(0).setAttribute("level", 1);
// Initally set all LI to level 1
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
for (a=0; a<LICollection.length;a++)
{LICollection.item(a).setAttribute("level", 1);}
// Set all non-level 1 LI to respective levels
if (ULCollection!=null)
{
for (u=0; u<ULCollection.length; u++)
{
var ULChildrenCollection=ULCollection.item(u).getElementsByTagName("UL");
for (l=0; l<ULChildrenCollection.length; l++)
{
var previousLevel=parseInt(ULCollection.item(u).getAttribute("level"));
ULChildrenCollection.item(l).setAttribute("level", previousLevel+1);
var LIChildrenCollection=ULChildrenCollection.item(l).getElementsByTagName("LI");
for (m=0; m<LIChildrenCollection.length; m++)
{LIChildrenCollection.item(m).setAttribute("level", previousLevel+1);}
}
}
}
}
function createTopMenu()
{
if(showECOption=='yes' && oneBranch!='yes')
{
var str='';
str+='<TABLE border="0" cellpadding="2" cellspacing="0" class="topMenu">';
str+='<TR>';
str+='<TD id="expandAllMenuItem" onClick="ECALL(1)">';
if(imageEXPANDALL=="")
{str+='Expand ALL<\/TD>'; }
else
{str+='<IMG border="0" src="MDMEImages\/'+imageEXPANDALL+'" alt="Expand ALL"><\/TD>';}
str+='<TD id="collapseAllMenuItem" onClick="ECALL(0)">';
if(imageCOLLAPSEALL=="")
{str+='Collapse ALL<\/TD>';}
else
{str+='<IMG border="0" src="MDMEImages\/'+imageCOLLAPSEALL+'" alt="Collapse ALL"><\/TD>';}
str+='<\/TR>';
str+='<\/TABLE>';
document.getElementById("MDME").insertAdjacentHTML("afterBegin", str);
if(GlobalECState==0)
{document.getElementById("expandAllMenuItem").style.display='inline';
document.getElementById("collapseAllMenuItem").style.display='none';}
else
{document.getElementById("expandAllMenuItem").style.display='none';
document.getElementById("collapseAllMenuItem").style.display='inline'}
}
}
function prepareListStyles()
{
ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
if (ULCollection!=null)
{for (u=0; u<ULCollection.length; u++)
{ULCollection.item(u).style.listStyleType="none";
ULCollection.item(u).setAttribute("id", "ULID"+u);}}
}
function attachEventhandlers()
{
// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;}
}
// Set Transparency level
if(navigator.appName == 'Microsoft Internet Explorer')
{
document.getElementById('MDME').style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+TValue+")"
}
else
{
document.getElementById('MDME').style.MozOpacity=1;
TValue=parseFloat(TValue/100-.001); // .001 is fix for moz opacity/image bug
document.getElementById('MDME').style.MozOpacity=TValue;}
}
function ECALL(o) // Expand or Collapse "ALL" routine
{
//strip all images
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{
for (d=0; d<LICollection; d++)
{LICollection.item(i).style.listStyleImage="none";}}
firstLoad=0; GlobalECState=o; Icons();
if(showECOption=='yes' && oneBranch!='yes')
{
if(GlobalECState==0)
{document.getElementById("expandAllMenuItem").style.display='inline';
document.getElementById("collapseAllMenuItem").style.display='none';}
else
{document.getElementById("expandAllMenuItem").style.display='none';
document.getElementById("collapseAllMenuItem").style.display='inline'}
}
}
(rest of code in next post because of character number limit)