From a4930b7e68fa7993a5342c5eba9237ce0a9022df Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 30 Nov 2012 09:22:17 +0000 Subject: [PATCH] Added checkbox macro --- core/modules/macros/checkbox.js | 106 ++++++++++++++++++ editions/tw5.com/tiddlers/Introduction.tid | 1 + .../tiddlers/samples/Tasks/Compose ballad.tid | 3 + .../tiddlers/samples/Tasks/Get the Ring.tid | 3 + .../tiddlers/samples/Tasks/Go to Mordor.tid | 3 + .../samples/Tasks/Kill the Dragon.tid | 3 + .../tiddlers/samples/Tasks/Make the beds.tid | 3 + .../samples/Tasks/TaskManagementExample.tid | 17 +++ 8 files changed, 139 insertions(+) create mode 100644 core/modules/macros/checkbox.js create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/Compose ballad.tid create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/Get the Ring.tid create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/Go to Mordor.tid create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/Kill the Dragon.tid create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/Make the beds.tid create mode 100644 editions/tw5.com/tiddlers/samples/Tasks/TaskManagementExample.tid diff --git a/core/modules/macros/checkbox.js b/core/modules/macros/checkbox.js new file mode 100644 index 000000000..f450f01c5 --- /dev/null +++ b/core/modules/macros/checkbox.js @@ -0,0 +1,106 @@ +/*\ +title: $:/core/modules/macros/checkbox.js +type: application/javascript +module-type: macro + +Checkbox macro + +{{{ +<> + +<> + +<< +<> +>> +}}} + + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.info = { + name: "checkbox", + params: { + tiddler: {byName: true, type: "tiddler"}, + tag: {byPos: 0, type: "text"}, + "class": {byName: true, type: "text"} + } +}; + +exports.getValue = function() { + var tiddler = this.wiki.getTiddler(this.targetTitle); + return tiddler ? tiddler.hasTag(this.params.tag) : false; +}; + +exports.executeMacro = function() { + // Get the title of the target tiddler + if(this.hasParameter("tiddler")) { + this.targetTitle = this.params.tiddler; + } else { + this.targetTitle = this.tiddlerTitle; + } + // Checkbox attributes + var checkboxAttributes = { + type: "checkbox" + }; + if(this.getValue()) { + checkboxAttributes.checked = "true"; + } + // Label attributes + var labelAttributes = { + "class": [] + }; + if(this.hasParameter("class")) { + $tw.utils.pushTop(labelAttributes["class"],this.params["class"].split(" ")); + } + if(this.classes) { + $tw.utils.pushTop(labelAttributes["class"],this.classes); + } + // Execute content + for(var t=0; t> * Browse the list of AllTiddlers or the ShadowTiddlers * Examine the example [[bitmap images|Motovun Jack.jpg]] and [[SVG images|Motovun Jack.svg]] +* Check out the TaskManagementExample * Explore the RoadMap of TiddlyWiki5's ongoing development * Play with the new CecilyView diff --git a/editions/tw5.com/tiddlers/samples/Tasks/Compose ballad.tid b/editions/tw5.com/tiddlers/samples/Tasks/Compose ballad.tid new file mode 100644 index 000000000..7d63da9d5 --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/Compose ballad.tid @@ -0,0 +1,3 @@ +title: Compose ballad +tags: task + diff --git a/editions/tw5.com/tiddlers/samples/Tasks/Get the Ring.tid b/editions/tw5.com/tiddlers/samples/Tasks/Get the Ring.tid new file mode 100644 index 000000000..747575290 --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/Get the Ring.tid @@ -0,0 +1,3 @@ +title: Get the Ring +tags: task + diff --git a/editions/tw5.com/tiddlers/samples/Tasks/Go to Mordor.tid b/editions/tw5.com/tiddlers/samples/Tasks/Go to Mordor.tid new file mode 100644 index 000000000..fe8c2316b --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/Go to Mordor.tid @@ -0,0 +1,3 @@ +title: Go to Mordor +tags: task done + diff --git a/editions/tw5.com/tiddlers/samples/Tasks/Kill the Dragon.tid b/editions/tw5.com/tiddlers/samples/Tasks/Kill the Dragon.tid new file mode 100644 index 000000000..9834c9cdf --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/Kill the Dragon.tid @@ -0,0 +1,3 @@ +title: Kill the Dragon +tags: task + diff --git a/editions/tw5.com/tiddlers/samples/Tasks/Make the beds.tid b/editions/tw5.com/tiddlers/samples/Tasks/Make the beds.tid new file mode 100644 index 000000000..6cd13e18d --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/Make the beds.tid @@ -0,0 +1,3 @@ +title: Make the beds +tags: task + diff --git a/editions/tw5.com/tiddlers/samples/Tasks/TaskManagementExample.tid b/editions/tw5.com/tiddlers/samples/Tasks/TaskManagementExample.tid new file mode 100644 index 000000000..871d97953 --- /dev/null +++ b/editions/tw5.com/tiddlers/samples/Tasks/TaskManagementExample.tid @@ -0,0 +1,17 @@ +title: TaskManagementExample + +! Outstanding tasks + +<< + +<< <> >> + +>> + +! Completed tasks + +<< + +<< <> >> + +>>