Hi all,
Is there any ways we can collapse/expand the content in the section by clicking on the heading?
<$button class="tc-btn-invisible" popup=<<qualify "$:/temp/popup">>>
!heading text
</$button>
<$reveal type="nomatch" state=<<qualify "$:/temp/popup">> text="">
section content goes here
</$reveal>
Use a <$button> widget with class="tc-btn-invisible" to create the heading. Surround the section content with a corresponding <$reveal> widget.
<<fold "!Section One" """and here comes the content""">><br> <<fold "!Section Two" """has entirely different content""">>
\define fold(heading, text) <$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>> $heading$ </$button> <$reveal type="nomatch" state=<<qualify "$:/state/section$heading$">> text=""> $text$ </$reveal> \end
\define fold(content)
<$set name="controller" value="$:/state/$(currentTiddler)$/section/$content$">
<$reveal type="nomatch" state=<<controller>> text="open">
<$button class="tc-btn-invisible" set=<<controller>> setTo="open">
<$transclude tiddler="$content$" field="caption" /> (closed)
</$button>
</$reveal>
<$reveal type="match" state=<<controller>> text="open">
<$button class="tc-btn-invisible" set=<<controller>> setTo="close">
<$transclude tiddler="$content$" field="caption" /> (open)
</$button>
</$reveal>
<$reveal type="match" state=<<controller>> text="open">
<$transclude tiddler="$content$" />
</$reveal>
</$set>
\end
OK, I have now got a version that actually works (slimmed down version - mine uses FontAwesome icons and has an edit-from-controller link, too)
\define fold(content)
<$set name="controller" value={{{ [[$:/state/]addsuffix<currentTiddler>addsuffix[/fold/]addsuffix<content>] }}}>
<$reveal type="nomatch" state=<<controller>> text="open">
<$button class="tc-btn-invisible" set=<<controller>> setTo="open">
<$transclude tiddler="$content$" field="caption" /> (closed)
</$button>
</$reveal>
<$reveal type="match" state=<<controller>> text="open">
<$button class="tc-btn-invisible" set=<<controller>> setTo="close">
<$transclude tiddler="$content$" field="caption" /> (open)
</$button>
</$reveal>
<$reveal type="match" state=<<controller>> text="open">
<$transclude tiddler="$content$" />
</$reveal>
</$set>
\end
This allows the target content to be included as foldable on multiple tiddlers, or multiple targets within one tiddler, without any interference between their open/closed states. The only time there would be interference is if you're including the same content into a single parent multiple times, but that's your own fault.
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/7c063182-5334-4172-bea1-9ce6d7941528%40googlegroups.com.
OK, I have now got a version that actually works (slimmed down version - mine uses FontAwesome icons and has an edit-from-controller link, too)
Interesting... *stuffs macro in pocket when no one is looking* : )
<span class="cs-fold-right"><$button>
<$action-navigate $to="$content$" />
<$action-sendmessage $message="tm-edit-tiddler" $param="$content$" />
<i class="fas fa-pen-square"></i>
</$button></span>
}
.cs-fold-right {
display: inline-block;
float: right;
}
\define fold(id, caption, content)<$set name="controller" value={{{ [[$:/temp/state/]addsuffix<currentTiddler>addsuffix[/fold/]addsuffix[$id$]] }}}>
<$reveal type="nomatch" state=<<controller>> text="open"> <$button class="tc-btn-invisible" set=<<controller>> setTo="open">
''$caption$'' {{$:/core/images/unfold-button}}
</$button></$reveal><$reveal type="match" state=<<controller>> text="open"> <$button class="tc-btn-invisible" set=<<controller>> setTo="close">
''$caption$'' {{$:/core/images/fold-button}}
</$button></$reveal>
<$reveal type="match" state=<<controller>> text="open">
$content$
</$reveal></$set>\end
<$set name="controller" value={{{ [[$:/temp/state/fold/]addsuffix[$id$]] }}}>
<$action-sendmessage $message="tm-edit-text-operation" $param="wrap-lines" prefix='<<fold "id" "caption" """' suffix='""">>'/>
<<fold "FoldExampleNo1" "Click me to view more :)" """WOHOOOO Hidden Text!
!! This is great!
""">>
Just wanted to check if there is any way to add a arrow indicator to the collapsed section to your macro code.
\define fold(heading, text)
<$reveal type="match" state=<<qualify "$:/state/section$heading$">> text="">
<$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>>
$heading$ {{$:/core/images/chevron-right}}
</$button>
<$reveal type="nomatch" state=<<qualify "$:/state/section$heading$">> text="">
$heading$ {{$:/core/images/chevron-down}}
$text$
</$reveal>
\end
I tried it and it displays the heading with the right arrow but when i click on the heading to expand text, no text appears and the heading disappears as well. When i click anywhere on the screen the heading re-appears.
\define fold(heading, text)<$reveal type="match" state=<<qualify "$:/state/section$heading$">> text=""><$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>>
$heading$ {{$:/core/images/chevron-right}}</$button>
</$reveal>
<$reveal type="nomatch" state=<<qualify "$:/state/section$heading$">> text="">
<$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>>
$heading$ {{$:/core/images/chevron-down}}</$button><br>$text$</$reveal>\end
<<fold "test1" """this is a test""">><<fold "test2" """another test""">>
Now it works but it completely removes the formatting of the hidden text!! 😭
\define fold(heading, text)
<$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>>
$heading$ {{$:/core/images/chevron-right}}
<
/$button>
<$reveal type="nomatch" state=<<qualify "$:/
state/section$heading$">> text="">
$text$
</$reveal>
\end
\define fold(heading, text)
<$button class="tc-btn-invisible" popup=<<qualify "$:/state/section$heading$">>>
$heading$ {{$:/core/images/fold-button}}
</$button>
<$reveal type="nomatch" state=<<qualify "$:/state/section$heading$">> text="">
$text$
</$reveal>
\end