From 391768ae3f2d1fbdbab558867e7c7524fca539b6 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 7 Jan 2015 16:18:36 +0100 Subject: [PATCH 1/2] updates to variable documentation --- editions/tw5.com/tiddlers/concepts/Macros.tid | 11 ++- .../tiddlers/macros/DumpVariablesMacro.tid | 20 ++--- .../tw5.com/tiddlers/variables/Variables.tid | 10 +-- .../WidgetVariable_ currentTiddler.tid | 37 +++++++-- .../WidgetVariable_ storyTiddler.tid | 19 ++++- .../WidgetVariable_ transclusion.tid | 42 ++++++---- .../wikitext/Variables in WikiText.tid | 83 +++++++++++++++---- 7 files changed, 152 insertions(+), 70 deletions(-) diff --git a/editions/tw5.com/tiddlers/concepts/Macros.tid b/editions/tw5.com/tiddlers/concepts/Macros.tid index fbeb98fd9..85bc3962c 100644 --- a/editions/tw5.com/tiddlers/concepts/Macros.tid +++ b/editions/tw5.com/tiddlers/concepts/Macros.tid @@ -1,18 +1,17 @@ created: 20140211171341271 -modified: 20140910215504098 +modified: 20150107121000000 tags: Concepts Reference title: Macros type: text/vnd.tiddlywiki -Macros are snippets of text that can be inserted with a concise shortcut: +Macros are snippets of text, inserted with the following shortcut syntax: ``` <> ``` -You can write your own [[Macros in WikiText]] or for more flexibility you can write [[JavaScript Macros|http://tiddlywiki.com/dev/index.html#JavaScript%20Macros]]. +You can define and use [[Macros in WikiText]] or write [[JavaScript Macros|http://tiddlywiki.com/dev/index.html#JavaScript%20Macros]] for more flexibility. -The following macros are built-in to the TiddlyWiki core: - -<> +The following macros are provided by the TiddlyWiki core: +<> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/macros/DumpVariablesMacro.tid b/editions/tw5.com/tiddlers/macros/DumpVariablesMacro.tid index c83f67068..36ab8d625 100644 --- a/editions/tw5.com/tiddlers/macros/DumpVariablesMacro.tid +++ b/editions/tw5.com/tiddlers/macros/DumpVariablesMacro.tid @@ -1,28 +1,20 @@ created: 20140908104107181 -modified: 20140908104107181 +modified: 20150107121000000 tags: Macros title: DumpVariablesMacro type: text/vnd.tiddlywiki caption: dumpvariables -The dumpvariables macro displays a table containing the values of all the variables defined at that location in the widget tree. It can be useful for exploring the mechanisms of TiddlyWiki and for debugging. +The ''dumpvariables'' [[macro|Macros]] displays a table with values of all [[variables|Variables]] that are defined in the current scope. It is useful for debugging and exploring TiddlyWiki internals. -! Parameters - -The dumpvariables macro does not require any parameters - -! Examples +''Note:'' Parameters and variable subsitutions for macros are displayed as empty strings. A macro defined as `\define myMacro(text) ''$text$''` thus displays as `''''`. +!! Example ``` <> ``` -Returns: - -<> - -The results returned by the dumpvariables macro will depend upon where it is used. - -Note that the values displayed for macros are displayed with all the parameters and variable subsitutions set to an empty string. So, a macro defined as `\define myMacro(text) ''$text$''` will display as `''''`. +Renders as: +<> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/variables/Variables.tid b/editions/tw5.com/tiddlers/variables/Variables.tid index 490987001..7c08a273b 100644 --- a/editions/tw5.com/tiddlers/variables/Variables.tid +++ b/editions/tw5.com/tiddlers/variables/Variables.tid @@ -1,15 +1,13 @@ created: 20141002133113496 -modified: 20141002230631361 +modified: 20150107121000000 tags: Reference title: Variables type: text/vnd.tiddlywiki -Variables together with [[Widgets]] and [[Macros]] are essential for dynamic WikiText. +[[Variables]] are an essential component of dynamic WikiText, as are [[Widgets]] and [[Macros]]. In fact, a variable is a shorthand of a macro. -You can define your own [[Variables in WikiText]] or use built-in variables. - -More detailed information of built-in variables could be found in below: +You can define custom [[Variables in WikiText]] or use one of the standard variables... <> -See also DumpVariablesMacro \ No newline at end of file +The [[<>|DumpVariablesMacro]] macro lists all variables defined in the current scope, allowing you to see and edit their values. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/variables/WidgetVariable_ currentTiddler.tid b/editions/tw5.com/tiddlers/variables/WidgetVariable_ currentTiddler.tid index b2fbfa83c..dd1a61492 100644 --- a/editions/tw5.com/tiddlers/variables/WidgetVariable_ currentTiddler.tid +++ b/editions/tw5.com/tiddlers/variables/WidgetVariable_ currentTiddler.tid @@ -1,22 +1,41 @@ caption: currentTiddler created: 20141001232824187 -modified: 20141002161518301 +modified: 20150107121000000 tags: Variables title: WidgetVariable: currentTiddler type: text/vnd.tiddlywiki -! Mechanism +The ''currentTiddler'' [[variable|Variables]] contains the title of the current tiddler. -The ''currentTiddler'' variable contains the title of the current tiddler. +!! Usage -The ListWidget assigns the list result to the ''currentTiddler'' variable, unless the `variable` attribute is specified. +Various [[Widgets]] and [[Macros]] are by default applied with respect to the tiddler referenced via ''currentTiddler''. Within the [[ListWidget]] or TemplateTiddlers you are thus often not required to specify the tiddler title. -A couple of [[Widgets]] and [[Macros]] by default apply to the tiddler according to the ''currentTiddler'' variable. +The following two examples are thus equivalent... -The TranscludeWidget (or WikiText `{{||TemplateTitle}}`) transcludes a tiddler without changing the ''currentTiddler'' variable. +* `<$view field=title/>` +* `<$view field=title tiddler=<>/>` -! Using currentTiddler Variable +;TranscludeWidget +: when [[transcluding|Transclusion]] a tiddler, ''currentTiddler'' is set to the tiddler being transcluded, +: e.g. when using the [[WikiText shorthand|Transclusion in WikiText]]: `{{||TemplateTiddlerTitle}}` +; ListWidget +: overrides the ''currentTiddler'' variable with the currently iterated list-item, +: unless a custom `variable` attribute is specified +; TiddlerWidget +: sets the ''currentTiddler'' variable for its inner scope -These mechanisms together allow you to write references like `<$view field="title" format="link"/>` in TemplateTiddlers or inside the ListWidget hierarchy without explicitly specifying the tiddler that it applies to. +!! Example -See also [[WidgetVariable: storyTiddler]] and [[WidgetVariable: currentTiddler]] +``` +<$view tiddler=<> field=title/> +``` + +<<< +<$view tiddler=<> field=title/> +<<< + +!! Other Standard Variables + +* [[WidgetVariable: storyTiddler]] +* [[WidgetVariable: transclusion]] \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/variables/WidgetVariable_ storyTiddler.tid b/editions/tw5.com/tiddlers/variables/WidgetVariable_ storyTiddler.tid index 2153fc6e3..807ce8cf6 100644 --- a/editions/tw5.com/tiddlers/variables/WidgetVariable_ storyTiddler.tid +++ b/editions/tw5.com/tiddlers/variables/WidgetVariable_ storyTiddler.tid @@ -1,10 +1,23 @@ caption: storyTiddler created: 20141001232753952 -modified: 20141002133957245 +modified: 20150107121000000 tags: Variables title: WidgetVariable: storyTiddler type: text/vnd.tiddlywiki -The ''storyTiddler'' variable is set by the [[default viewtemplate|$:/core/ui/ViewTemplate]] to the name of the current tiddler within tiddlers in the story river, and is not defined within the sidebar. +The ''storyTiddler'' [[variable|Variables]] is set by the [[default view-template|$:/core/ui/ViewTemplate]] to the title of the tiddler in the story river. It is therefore undefined in elements like the ''sidebar''. -See also [[WidgetVariable: currentTiddler]] \ No newline at end of file +!! Example + +``` +<$view tiddler=<> field=title/> +``` + +<<< +<$view tiddler=<> field=title/> +<<< + +!! Other Standard Variables + +* [[WidgetVariable: currentTiddler]] +* [[WidgetVariable: transclusion]] \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/variables/WidgetVariable_ transclusion.tid b/editions/tw5.com/tiddlers/variables/WidgetVariable_ transclusion.tid index 5526d4cf6..816581980 100644 --- a/editions/tw5.com/tiddlers/variables/WidgetVariable_ transclusion.tid +++ b/editions/tw5.com/tiddlers/variables/WidgetVariable_ transclusion.tid @@ -1,36 +1,46 @@ caption: transclusion created: 20141002004621385 -modified: 20141002162057822 +modified: 20150107121000000 tags: Variables title: WidgetVariable: transclusion type: text/vnd.tiddlywiki -! Mechanism -The ''transclusion'' variable is set automatically by the transclude widget to contain a string that identifies the position of the current node within the widget tree. In the sidebar it is set to `{|$:/core/ui/PageTemplate/sidebar|||}` and within the tiddler "HelloThere" in the story river it is set to `{HelloThere|HelloThere|||}`. Each nested level of transclusion appends another curly bracketed list of symbols. +The ''transclusion'' [[variable|Variables]] is automatically set by the TranscludeWidget to contain a string identifying the position of the current node within the widget tree. -The QualifyMacro uses the ''transclusion'' variable to identify the stack of transcluded tiddlers. +With the ''transclusion'' variable, the QualifyMacro identifies the stack of transcluded tiddlers. -! Example +In the sidebar, the ''transclusion'' variable is set to:
+`{|$:/core/ui/PageTemplate/sidebar|||}` + +When the tiddler "HelloThere" is displayed in the story river ''transclusion'' is set to:
`{HelloThere|HelloThere|||}` + +Each nested level of transclusion appends another curly bracketed list of symbols. + +!! Example + +''identifying if we're in the sidebar or not'' ``` \define mymacro() -Hello from mymacro -<$list filter="[prefix[{|$:/core/ui/PageTemplate/sidebar|||}]]" emptyMessage="in a tiddler"> - in the sidebar +We are +<$list +filter="[prefix[{|$:/core/ui/PageTemplate/sidebar|||}]]" +emptyMessage="in the story river."> +in the sidebar. \end <> ``` -Result in story tiddler +Result in a story tiddler: -``` -Hello from mymacro in a tiddler -``` +<<< +We are in the story river. +<<< -Result in the sidebar +Result in the sidebar: -``` -Hello from mymacro in the sidebar -``` +<<< +We are in the sidebar. +<<< \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid index bd1f24786..a4d897628 100644 --- a/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid @@ -1,28 +1,79 @@ caption: Variables created: 20141002141231992 -modified: 20141018104313995 +modified: 20150107121000000 tags: WikiText title: Variables in WikiText type: text/vnd.tiddlywiki -! Defining Variables -Variables contains values defined by [[Widgets]]. -Variables are available within the widget that defines them, and the child widgets in the widget tree. +\define tags() {{!!tags}} -Variables are defined by: +[[Variables]] contain values. They are available within the scope of the [[widget|Widgets]] in which they are defined, as well as all child widgets in the widget tree. -* TiddlyWiki core and viewtemplate -* SetWidget -* ListWidget -* [[Macro definition|Macros in WikiText]] +!!Defining Variables -! Using Variables +Variables are defined by... -Variables are used in: +; [[Macros|Macros in WikiText]] +: in fact, variables are macro shorthands (see example below) +; SetWidget +: sets a variable to a value +; ListWidget +: sets list-item and iterator variabes +; TiddlyWiki +: in the core and core templates -* Variable substitution `$(name)$` -* Concise shortcut `<>` -* [[Filter expression|Introduction to Filters]] `[operator]` -* Some default behaviors of [[Widgets]] +!!Using Variables -See also [[currentTiddler|WidgetVariable: currentTiddler]] variable, built-in [[variables|Variables]] and [[Confusion between Transclusion and Substitution]]. +Variables are used via... + +; shorthand +:`<>` +; variable substitution within [[macros|Macros]] +:`$(variableName)$` +; as variable operands in [[filter expressions|Introduction to Filters]] +: `[operator]` +; in [[widgets|Widgets]] +: internally, or as widget attributes +: `<$edit tiddler=<>/>` + +!! Examples + +''defining a variable via SetWidget'' + +``` +<$set name=foo value=bar> +<> + +``` + +<<< +<$set name=foo value=bar> +<> + +<<< + +''a variable is a macro'' + +Below, the `\define` pragma at the beginning of a tiddler [[defines the macro|Macros in WikiText]] `<>`, valid in the scope of the CurrentTiddler, returning the value of the standard `tags` field. + +``` +\define tags() {{!!tags}} + +<> +``` + +<<< +<> +<<< + +''using a filter variable to get all incoming links'' + +Using the [[backlinks|FilterOperator: backlinks]] [[filter operator|FilterOperators]] to get all tiddlers linking to this one... + +``` +<backlinks[]]">> +``` + +<<< +<backlinks[]]">> +<<< \ No newline at end of file From 3657bbe9206d1ede62d0e9ed688e04e8f232afdd Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 10 Jan 2015 18:08:12 +0000 Subject: [PATCH 2/2] Switch from addEventListener to onbeforeunload This makes it possible for TiddlyDesktop to reuse these functions to handle detecting unsaved changes --- core/modules/saver-handler.js | 4 ++-- core/modules/syncer.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/modules/saver-handler.js b/core/modules/saver-handler.js index 0669ec917..3344495c7 100644 --- a/core/modules/saver-handler.js +++ b/core/modules/saver-handler.js @@ -75,14 +75,14 @@ function SaverHandler(options) { } }); // Set up our beforeunload handler - window.addEventListener("beforeunload",function(event) { + window.onbeforeunload = function(event) { var confirmationMessage; if(self.isDirty()) { confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); event.returnValue = confirmationMessage; // Gecko } return confirmationMessage; - }); + }; } // Install the save action handlers if($tw.browser) { diff --git a/core/modules/syncer.js b/core/modules/syncer.js index 08d5deb19..617c54155 100644 --- a/core/modules/syncer.js +++ b/core/modules/syncer.js @@ -39,14 +39,14 @@ function Syncer(options) { // Browser event handlers if($tw.browser) { // Set up our beforeunload handler - window.addEventListener("beforeunload",function(event) { + window.onbeforeunload = function(event) { var confirmationMessage; if(self.isDirty()) { confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); event.returnValue = confirmationMessage; // Gecko } return confirmationMessage; - }); + }; // Listen out for login/logout/refresh events in the browser $tw.rootWidget.addEventListener("tm-login",function() { self.handleLoginEvent();