78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
// xMenu5, Copyright 2004,2005 Michael Foster (Cross-Browser.com)
|
|
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
|
|
|
|
function xMenu5(idUL, btnClass, idAutoOpen) // object prototype
|
|
{
|
|
// Constructor
|
|
|
|
var i, ul, btns, mnu = xGetElementById(idUL);
|
|
btns = xGetElementsByClassName(btnClass, mnu, 'DIV');
|
|
for (i = 0; i < btns.length; ++i) {
|
|
ul = xNextSib(btns[i], 'UL');
|
|
btns[i].xClpsTgt = ul;
|
|
btns[i].onclick = btn_onClick;
|
|
set_display(btns[i], 0);
|
|
}
|
|
if (idAutoOpen) {
|
|
var e = xGetElementById(idAutoOpen);
|
|
while (e && e != mnu) {
|
|
if (e.xClpsTgt) set_display(e, 1);
|
|
while (e && e != mnu && e.nodeName != 'LI') e = e.parentNode;
|
|
e = e.parentNode; // UL
|
|
while (e && !e.xClpsTgt) e = xPrevSib(e);
|
|
}
|
|
}
|
|
|
|
// Private
|
|
|
|
function btn_onClick()
|
|
{
|
|
var thisLi, fc, pUl;
|
|
if (this.xClpsTgt.style.display == 'none') {
|
|
set_display(this, 1);
|
|
// get this label's parent LI
|
|
var li = this.parentNode;
|
|
thisLi = li;
|
|
pUl = li.parentNode; // get this LI's parent UL
|
|
li = xFirstChild(pUl); // get the UL's first LI child
|
|
// close all labels' ULs on this level except for thisLI's label
|
|
while (li) {
|
|
if (li != thisLi) {
|
|
fc = xFirstChild(li);
|
|
if (fc && fc.xClpsTgt) {
|
|
set_display(fc, 0);
|
|
}
|
|
}
|
|
li = xNextSib(li);
|
|
}
|
|
}
|
|
else {
|
|
set_display(this, 0);
|
|
}
|
|
}
|
|
|
|
function set_display(ele, bBlock)
|
|
{
|
|
if (bBlock) {
|
|
ele.xClpsTgt.style.display = 'block';
|
|
ele.innerHTML = '-';
|
|
}
|
|
else {
|
|
ele.xClpsTgt.style.display = 'none';
|
|
ele.innerHTML = '+';
|
|
}
|
|
}
|
|
|
|
// Public
|
|
|
|
this.onUnload = function()
|
|
{
|
|
for (i = 0; i < btns.length; ++i) {
|
|
btns[i].xClpsTgt = null;
|
|
btns[i].onclick = null;
|
|
}
|
|
}
|
|
} // end xMenu5 prototype
|
|
|
|
|