/*\ title: $:/core/modules/widgets/fields.js type: application/javascript module-type: widget Fields widget \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; var Widget = require("$:/core/modules/widgets/widget.js").widget; var FieldsWidget = function(parseTreeNode,options) { this.initialise(parseTreeNode,options); }; /* Inherit from the base widget class */ FieldsWidget.prototype = new Widget(); /* Render this widget into the DOM */ FieldsWidget.prototype.render = function(parent,nextSibling) { this.parentDomNode = parent; this.computeAttributes(); this.execute(); var textNode = this.document.createTextNode(this.text); parent.insertBefore(textNode,nextSibling); this.domNodes.push(textNode); }; /* Compute the internal state of the widget */ FieldsWidget.prototype.execute = function() { // Get parameters from our attributes this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); this.template = this.getAttribute("template"); this.exclude = this.getAttribute("exclude"); this.stripTitlePrefix = this.getAttribute("stripTitlePrefix","no") === "yes"; // Get the value to display var tiddler = this.wiki.getTiddler(this.tiddlerTitle); // Get the exclusion list var exclude; if(this.exclude) { exclude = this.exclude.split(" "); } else { exclude = ["text"]; } // Compose the template var text = []; if(this.template && tiddler) { var fields = []; for(var fieldName in tiddler.fields) { if(exclude.indexOf(fieldName) === -1) { fields.push(fieldName); } } fields.sort(); for(var f=0; f