Announcement

Collapse
No announcement yet.

Calling all javaScript gurus!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calling all javaScript gurus!

    Hi there

    I've amended the subsection code from the AUG to display the current section links you can view this as work in progress at www.lapreya.com

    I now want to only display the current parent section for example if you are in Makeup/Lips I only want to display the link to the current parent section ie Lips and not display the other parent sections which in this case would be eyes, face, nails, body, gifts.

    I know its just a case of adding another if or else statment but the logic is doing my head in!

    Any help would be greatly appreciated.




    Code:
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function SubSectionList(ar)
    {
    var SectionName = 'CUSTOMVAR:SECTIONNAME';
    var SubSectionName = 'CUSTOMVAR:SUBSECTIONNAME';
    {
    var strIDs = ' ';
    for (var i=1;i<=ar.length;i++)
    {
    if (ar[i].sURL !=null && ar[i].sName == SectionName)
    {
    strIDs += ' ';
    {
    if (ar[i].pChild)
    {
    for (var j=1;j<=ar[i].pChild.length;j++)
    {
    strIDs += '<a href="' + ar[i].pChild[j].sURL + '"><p><span class="actxxsmall">' + ar[i].pChild[j].sName + '</span></a></p>';
    {
    if (ar[i].pChild[j].sName == SubSectionName)
    {
    for (var k=1;k<=ar[i].pChild[j].pChild.length;k++)
    {
    strIDs += '&nbsp;&nbsp;<a href="' + ar[i].pChild[j].pChild[k].sURL + '"><span class="actxxsmall">' + ar[i].pChild[j].pChild[k].sName + '</span></a><br>';
    }
    }
    }
    }
    }
    }
    }
    }
    strIDs += ' '
    return strIDs
    }
    }
    //-->
    </SCRIPT>

    #2
    Solution

    Hi there

    After some deep thought I've come up with the following solution - although not extensively tested yet.

    The following script, amended from the AUG, will display links according to what section you are in within the site. For the script to work you would need to add a custom variable called SECTIONNAME for the top level sections of the site and a further customvar called SUBSECTIONNAME for the second section down.

    Any comments and suggestions are welcome

    Code:
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function SubSectionList(ar)
    {
     var strIDs = ' ';
     var SectionName = 'CUSTOMVAR:SECTIONNAME';
     var SubSectionName = 'CUSTOMVAR:SUBSECTIONNAME';
     {
     if (SubSectionName)//we're in a subsection
    		{
    		for (var i=1;i<=ar.length;i++)
    			{
    			if (ar[i].sURL !=null && ar[i].sName == SectionName && ar[i].pChild)
    				{
    				for (var j=1;j<=ar[i].pChild.length;j++)
    					{
    					if (ar[i].pChild[j].sName == SubSectionName && ar[i].pChild[j])
    						{
    						strIDs += '<a href="' + ar[i].pChild[j].sURL + '"><p><span class="actxxsmall">' + ar[i].pChild[j].sName + '</span></a></p>';
    							{
    							{ if (ar[i].pChild[j].pChild)// if we have a sub-subsection
    							for (var k=1;k<=ar[i].pChild[j].pChild.length;k++)
    								{
    								strIDs += '&nbsp;&nbsp;<a href="' + ar[i].pChild[j].pChild[k].sURL + '"><span class="actxxsmall">' + ar[i].pChild[j].pChild[k].sName + '</span></a><br>';
    								}
    							}
    							}
    						}
    					}
    				}
    			}
    		}
    		else //not in a subsection
    		{
    		for (var i=1;i<=ar.length;i++)
    			{
    			if (ar[i].sName == SectionName && ar[i].pChild)
    				{
    				for (var j=1;j<=ar[i].pChild.length;j++)
    						{
    						strIDs += '<a href="' + ar[i].pChild[j].sURL + '"><p><span class="actxxsmall">' + ar[i].pChild[j].sName + '</span></a></p>';
    						}
    				}
    			}
    		}	
    		}
    strIDs += ' '
    return strIDs
    		
    }
    //-->
    </SCRIPT>

    Comment

    Working...
    X