From c23f6af4b5c59f4d09dd8d6704e1939bb9d5b2d3 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 1 Aug 2014 17:48:26 +0100 Subject: [PATCH] Add CSS classes for each tag --- core/modules/widgets/tiddler.js | 17 +++++++++++++++++ core/ui/ViewTemplate.tid | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/modules/widgets/tiddler.js b/core/modules/widgets/tiddler.js index b7521fd34..a8b10e85f 100755 --- a/core/modules/widgets/tiddler.js +++ b/core/modules/widgets/tiddler.js @@ -44,10 +44,27 @@ TiddlerWidget.prototype.execute = function() { this.setVariable("missingTiddlerClass",(this.wiki.tiddlerExists(this.tiddlerTitle) || this.wiki.isShadowTiddler(this.tiddlerTitle)) ? "tw-tiddler-exists" : "tw-tiddler-missing"); this.setVariable("shadowTiddlerClass",this.wiki.isShadowTiddler(this.tiddlerTitle) ? "tw-tiddler-shadow" : ""); this.setVariable("systemTiddlerClass",this.wiki.isSystemTiddler(this.tiddlerTitle) ? "tw-tiddler-system" : ""); + this.setVariable("tiddlerTagClasses",this.getTagClasses()) // Construct the child widgets this.makeChildWidgets(); }; +/* +Create a string of CSS classes derived from the tags of the current tiddler +*/ +TiddlerWidget.prototype.getTagClasses = function() { + var tiddler = this.wiki.getTiddler(this.tiddlerTitle); + if(tiddler) { + var tags = []; + $tw.utils.each(tiddler.fields.tags,function(tag) { + tags.push("tw-tag-" + encodeURIComponent(tag)); + }); + return tags.join(" "); + } else { + return ""; + } +}; + /* Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering */ diff --git a/core/ui/ViewTemplate.tid b/core/ui/ViewTemplate.tid index a18a0ab62..baf83bb4d 100644 --- a/core/ui/ViewTemplate.tid +++ b/core/ui/ViewTemplate.tid @@ -1,7 +1,7 @@ title: $:/core/ui/ViewTemplate \define frame-classes() -tw-tiddler-frame tw-tiddler-view-frame $(missingTiddlerClass)$ $(shadowTiddlerClass)$ $(systemTiddlerClass)$ +tw-tiddler-frame tw-tiddler-view-frame $(missingTiddlerClass)$ $(shadowTiddlerClass)$ $(systemTiddlerClass)$ $(tiddlerTagClasses)$ \end <$set name="storyTiddler" value=<>><$set name="tiddlerInfoState" value=<>><$tiddler tiddler=<>>
>><$list filter="[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!has[draft.of]]" variable="listItem"><$transclude tiddler=<>/>