J
Jeff Gutsell
I've created a site where the pages generally contain a table of
contents (site map) down the left side. When each page loads, the
first function is called. The second function populates a global var
(array) of all the links.
I try to avoid using global variables, but I am stumped how to
eliminate this one (TocLinks) because other functions need to iterate
through it. I think the answer is to create a custom object that the
other functions can access. But I need some pointers on how to
proceed.
Here's the function that the pages call initially and the 2nd function
that it calls:
function SetCurrPgLink()
{
var parElem;
var parElemUL;
var findUL;
GetPageLinks();
for (var i = 0; i < TocLinks.length; i++)
{
var x = TocLinks.href;
if (x.indexOf(CurrentPage) > -1)
{
CurrentPgIndex = i;
TocLinks.id = 'CurrentPgA';
parElem = TocLinks.parentNode;
parElem.style.backgroundColor = 'white';
findUL = parElem.parentNode.tagName.toLowerCase();
if (findUL == 'ul')
{
parElemUL = parElem.parentNode;
parElemUL.style.display = 'block';
}
parElemUL.parentNode.className = 'FolderOpenLI';
break;
}
}
}
/* fine-tune list of anchors */
function GetPageLinks()
{
var CountPgItems = 0;
var TocDivNode = document.getElementById('TocDiv');
var TocLinksAll = TocDivNode.getElementsByTagName('a');
for (var n = 0; n < TocLinksAll.length; n++)
{
if (TocLinksAll[n].parentNode.className == 'PageItem')
{
TocLinks[CountPgItems] = TocLinksAll[n];
CountPgItems++;
}
}
}
contents (site map) down the left side. When each page loads, the
first function is called. The second function populates a global var
(array) of all the links.
I try to avoid using global variables, but I am stumped how to
eliminate this one (TocLinks) because other functions need to iterate
through it. I think the answer is to create a custom object that the
other functions can access. But I need some pointers on how to
proceed.
Here's the function that the pages call initially and the 2nd function
that it calls:
function SetCurrPgLink()
{
var parElem;
var parElemUL;
var findUL;
GetPageLinks();
for (var i = 0; i < TocLinks.length; i++)
{
var x = TocLinks.href;
if (x.indexOf(CurrentPage) > -1)
{
CurrentPgIndex = i;
TocLinks.id = 'CurrentPgA';
parElem = TocLinks.parentNode;
parElem.style.backgroundColor = 'white';
findUL = parElem.parentNode.tagName.toLowerCase();
if (findUL == 'ul')
{
parElemUL = parElem.parentNode;
parElemUL.style.display = 'block';
}
parElemUL.parentNode.className = 'FolderOpenLI';
break;
}
}
}
/* fine-tune list of anchors */
function GetPageLinks()
{
var CountPgItems = 0;
var TocDivNode = document.getElementById('TocDiv');
var TocLinksAll = TocDivNode.getElementsByTagName('a');
for (var n = 0; n < TocLinksAll.length; n++)
{
if (TocLinksAll[n].parentNode.className == 'PageItem')
{
TocLinks[CountPgItems] = TocLinksAll[n];
CountPgItems++;
}
}
}