<$button>
Button!
<$fieldmangler>
<$action-sendmessage $message="tm-add-tag" $param="MyTag"/>
<$text text="chTxt"/>
</$fieldmangler>
</$button>
var chWidgetsArray = [];
chWidgetsArray.push(
{ type: "fieldmangler",
children: [
{ type: "action-sendmessage", message: "tm-add-tag", param: "MyTag" },
{ type: "text", text: "chTxt" }
]
}
);
this.makeChildWidgets(chWidgetsArray);
Having said that... Really what I'm trying to learn is how to write a javascript widget that sends messages up the chain to the tiddler the widget is sitting on, and I'm stuck on doing this with a button widget! Child widgets made in button.js do work (i.e. text), but not action-sendmessage!
// Make a list of Tiddlers tagged with "myTag", which aren't drafts
<$list filter="[tag[$tag$]] -[has[draft.of]]" variable="myTag">
// Output the list as button widgets
<$button class="button off">
// When the button is clicked, make a temp Tiddler with these tags in a field called "list"
<$action-listops $tiddler="$:/temp/myTags" $field:list $subfilter="[tag[$tag$]] -[has[draft.of]]"/>
// Take the current Tiddler (where this is called from) and tag it
with a list with the tags from the list in the temp Tiddler removed, and
tagWithSpaces (which is myTag) appended (not sure here?)
<$action-listops $tiddler=<<currentTiddler>> $tags="+[remove{$:/temp/myTags!!list}append<tagWithSpaces>]" />
<<myTag>>
</$button>
</$list>
\end
Wow, thank you! I have to say, I'm impressed but confused more! Looking at that, I think I'm scared off TW5 even more...
Totally cryptic compared to the JavaScript modules! ;-)
Now I have more to learn. :-)
I think I've figured out what it does...
Next step is to reset the "class" of the buttons to "off", then set the "class" of the button I've clicked to "on".
This is why I'm thinking it would have been easier to write a widget in JavaScript than to write a macro in TW.
Again, totally impressed, but equally stumped! At least I'm learning!!
Next step is to reset the "class" of the buttons to "off", then set the "class" of the button I've clicked to "on".
See tc-xxxx classes in tw help and my code above.
Adding style sheets is easy. Just create a tiddler eg: myStyles and tag it: $:/tags/Stylesheet
It needs to contain valid CSS code.
if (iClickedThisButton) {
\define $buttonClass$ = "on"
} else {
\define $buttonClass
$ = "off
}
<$button class="$buttonClass
$">
<$list .... all your other code >
\define tagWithSpaces()[[$(myTag)$]]
\define toggleTagSelect(tag)
<$select>
<$list filter="[tag[$tag$]] -[has[draft.of]]" variable="myTag">
<$action-listops $tiddler="$:/temp/myTags" $field:list $subfilter="[tag[$tag$]] -[has[draft.of]]" />
<$action-listops $tiddler=<<currentTiddler>> $tags="+[remove{$:/temp/myTags!!list}append<tagWithSpaces>]" />
<option value={{<<myTag>>!!text}}><<myTag>></option>
</$list>
</$select>
\end
value={{<<myTag>>!!text}}
comes out blank when I inspect the option element. I've tried a bunch of variations.\define toggleTagButtons(tag)
<$list filter="[tag[$tag$]] -[has[draft.of]]" variable="myTag">
<$set name="buttonClass" filter="[is[current]tag<myTag>]" value="button on" emptyValue="button off">
<$button class=<<buttonClass>>>
<$action-listops $tiddler="$:/temp/myTags" $field:list $subfilter="[tag[$tag$]] -[has[draft.of]]"/>
<$action-listops $tiddler=<<currentTiddler>> $tags="+[remove{$:/temp/myTags!!list}append<tagWithSpaces>]" />
<<myTag>>
</$button>
</$set>
</$list>
\end
WOW! I answered my own question! I'm seriously impressed.
<$action-listops $tiddler="$:/temp/myTags" $field:list $subfilter="[tag[$tag$]] -[has[draft.of]]"/>
<$action-listops $tiddler=<<currentTiddler>> $tags="+[remove{$:/temp/myTags!!list}append<tagWithSpaces>]" />
The temporary Tiddler that saves the state of the tags needs to be named for the Tiddler and the tag in question, like this:
$:/temp/<currentTiddler>/$tag$
This way each instance on each Tiddler with this widget on it has it's own temporary Tiddler named for the Tiddler/instance.
\define state() $:/temp/toggle-tags/$(currentTiddler)$/$(item)$
\define replace() +[remove{$(state)$!!list}append<title>]
\define remove() +[remove{$(state)$!!list}]
\define title() [[$(item)$]]
\define toggle-tags(filter)
<$list filter="$filter$ -[has[draft.of]]" variable="item">
<$set name="cls" filter="[is[current]tag<item>]" value="button on" emptyValue="button off">
<$button class=<<cls>>>
<$action-listops $tiddler=<<state>> $field:list $subfilter="$filter$ -[has[draft.of]]"/>
<$list filter="[<cls>] -[[button on]]" variable="none">
<$action-listops $tags=<<replace>> />
</$list>
<$list filter="[<cls>] -[[button off]]" variable="none">
<$action-listops $tags=<<remove>> />
</$list>
<$text text=<<item>>/>
</$button>
</$set>
</$list>
\end
!! Example
; filters
: <<toggle-tags filter:"[tag[Filter Operators]removesuffix[ Operator]]">>
; macros
: <<toggle-tags filter:"[tag[Macros]removesuffix[ Macro]]">>
<style>
.button.on {color:deeppink;}
</style>