mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-26 10:00:34 +00:00
be06257430
Belatedly realised that the design would be clearer without these two separate concepts being conflated into a single widget. As a result of this change, any other widget or template that generates transclude widgets has needed adjustment.
116 lines
2.9 KiB
JavaScript
116 lines
2.9 KiB
JavaScript
/*\
|
|
title: $:/core/modules/widgets/info.js
|
|
type: application/javascript
|
|
module-type: widget
|
|
|
|
Implements the info widget that displays various information about a specified tiddler.
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var InfoWidget = function(renderer) {
|
|
// Save state
|
|
this.renderer = renderer;
|
|
// Generate child nodes
|
|
this.generate();
|
|
};
|
|
|
|
InfoWidget.types = {};
|
|
|
|
InfoWidget.types.changecount = function(options) {
|
|
var text = options.wiki.getChangeCount(options.widget.renderer.tiddlerTitle);
|
|
return [{type: "text", text: text}];
|
|
};
|
|
|
|
InfoWidget.types.currentfield = function(options) {
|
|
var fieldName = options.widget.renderer.renderTree.getContextVariable(options.widget.renderer,"field","text");
|
|
return [{type: "text", text: fieldName}];
|
|
};
|
|
|
|
var FIELD_DESCRIPTION_PREFIX = "$:/docs/fields/";
|
|
|
|
InfoWidget.types.currentfielddescription = function(options) {
|
|
var fieldName = options.widget.renderer.renderTree.getContextVariable(options.widget.renderer,"field","text"),
|
|
descriptionTitle = FIELD_DESCRIPTION_PREFIX + fieldName;
|
|
return [{
|
|
type: "element",
|
|
tag: "$transclude",
|
|
isBlock: false,
|
|
attributes: {
|
|
title: {type: "string", value: descriptionTitle}
|
|
}
|
|
}];
|
|
};
|
|
|
|
var MODULE_TYPE_DESCRIPTION_PREFIX = "$:/docs/moduletypes/";
|
|
|
|
/*
|
|
Return a list of all the currently loaded modules grouped by type
|
|
*/
|
|
InfoWidget.types.modules = function(options) {
|
|
var output = [],
|
|
types = [];
|
|
// Collect and sort the module types
|
|
$tw.utils.each($tw.modules.types,function(moduleInfo,type) {
|
|
types.push(type);
|
|
});
|
|
types.sort();
|
|
// Output the module types
|
|
$tw.utils.each(types,function(moduleType) {
|
|
// Heading
|
|
output.push({type: "element", tag: "h2", children: [
|
|
{type: "text", text: moduleType}
|
|
]})
|
|
// Description
|
|
output.push({
|
|
type: "element",
|
|
tag: "$transclude",
|
|
isBlock: false,
|
|
attributes: {
|
|
title: {type: "string", value: MODULE_TYPE_DESCRIPTION_PREFIX + moduleType}
|
|
}
|
|
});
|
|
// List each module
|
|
var list = {type: "element", tag: "ul", children: []},
|
|
modules = [];
|
|
$tw.utils.each($tw.modules.types[moduleType],function(moduleInfo,moduleName) {
|
|
var listItem = {type: "element", tag: "li", children: [
|
|
{type: "element", tag: "$link", attributes: {
|
|
to: {type: "string", value: moduleName}
|
|
}, children: [
|
|
{type: "text", text: moduleName}
|
|
]}
|
|
]}
|
|
list.children.push(listItem);
|
|
});
|
|
output.push(list);
|
|
});
|
|
return output;
|
|
};
|
|
|
|
InfoWidget.prototype.generate = function() {
|
|
// Get attributes
|
|
this.type = this.renderer.getAttribute("type","changecount").toLowerCase();
|
|
// Get the appropriate value for the current tiddler
|
|
var value = [],
|
|
fn = InfoWidget.types[this.type];
|
|
if(fn) {
|
|
value = fn({
|
|
wiki: this.renderer.renderTree.wiki,
|
|
widget: this
|
|
});
|
|
}
|
|
// Set the element
|
|
this.tag = "span";
|
|
this.attributes = {};
|
|
this.children = this.renderer.renderTree.createRenderers(this.renderer,value);
|
|
};
|
|
|
|
exports.info = InfoWidget;
|
|
|
|
})();
|