2013-03-10 19:24:22 +00:00
|
|
|
/*\
|
2013-05-31 12:23:25 +00:00
|
|
|
title: $:/core/modules/widgets/info.js
|
2013-03-10 19:24:22 +00:00
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2013-08-09 15:45:40 +00:00
|
|
|
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) {
|
2013-08-09 20:57:05 +00:00
|
|
|
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: {
|
2013-08-24 15:45:45 +00:00
|
|
|
title: {type: "string", value: descriptionTitle}
|
2013-08-09 20:57:05 +00:00
|
|
|
}
|
|
|
|
}];
|
2013-08-09 15:45:40 +00:00
|
|
|
};
|
|
|
|
|
2013-08-09 20:57:05 +00:00
|
|
|
var MODULE_TYPE_DESCRIPTION_PREFIX = "$:/docs/moduletypes/";
|
|
|
|
|
2013-08-09 15:45:40 +00:00
|
|
|
/*
|
|
|
|
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
|
2013-08-09 20:57:05 +00:00
|
|
|
output.push({type: "element", tag: "h2", children: [
|
2013-08-09 15:45:40 +00:00
|
|
|
{type: "text", text: moduleType}
|
|
|
|
]})
|
2013-08-09 20:57:05 +00:00
|
|
|
// Description
|
|
|
|
output.push({
|
|
|
|
type: "element",
|
|
|
|
tag: "$transclude",
|
|
|
|
isBlock: false,
|
|
|
|
attributes: {
|
2013-08-24 15:45:45 +00:00
|
|
|
title: {type: "string", value: MODULE_TYPE_DESCRIPTION_PREFIX + moduleType}
|
2013-08-09 20:57:05 +00:00
|
|
|
}
|
|
|
|
});
|
2013-08-09 15:45:40 +00:00
|
|
|
// 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;
|
2013-03-10 19:24:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InfoWidget.prototype.generate = function() {
|
|
|
|
// Get attributes
|
2013-08-09 15:45:40 +00:00
|
|
|
this.type = this.renderer.getAttribute("type","changecount").toLowerCase();
|
2013-03-10 19:24:22 +00:00
|
|
|
// Get the appropriate value for the current tiddler
|
2013-08-21 22:09:40 +00:00
|
|
|
var value = [],
|
2013-03-10 19:24:22 +00:00
|
|
|
fn = InfoWidget.types[this.type];
|
|
|
|
if(fn) {
|
|
|
|
value = fn({
|
|
|
|
wiki: this.renderer.renderTree.wiki,
|
2013-06-02 22:20:24 +00:00
|
|
|
widget: this
|
2013-03-10 19:24:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Set the element
|
|
|
|
this.tag = "span";
|
|
|
|
this.attributes = {};
|
2013-08-09 15:45:40 +00:00
|
|
|
this.children = this.renderer.renderTree.createRenderers(this.renderer,value);
|
2013-03-10 19:24:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.info = InfoWidget;
|
|
|
|
|
|
|
|
})();
|