From a43d7aed9530cafe29716583f239d47e1246df4b Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 3 Jan 2013 22:36:51 +0000 Subject: [PATCH] Added setstyle widget and use it to colour the tag buttons --- core/modules/widgets/setstyle.js | 40 ++++++++++++++++++++++++++++++++ core/templates/TagTemplate.tid | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 core/modules/widgets/setstyle.js diff --git a/core/modules/widgets/setstyle.js b/core/modules/widgets/setstyle.js new file mode 100644 index 000000000..bd792957f --- /dev/null +++ b/core/modules/widgets/setstyle.js @@ -0,0 +1,40 @@ +/*\ +title: $:/core/modules/widget/setstyle.js +type: application/javascript +module-type: widget + +Implements the setstyle widget. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var SetStyleWidget = function(renderer) { + // Save state + this.renderer = renderer; + // Generate child nodes + this.generate(); +}; + +SetStyleWidget.prototype.generate = function() { + // Get the parameters from the attributes + this.name = this.renderer.getAttribute("name"); + this.value = this.renderer.getAttribute("value"); + this["class"] = this.renderer.getAttribute("class"); + // Set up the element + this.tag = this.renderer.parseTreeNode.isBlock ? "div" : "span"; + this.attributes = { + style: this.name + ":" + this.value + }; + if(this["class"]) { + this.attributes["class"] = this["class"]; + } + this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children); +}; + +exports.setstyle = SetStyleWidget; + +})(); diff --git a/core/templates/TagTemplate.tid b/core/templates/TagTemplate.tid index 267c7e8a2..fed966802 100644 --- a/core/templates/TagTemplate.tid +++ b/core/templates/TagTemplate.tid @@ -1,6 +1,6 @@ title: $:/templates/TagTemplate -<$button popup="tagpopup" qualifyTiddlerTitles="yes" class="btn-invisible">@@.label <$view field="title" format="text" />@@ +<$button popup="tagpopup" qualifyTiddlerTitles="yes" class="btn-invisible"><$setstyle name="background-color" value={{!!color}} class="label"><$view field="title" format="text" /> <$reveal state="tagpopup" type="popup" position="below" qualifyTiddlerTitles="yes" >
@@.dropdown-menu