// Fully accessible collapsible outlines. JavaScript code // copyright 2007, Boutell.Com, Inc. // // See http://www.boutell.com/newfaq/ for more information. // // Permission granted to use, republish, sell and otherwise // benefit from this code as you see fit, provided you keep // this notice intact. You may remove comments below this line. // // END OF NOTICE // // INSTRUCTIONS: this WON'T WORK unless you do the following in the // document that includes it: // // 1. In the
element of your page, bring in this code: // // // // 2. Call outlineInit() from your onLoad handler: // // // // If you need other code in onLoad, that's fine. Just separate the // calls with semicolons ( ; ). // // 3. To create your outline, write a nested list with the //
";
item.insertBefore(span, kids[0]);
item.onclick = outlineItemClick;
}
}
function outlineGetTarget(evt)
{
var target;
if (!evt) {
// Old IE
evt = window.event;
}
// Prevent double event firing (sigh)
evt.cancelBubble = true;
if (evt.stopPropagation) {
evt.stopPropagation();
}
var target = evt.target;
if (!target) {
// Old IE
target = evt.srcElement;
}
return target;
}
function outlineItemClickByOffset(id)
{
outlineItemClickBody(outlineItems[id]);
}
function outlineItemClick(evt)
{
target = outlineGetTarget(evt);
outlineItemClickBody(target);
}
function outlineItemClickBody(target)
{
var closed = true;
var kids = target.childNodes;
var hasKids = false;
for (var i = 0; (i < kids.length); i++) {
var kid = kids[i];
if (kid.nodeName == "UL") {
if (kid.style.display == "none") {
kid.style.display = "block";
} else {
kid.style.display = "none";
closed = false;
}
hasKids = true;
}
}
if (!hasKids) {
// We're here because of a click on a
// childless node. Ignore that.
return;
}
var img = outlineGetImg(target);
if (closed) {
// We've just opened it, show close button
img.src = "images/oclose1.jpg";
img.alt = "Click to close";
} else {
img.src = "images/oopen1.jpg";
img.alt = "Click to open";
}
}
function outlineGetImg(target)
{
return outlineGetDescendantWithClassName(target, "oimg");
}
function outlineGetDescendantWithClassName(parent, cn)
{
// Regular expression: beginning with class name, or
// class name preceded by a space; and ending with class name, or
// class name followed by a space. Covers the ways a single class
// name can appear with or without others in the className attribute.
var elements = parent.childNodes;
var length = elements.length;
var i;
var regexp = new RegExp("(^| )" + cn + "( |$)");
for (i = 0; (i < length); i++) {
if (regexp.test(elements[i].className)) {
return elements[i];
}
var result = outlineGetDescendantWithClassName(
elements[i], cn);
if (result) {
return result;
}
}
return null;
}
function outlineGetTopLevelLists()
{
// Regular expression: beginning with class name, or
// class name preceded by a space; and ending with class name, or
// class name followed by a space. Covers the ways a single class
// name can appear with or without others in the className attribute.
var cn = "outline";
var elements = document.getElementsByTagName("ul");
var length = elements.length;
var i;
var regexp = new RegExp("(^| )" + cn + "( |$)");
var results = new Array();
for (i = 0; (i < length); i++) {
if (regexp.test(elements[i].className)) {
results.push(elements[i]);
}
}
return results;
}