-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OcttKB Cross-Repo Sync (HTML to Raw)
- Loading branch information
octospacc
committed
Jan 29, 2024
1 parent
091ea33
commit 35eb8cb
Showing
42 changed files
with
690 additions
and
33 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_changelog.tid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
created: 20171230164920491 | ||
modified: 20171230165117169 | ||
tags: | ||
title: $:/plugins/ebalster/condition/changelog | ||
|
||
!!Version 0.1.1 — December 30, 2017 | ||
|
||
* Fix an error when refreshing the condition widget. | ||
* Fix "match" attribute not working as expected. | ||
|
||
|
||
!!Version 0.1.0 — December 29, 2017 | ||
|
||
* Initial implementation. | ||
* Includes $if, $else, $else-if | ||
* Common code in condition.js |
28 changes: 28 additions & 0 deletions
28
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_license.tid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
caption: license | ||
created: 20171230044445712 | ||
modified: 20171230044506791 | ||
revision: 0 | ||
tags: | ||
title: $:/plugins/ebalster/condition/license | ||
type: text/vnd.tiddlywiki | ||
|
||
!!The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Evan Balster | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
94 changes: 94 additions & 0 deletions
94
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_readme.tid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
caption: readme | ||
created: 20171230044517252 | ||
modified: 20171230052355854 | ||
revision: 0 | ||
tags: | ||
title: $:/plugins/ebalster/condition/readme | ||
type: text/vnd.tiddlywiki | ||
|
||
The ''Condition'' plugin for TiddlyWiki, version {{$:/plugins/ebalster/condition!!version}}, by Evan Balster. | ||
|
||
This plugin defines widgets that will either show or hide their contents depending on a condition. | ||
|
||
Unlike the closely-related reveal widget, condition widgets do //not// retain their content, and do not support animation or popups. Conditions may be based on variables, macros or filtered attributes. It can also be used with the [[Formula Plugin]]. | ||
|
||
|
||
!!Truthiness | ||
|
||
Truthiness is a simple rule for whether a value triggers an "if" widget or not. Values are "truthy" if they do not match any of the "falsy" values below: | ||
|
||
* The number `0`, including any decimal point. | ||
* `false` | ||
* `undefined` | ||
* `null` | ||
* Blank (no text) | ||
|
||
This matching is case-insensitive, and any whitespace before or after the value will be ignored. | ||
|
||
|
||
!!If Widget | ||
|
||
The `$if` widget will show its content based on whether a value is "truthy", or matches another value. | ||
|
||
|Attribute|Meaning|h | ||
|value|''Required.'' Content is shown if `value` is truthy.| | ||
|match|Optional. If present, `value` and `match` must equal //exactly// for content to be shown. (Truthiness doesn't matter.)| | ||
|not|Inverts the condition, so the value will be shown if it would be hidden and vice versa.| | ||
|
||
For example, | ||
|
||
``` | ||
<$if not value={{$:/StoryList}}> | ||
No tiddlers are open right now! | ||
</$if> | ||
``` | ||
|
||
|
||
!!Else Widget | ||
|
||
The `$else` widget has no attributes. It must be placed after one of the conditional widgets listed below, and will only show its contents if the preceding widget is //not// showing its content. | ||
|
||
|After...|Show contents when...|h | ||
|`$if`<br/>`$else-if`|None of the previous if-conditions was true.| | ||
|`$list`|The list is empty. `$else` can be used instead of emptyMessage.| | ||
|`$reveal`|The contents of the reveal widget are hidden.| | ||
|`$else`|An else after an else will //never// be shown.| | ||
|
||
For example: | ||
|
||
``` | ||
<$if value={{{[tag[Note]]}}}> | ||
!!My notes: | ||
<$list filter="[tag[Note]]"> | ||
- {{!!title}} | ||
</$list> | ||
</$if> | ||
<$else> | ||
!!I don't have any notes... | ||
</$else> | ||
``` | ||
|
||
Note that the else widget can't have any blank lines between it and the preceding widget. | ||
|
||
|
||
!!Else-If Widget | ||
|
||
The `$else-if` widget is a combination of the `$else` and `$if` widgets, and has the same attributes as the `$if` widget. Its content will only be displayed if the previous widget is //not// showing its content //and// the `$if`-condition is true. | ||
|
||
`$else-if` widgets can be used to perform a "chain" of tests, showing some text based on the first condition that passes (or fails). For example: | ||
|
||
``` | ||
Something approaches... | ||
|
||
<$if value={{!!animal}} match=cat> Meow! </$if> | ||
<$else-if value={{!!animal}} match=dog> Bark! </$else-if> | ||
<$else-if value={{!!animal}} match=bird> Tweet! </$else-if> | ||
<$else> This isn't like any animal you've seen before. </$else> | ||
``` | ||
|
||
|
||
!!Help & Support | ||
|
||
This plugin is a work in progress; seek help with it on the TiddlyWiki Google Group: https://groups.google.com/forum/#!forum/tiddlywiki | ||
|
||
Or E-mail me directly: [[evan@imitone.com|mailto://evan@imitone.com]] |
15 changes: 15 additions & 0 deletions
15
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_repack.tid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
created: 20171230044112191 | ||
modified: 20171230165309317 | ||
revision: 0 | ||
tags: | ||
title: $:/plugins/ebalster/condition/repack | ||
type: text/vnd.tiddlywiki | ||
|
||
Repacking command (use this in the browser console to repack the plugin) | ||
|
||
<pre><code>$tw.utils.repackPlugin("$:/plugins/ebalster/condition", (= "[" & textjoin(",", | ||
TRUE, | ||
[prefix[$:/plugins/ebalster/condition/]addprefix["]addsuffix["]]) & "]" =)); | ||
</code></pre> | ||
|
||
Version: <$edit-text tiddler="$:/plugins/ebalster/condition" field="version" /> |
163 changes: 163 additions & 0 deletions
163
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_widgets_condition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/*\ | ||
title: $:/plugins/ebalster/condition/widgets/condition.js | ||
type: application/javascript | ||
module-type: widget | ||
Base class for condition widgets. | ||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
var Widget = require("$:/core/modules/widgets/widget.js").widget; | ||
|
||
var ConditionWidget = function(parseTreeNode,options) { | ||
if(arguments.length > 0) { | ||
this.initialise(parseTreeNode,options); | ||
} | ||
}; | ||
|
||
/* | ||
Inherit from the base widget class | ||
*/ | ||
ConditionWidget.prototype = new Widget(); | ||
|
||
/* | ||
Render this widget into the DOM | ||
*/ | ||
ConditionWidget.prototype.render = function(parent,nextSibling) { | ||
this.parentDomNode = parent; | ||
this.computeAttributes(); | ||
this.execute(); | ||
this.rerender(parent,nextSibling); | ||
}; | ||
|
||
ConditionWidget.prototype.rerender = function(parent,nextSibling) { | ||
this.removeChildDomNodes(); | ||
if (this.conditionError) { | ||
// Show an error. | ||
var parseTreeNodes = [{type: "element", tag: "span", attributes: { | ||
"class": {type: "string", value: "tc-error"} | ||
}, children: [ | ||
{type: "text", text: this.conditionError} | ||
]}]; | ||
this.makeChildWidgets(parseTreeNodes); | ||
} | ||
else if (this.isOpen) { | ||
// Construct and render the child widgets. | ||
this.makeChildWidgets(this.parseTreeNode.children); | ||
} | ||
else { | ||
// Destroy the child widgets. | ||
this.children = []; | ||
} | ||
this.renderChildren(parent,nextSibling); | ||
}; | ||
|
||
/* | ||
Compute the internal state of the widget (default behavior) | ||
*/ | ||
ConditionWidget.prototype.execute = function() { | ||
this.executeIf("$condition"); | ||
}; | ||
|
||
/* | ||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | ||
*/ | ||
ConditionWidget.prototype.refresh = function(changedTiddlers) { | ||
var currentlyOpen = this.isOpen; | ||
var changedAttributes = this.computeAttributes(); | ||
this.execute(); | ||
if(this.isOpen !== currentlyOpen) { | ||
var nextSibling = this.findNextSiblingDomNode(); | ||
this.rerender(this.parentDomNode,nextSibling); | ||
return true; | ||
} | ||
return this.refreshChildren(changedTiddlers); | ||
}; | ||
|
||
/* | ||
Utility: Is a value "truthy"? | ||
*/ | ||
ConditionWidget.prototype.valueIsTruthy = function(value) { | ||
// It's truthy if it's not falsy, ie, undefined, false, blank or zero. | ||
return !(/^\s*(undefined|false|null|0+|0*\.0+|0+\.0*|)\s*$/i.test(value)); | ||
}; | ||
|
||
/* | ||
Utility: Find a preceding non-text widget for an "else" widget. | ||
*/ | ||
ConditionWidget.prototype.findPrecedingConditionWidget = function() { | ||
var siblings = (this.parentWidget ? this.parentWidget.children : null); | ||
var sibling; | ||
if (siblings) { | ||
for (var i = siblings.indexOf(this)-1; i >= 0; --i) { | ||
sibling = siblings[i]; | ||
if (sibling.parseTreeNode.type == "text") continue; | ||
if (sibling.isOpen != null || sibling.list != null) return sibling; | ||
return null; | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
/* | ||
Utility: Test if another widget triggers an "else"; ie, false conditions, closed reveals, empty lists. | ||
*/ | ||
ConditionWidget.prototype.widgetTriggersElse = function(widget) { | ||
// Condition widgets | ||
if (widget.triggerElse != null) return widget.triggerElse; | ||
// Reveal widget | ||
if (widget.isOpen != null) return !widget.isOpen; | ||
// List widget | ||
if (widget.list != null) return (widget.list instanceof Array) && widget.list.length == 0; | ||
}; | ||
|
||
/* | ||
Utility: Execute as an "else" condition, computing isOpen and conditionError accordingly. | ||
*/ | ||
ConditionWidget.prototype.executeElse = function(widgetName) { | ||
this.isOpen = false; | ||
this.conditionError = null; | ||
this.triggerElse = false; | ||
var predicate = this.findPrecedingConditionWidget(); | ||
if (!predicate) { | ||
this.conditionError = (widgetName||"$else") + " widget must follow $if, $else-if, $reveal or $list."; | ||
return; | ||
} | ||
this.isOpen = this.widgetTriggersElse(predicate); | ||
}; | ||
|
||
/* | ||
Utility: Execute as an "if" condition, computing isOpen and conditionError accordingly. | ||
*/ | ||
ConditionWidget.prototype.executeIf = function(widgetName) { | ||
this.isOpen = false; | ||
this.conditionError = null; | ||
this.triggerElse = false; | ||
// Re-check our "if" condition. | ||
var value = this.getAttribute("value"); | ||
var match = this.getAttribute("match"); | ||
if (value == null) { | ||
this.conditionError = (widgetName||"$condition") + " widget requires a 'value' attribute."; | ||
return; | ||
} | ||
else if (match == null) { | ||
// Open if the value is truthy. | ||
this.isOpen = this.valueIsTruthy(value); | ||
} | ||
else { | ||
this.isOpen = (value == match); | ||
} | ||
if (this.getAttribute("not")) { | ||
this.isOpen = !this.isOpen; | ||
} | ||
this.triggerElse = !this.isOpen; | ||
}; | ||
|
||
exports.condition = ConditionWidget; | ||
|
||
})(); |
8 changes: 8 additions & 0 deletions
8
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_widgets_condition.js.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
created: 20171230024342810 | ||
description: As the $vars widget, but each attribute is interpreted as a formula. | ||
modified: 20171230024403999 | ||
module-type: widget | ||
revision: 0 | ||
tags: | ||
title: $:/plugins/ebalster/condition/widgets/condition.js | ||
type: application/javascript |
36 changes: 36 additions & 0 deletions
36
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_widgets_elif.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*\ | ||
title: $:/plugins/ebalster/condition/widgets/if.js | ||
type: application/javascript | ||
module-type: widget | ||
If-condition widget | ||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
var ConditionWidget = require("$:/plugins/ebalster/condition/widgets/condition.js").condition; | ||
|
||
var ElifWidget = function(parseTreeNode,options) { | ||
this.initialise(parseTreeNode,options); | ||
}; | ||
|
||
/* | ||
Inherit from the base widget class | ||
*/ | ||
ElifWidget.prototype = new ConditionWidget(); | ||
|
||
/* | ||
Compute the internal state of the widget | ||
*/ | ||
ElifWidget.prototype.execute = function() { | ||
this.executeElse("$else-if"); | ||
if (this.isOpen) this.executeIf("$if"); | ||
}; | ||
|
||
exports["else-if"] = ElifWidget; | ||
|
||
})(); |
8 changes: 8 additions & 0 deletions
8
Wiki-OcttKB/plugins/condition/$__plugins_ebalster_condition_widgets_elif.js.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
created: 20171230040903429 | ||
description: As the $vars widget, but each attribute is interpreted as a formula. | ||
modified: 20171230040911552 | ||
module-type: widget | ||
revision: 0 | ||
tags: | ||
title: $:/plugins/ebalster/condition/widgets/elif.js | ||
type: application/javascript |
Oops, something went wrong.