TiddlyWiki5/editions/tw5.com/tiddlers/features/StartupActions.tid

45 lines
2.2 KiB
Plaintext
Raw Normal View History

2018-03-23 09:35:39 +00:00
created: 20180323092308399
2020-10-25 16:22:21 +00:00
modified: 20201025161723719
2018-03-23 09:35:39 +00:00
tags: Features
title: StartupActions
type: text/vnd.tiddlywiki
TiddlyWiki executes any ActionWidgets found in tiddlers with the following system tags during startup:
2018-03-23 09:35:39 +00:00
2020-10-25 16:22:21 +00:00
* Executed during initial startup:
** <<tag "$:/tags/StartupAction">> (executed on all platforms)
** <<tag "$:/tags/StartupAction/Browser">> (only executed when running in the browser)
** <<tag "$:/tags/StartupAction/Node">> (only executed when running under Node.js)
* Executed after startup rendering:
** <<.from-version "5.1.23">> <<tag "$:/tags/StartupAction/PostRender">> (only executed when running in the browser)
2018-03-23 09:35:39 +00:00
2020-10-25 16:22:21 +00:00
!! Initial Startup Actions
The initial startup actions are useful for customising TiddlyWiki according to environmental factors such as the screen size. For example, the following action widgets when placed in a tiddler tagged `$:/tags/StartupAction/Browser` will cause the sidebar to be hidden by default when the screen width is less than 1000 pixels:
2018-03-23 09:35:39 +00:00
```
<$reveal type="lt" state="$:/info/browser/screen/width" text="3000">
<$action-setfield $tiddler="$:/state/sidebar" $value="no"/>
</$reveal>
<$reveal type="gteq" state="$:/info/browser/screen/width" text="3000">
<$action-setfield $tiddler="$:/state/sidebar" $value="yes"/>
</$reveal>
```
2018-03-23 11:48:48 +00:00
<<.from-version "5.1.20">> This example switches to the language plugin matching the language reported by the browser:
```
<$action-setfield $tiddler="$:/language" text={{{ [[$:/languages/en-GB]] [plugin-type[language]sort[description]removeprefix[$:/languages/]] +[prefix{$:/info/browser/language}] ~[[en-GB]] +[addprefix[$:/languages/]] }}}/>
```
2020-10-25 16:22:21 +00:00
Note that global macros are not available within initial startup action tiddlers by default. If you need to access them then you'll need to explicitly include them with an ''import'' [[pragma|Pragma]] at the top of the tiddler:
2018-03-23 11:48:48 +00:00
```
2018-09-28 17:18:07 +00:00
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
2018-03-23 11:48:48 +00:00
```
2020-10-25 16:22:21 +00:00
!! Post-Render Startup Actions
<<.from-version "5.1.23">> Post-render startup actions occur after the TiddlyWiki user interface has been rendered. This makes it possible to perform actions that depend on the rendered display (such as displaying modals).