|
Greetings.
I'm reading this book that is teaching me the more appropriate way of assigning functions. It has an 'accordian' example that when you click on a link, it expands into other options and when you click it again it 'collapses'.
I understand the most of it, but there is just one part I don't understand.
Here's the code.
Assuming this small HTML/CSS file (code cut short/suppose to collapse links by moving to the left):
ul.accordion li.collapsed * {
position:absolute;
left: -10000px;
}
ul.accordion li.collapsed h2, ul.accordion li.expanded h2,
ul.accordion li.collapsed h2 a:link,
ul.accordion li.collapsed h2 a:visited,
ul.accordion li.expanded h2 a:link,
ul.accordion li.expanded h2 a:visited {
position:static;
}
JavaScript Code:
var Accordion =
{
init: function()
{
var accordions = Core.getElementsByClass("accordion");
for (var i = 0; i < accordions.length; i++)
{
var folds = accordions[i].childNodes;
for (var j = 0; j < folds.length; j++)
{
if (folds[j].nodeType == 1)
{
Accordion.collapse(folds[j]);
var foldsLinks = folds[j].getElementsByTagName("a");
var foldTitleLink = foldLinks[0];
Core.addEventListener(
foldTitleLink, "click", Accordion.clickListener);
for (var k = 1; k < foldLinks.length; k++)
{
Core.addEventListener(
foldLinks[k], "focus", Accordion.focusListener);
}
}
}
if (location.hash.length > 1)
{
var activeFold = document.getElementById(
location.hash.substring(1));
if (activeFold && activeFold.parentNode == accordions[i])
{
Accordion.expand(activeFold);
}
}
}
},
collapse: function(fold)
{
Core.removeClass(fold, "expanded");
Core.addClass(fold, "collapsed");
},
collapseAll: function(accordion)
{
var folds = accordion.childNodes;
for (var i = 0; i < folds.length; i++)
{
if (folds[i].nodeType == 1)
{
Accordion.collapse(folds[i]);
}
}
},
expand: function(fold)
{
Accordion.collapseAll (fold.parentNode);
Core.removeClass(fold, "collapsed");
Core.addClass (fold, "expanded);
},
clickListener: function(event)
{
var fold = this.parentNode.parentNode;
if (Core.hasClass(fold, "collapsed"))
{
Accordion.expand(fold);
}
else
{
Accordion.collapse(fold)
}
Core.preventDefault(event)
},
focusListener: function(event)
{
var element = this;
while (element.parentNode)
{
if (element.parentNode.className == "accordion")
{
Accordion.expand(element);
return;
}
element = element.parentNode;
}
}
};
Core.start(Accordion);
The part that I don't understand is highlighted in blue. It's supposed to be a script insert for browsers that don't have a mouse. So if they tab to every link, it's still going to tab through the collapsed links that are pushed off to the left. So the book create this code in blue so that it does something when the user tabs through the collapsed links. I really would need more of a visual picture of how this works than anything, because the code I can follow.
Please help. Thanks.
|