[TW5] Autocollaps TOC categories

377 views
Skip to first unread message

magev958

unread,
Mar 3, 2015, 3:23:05 AM3/3/15
to tiddl...@googlegroups.com
Hello, I was wondering if it is possible to auto-collapse open categories in the TOC when you click on another.
I have 800 links in 40 or 50 subcategories, making a very long list if everything is open

category (TOC link: no)
   subcategory (TOC link: no)
      sub-sub-category (TOC link: no)
         link

Andreas Hahn

unread,
Mar 3, 2015, 6:46:31 AM3/3/15
to tiddl...@googlegroups.com

Hi,

yes that is very possible and here is how you would do it:

\define toc-selective-single-expandable(tag,sort:"",itemClassFilter)
<ol class="tc-toc toc-selective-expandable">
<$list filter="[all[shadows+tiddlers]tag[$tag$]!has[draft.of]$sort$]">
<$list filter="[all[current]toc-link[no]]" variable="ignore" emptyMessage="<<toc-linked-selective-single-expandable-body tag:'$tag$' sort:'$sort$' itemClassFilter:'$itemClassFilter$'>>">
<<toc-unlinked-selective-single-expandable-body tag:"""$tag$""" sort:"""$sort$""" itemClassFilter:"""$itemClassFilter$""">>
</$list>
</$list>
</ol>
\end

\define toc-linked-selective-single-expandable-body(tag,sort:"",itemClassFilter)
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$">>>
<$set name="toc-item-class" filter="""$itemClassFilter$""" value="toc-item-selected" emptyValue="toc-item">
<li class=<<toc-item-class>>>
<$link>
<$list filter="[all[current]tagging[]limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button>">
<$reveal type="nomatch" state=<<toc-state>> text=<<currentTiddler>>>
<$button set=<<toc-state>> setTo=<<currentTiddler>> class="tc-btn-invisible">
{{$:/core/images/right-arrow}}
</$button>
</$reveal>
<$reveal type="match" state=<<toc-state>> text=<<currentTiddler>>>
<$button set=<<toc-state>> setTo="x-all-close" class="tc-btn-invisible">
{{$:/core/images/down-arrow}}
</$button>
</$reveal>
</$list>
<<toc-caption>>
</$link>
<$reveal type="match" state=<<toc-state>> text=<<currentTiddler>>>
<$macrocall $name="toc-selective-single-expandable" tag=<<currentTiddler>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$"""/>
</$reveal>
</li>
</$set>
</$set>
\end

\define toc-unlinked-selective-single-expandable-body(tag,sort:"",itemClassFilter)
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$">>>
<$set name="toc-item-class" filter="""$itemClassFilter$""" value="toc-item-selected" emptyValue="toc-item">
<li class=<<toc-item-class>>>
<$list filter="[all[current]tagging[]limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button> <$view field='caption'><$view field='title'/></$view>">
<$reveal type="nomatch" state=<<toc-state>> text=<<currentTiddler>>>
<$button set=<<toc-state>> setTo=<<currentTiddler>> class="tc-btn-invisible">
{{$:/core/images/right-arrow}}
<<toc-caption>>
</$button>
</$reveal>
<$reveal type="match" state=<<toc-state>> text=<<currentTiddler>>>
<$button set=<<toc-state>> setTo="close" class="tc-btn-invisible">
{{$:/core/images/down-arrow}}
<<toc-caption>>
</$button>
</$reveal>
</$list>
<$reveal type="match" state=<<toc-state>> text=<<currentTiddler>>>
<$macrocall $name="""toc-selective-single-expandable""" tag=<<currentTiddler>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$"""/>
</$reveal>
</li>
</$set>
</$set>
\end

Copy and append this either in $:/core/macros/toc or make a new tiddler copy this into it and tag it $:/tags/Macro. Then use it with:

<<toc-selective-single-expandable 'TableOfContents'>>

Alternatively you can just drag&drop the attached file and import the tiddlers.

/Andreas

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

toc-autocollaps.json

magev958

unread,
Mar 3, 2015, 10:00:19 AM3/3/15
to tiddl...@googlegroups.com
Thank You, it works like a charm :)

Jon

unread,
Mar 3, 2015, 2:39:00 PM3/3/15
to tiddl...@googlegroups.com
Thanks Andreas, this is great.

Regards
Jon

Tobias Beer

unread,
Mar 5, 2015, 5:00:39 AM3/5/15
to tiddl...@googlegroups.com
Hi Andreas,

Can you see to it that this doesn't get buried in a discussion thread.
To me this feels like the best default behaviour, 
possibly alongside some "live mode" (later)
updating the toc so as to show the last opened / currently viewed tiddler.

Best wishes, Tobias. 

magev958

unread,
Mar 5, 2015, 5:18:29 AM3/5/15
to tiddl...@googlegroups.com
A follow-up question. TOC get sorted by the "title" but I would like to sort it by "caption ". Where do I put that in the code?
 

Tobias Beer

unread,
Mar 5, 2015, 6:45:56 AM3/5/15
to tiddl...@googlegroups.com
Hi magev958,
 
A follow-up question. TOC get sorted by the "title" but I would like to sort it by "caption ". Where do I put that in the code?

If I interpret the code right, the second parameter of the macro seems to cater for a sort filter component like so...

<<toc-selective-single-expandable "TableOfContents" "sort[caption]">>

You could sort by title first and then caption, in case there was no caption...

<<toc-selective-single-expandable "TableOfContents" "sort[title]sort[caption]">>

Best wishes, Tobias.

Andreas Hahn

unread,
Mar 5, 2015, 7:10:04 AM3/5/15
to tiddl...@googlegroups.com
Am 05.03.2015 um 11:00 schrieb Tobias Beer:
> Can you see to it that this doesn't get buried in a discussion thread.
> To me this feels like the best default behaviour,

Maybe this can be added as an "example" to the official documentation,
much like the TaskManagement example.

/Andreas

Andreas Hahn

unread,
Mar 5, 2015, 7:12:50 AM3/5/15
to tiddl...@googlegroups.com
Am 05.03.2015 um 12:45 schrieb Tobias Beer:
You could sort by title first and then caption, in case there was no caption...

Am I wrong, or does this at most result in the tiddlers with an empty caption being sorted alphabetically by title ? And even that might not be guaranteed by the TW sort algorithm.
So what would be the advantage to sort it by title first ? (It does not produce a perfectly sorted output, does it ?)

/Andreas

magev958

unread,
Mar 5, 2015, 8:32:44 AM3/5/15
to tiddl...@googlegroups.com
It's so simple that I should have figured it out myself :)

Tobias Beer

unread,
Mar 6, 2015, 12:48:22 AM3/6/15
to tiddl...@googlegroups.com
Am I wrong, or does this at most result in the tiddlers with an empty caption being sorted alphabetically by title ? And even that might not be guaranteed by the TW sort algorithm. So what would be the advantage to sort it by title first ? (It does not produce a perfectly sorted output, does it ?)

Tbh, I just assumed it would do what it says... as I'm sure that not all tiddler's have a caption. At second thought, you're right... what's the point of sorting by title if we have the default sorting algorithm from the tagging / list order. So, perhaps forget the title part. I guess, if we wanted it properly we'd also want to first sort by caption and then have the list-field order applied. Looks like  that's not an option, though.

Best wishes, Tobias.
Reply all
Reply to author
Forward
0 new messages