mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-04-27 09:11:30 +00:00
Added tags and color macros
Which enables us to do nice colour coded tags. Soon they'll have a drop down on them too
This commit is contained in:
41
core/modules/macros/color.js
Normal file
41
core/modules/macros/color.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/color.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Color macro.
|
||||
|
||||
Applies the specified colour to its content. By default, the colour value is obtained from the `color` field of the current tiddler
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "color",
|
||||
params: {
|
||||
"default": {byName: "default", type: "text"},
|
||||
}
|
||||
};
|
||||
|
||||
exports.executeMacro = function() {
|
||||
var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
||||
attributes = {
|
||||
style: {
|
||||
"background-color": (tiddler && tiddler.fields.color) || this.params["default"]
|
||||
}
|
||||
};
|
||||
if(this.classes) {
|
||||
attributes["class"] = this.classes.slice(0);
|
||||
}
|
||||
for(var t=0; t<this.content.length; t++) {
|
||||
this.content[t].execute(this.parents,this.tiddlerTitle);
|
||||
}
|
||||
return $tw.Tree.Element("span",attributes,this.content);
|
||||
};
|
||||
|
||||
|
||||
})();
|
||||
45
core/modules/macros/tags.js
Normal file
45
core/modules/macros/tags.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/tags.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Implements the tags macro.
|
||||
|
||||
{{{
|
||||
<<tags template:MyTagTemplate>>
|
||||
}}}
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "tags",
|
||||
dependentOnContextTiddler: true,
|
||||
params: {
|
||||
template: {byName: true, type: "tiddler"},
|
||||
filter: {byName: true, type: "filter"}
|
||||
}
|
||||
};
|
||||
|
||||
exports.executeMacro = function() {
|
||||
var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
||||
child = $tw.Tree.Element("div",{"class":"tw-tags-wrapper"},[]);
|
||||
if(tiddler && tiddler.fields.tags) {
|
||||
for(var t=0; t<tiddler.fields.tags.length; t++) {
|
||||
var tag = tiddler.fields.tags[t];
|
||||
child.children.push($tw.Tree.Macro("tiddler",{
|
||||
srcParams: {target: tag,template: this.params.template},
|
||||
wiki: this.wiki,
|
||||
isBlock: false
|
||||
}));
|
||||
}
|
||||
}
|
||||
child.execute(this.parents,this.tiddlerTitle);
|
||||
return child;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -124,7 +124,7 @@ exports.executeMacro = function() {
|
||||
attributes["class"].push("tw-tiddler-missing");
|
||||
}
|
||||
// Return the children
|
||||
return $tw.Tree.Element("div",attributes,childrenClone);
|
||||
return $tw.Tree.Element(this.isBlock ? "div" : "span",attributes,childrenClone);
|
||||
};
|
||||
|
||||
exports.refreshInDom = function(changes) {
|
||||
|
||||
Reference in New Issue
Block a user