Duncan Glendinning

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromDuncan Glendinning
ToMe
SubjectProblem with Nested list collapsing script
Date2 September 2008 15:04
Hi there!!

Despite looking on your site, I can't find the solution to what I want
to do, so am hoping you can help.
Am using your Nested list collapsing script, and when the page loads,
the tree is fully collapsed, as you would expect. What I would like to
do is be able to set it to have one branch of it (or sub branch)
expanded when the page loads. Is there any way of doing this?

Many thanks in advance for your help, and what a fantastic, simple script!!

All the best,
Duncan Glendinning
FromMe
ToDuncan Glendinning
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 16:30
Duncan,

> have one branch of it (or sub branch) expanded when the page loads.

See the documentation for the selfLink function, which can be used for this purpose.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromDuncan Glendinning
ToMe
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 17:16
*Good Afternoon Mark,

Sorry, still no luck. I have this:
*
<ul  class="maketree" id="treeversion">
<li>Book 1
<ul>
 <li><a href="someHref">Chapter 1</a></li>
 <li><a href="someHref">Chapter 2</a></li>
 <li><a href="someHref">Chapter 3</a></li>
 <li><a href="someHref">Chapter 4</a></li>
</ul>
</li>
<li>Book 2
<ul>
 <li><a href="someHref">Chapter 1</a></li>
 <li><a href="someHref">Chapter 2</a></li>
 <li>Chapter 3
   <ul>
     <li><a href="listCollapseExample.html">Ex 1</a></li>
     <li><a href="someHref">Ex 2</a></li>
   </ul>
 </li>
 <li><a href="javascript:notA();">Chapter 4</a></li>
</ul>
</li>
<li class="last">Book 3
<ul id="expandthis">
   <li ><a href="javascript:notA();">Chapter 1</a></li>
   <li><a href="javascript:notA();">Chapter 2</a></li>
   <li><a href="javascript:notA();">Chapter 3</a></li>
   <li class="last"><a href="javascript:notA();">Chapter 4</a></li>
</ul>
</li>
</ul>

*Followed by this:*

<script type="text/javascript">
   compactMenu('treeversion',false,'&plusmn; ');
   selfLink('treeversion','samePage',true);
   expandCollapseAll('expandthis',true);
</script>

*And I am hoping the Book 3 would load expanded, showing* Chapters 1, 2, and
3. No luck though.
*Can you point me in the right direction?*
*
Best regards,
Duncan
FromMe
ToDuncan Glendinning
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 17:29
Duncan,

>    <li ><a href="javascript:notA();">Chapter 1</a></li>
> ...
>    selfLink('treeversion','samePage',true);

It looks through the lists for a link that points to the current page. None
of the links in the section you want to expand point to the current page.
You have to set up the links properly first. It won't work if you leave them
all with their href set to "javascript:notA();".

Alternatively, if you don't want it to point to the current page, it could
be used like this:
<li><a href="foo.html">Chapter 1</a></li>
...
selfLink('treeversion','whatever',true,'foo.html');

>    expandCollapseAll('expandthis',true);

Remove this. It should say 'treeversion' not 'expandthis' anyway, but don't
bother, since you don't want it to expand the entire tree.


Tarquin
FromDuncan Glendinning
ToMe
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 17:34
Tarquin,

I get you regarding the links... how do I make one branch of the list
load already expanded though then, seeing as I can't seem to be able
to do this..your documentation says its using expandCollapseAll() but
then as you said I don't want to load all the branches expanded, just
the Book 3 one so it shows its chapters when the page loads.

Thank you so much for your help, really appreciate it.

Duncan
FromMe
ToDuncan Glendinning
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 17:39
Duncan,

> I get you regarding the links... how do I make one branch of the list
> load already expanded though then

Then you don't get me. You need to set the links up correctly. selfLink
cannot work until you do that. Set the links up, and selfLink can either
expand whatever branch has a link pointing to the current page, or it can
(if you choose) expand a branch containing a link to a chosen href.

Tarquin
FromDuncan Glendinning
ToMe
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 18:37
Tarquin,

Sorted, thank you so much!
Last question, I promise.
How can I use  selfLink() to expand a branch whose parent is not a
link to anything?

For example:

<ul class="maketree" id="treeversion">
<li>Book 1
    <ul>

        <li><a href="book1chap1.html">Chapter 1</a></li>
        <li><a href="book1chap2.html">Chapter 2</a></li>
        <li><a href="book1chap3.html">Chapter 3</a></li>
        <li class="last"><a href="book1chap4.html">Chapter 4</a></li>
    </ul>
</li>
<li>Book 2
    <ul>
        <li><a href="book2chap1.html">Chapter 1</a></li>
        <li><a href="book2chap2.html">Chapter 2</a></li>
        <li >Chapter 3
            <ul>
                <li><a href="book2chap2ex1.html">Ex 1</a></li>
                <li class="last"><a href="book2chap2ex2.html">Ex 2</a></li>
            </ul>

        </li>
        <li class="last"><a href="book2chap4.html">Chapter 4</a></li>
    </ul>
</li>
<li class="last"><A HREF='book3.html'>Book 3</A>
<ul >
    <li ><a href="book3chap1.html">Chapter 1</a></li>
    <li><a href="book3chap2.html">Chapter 2</a></li>

    <li><a href="book3chap3.html">Chapter 3</a></li>
    <li class="last"><a href="book3chap4.html">Chapter 4</a></li>
</ul>
</li>
</ul>


What would I do to expand down to Chapter 3 of Book 2, seeing as the
actual Chapter 3 li isn't in an href with a url you can reference in
the selfLink() function?

Thanks again,

Duncan
FromDuncan Glendinning
ToMe
SubjectRe: Problem with Nested list collapsing script
Date2 September 2008 19:51
Duncan,

>         <li><a href="book2chap2.html">Chapter 2</a></li>
>         <li >Chapter 3
>             <ul>
>                 <li><a href="book2chap2ex1.html">Ex 1</a></li>
>
> What would I do to expand down to Chapter 3 of Book 2

selfLink one of its siblings instead. In this case, something like:
selfLink('treeversion','',true,'book2chap2.html');

(It is also possible to abuse stateToFromStr to get it to expand even if
there is not a sibling with a link, but that's generally much more
trouble than it's worth, since it's not designed for that purpose, and it
will not cope with you adding or removing list items. So if you did need to
do that, it's generally easier to selfLink a child of chapter 3 like
'book2chap2ex1.html', and live with the differences.)
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.