2013-10-12 16:05:13 +00:00
|
|
|
/*\
|
2013-11-08 08:47:00 +00:00
|
|
|
title: $:/core/modules/widgets/tiddler.js
|
2013-10-12 16:05:13 +00:00
|
|
|
type: application/javascript
|
2013-11-08 08:47:00 +00:00
|
|
|
module-type: widget
|
2013-10-12 16:05:13 +00:00
|
|
|
|
|
|
|
Tiddler widget
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2013-11-08 08:47:00 +00:00
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
2013-10-12 16:05:13 +00:00
|
|
|
|
|
|
|
var TiddlerWidget = function(parseTreeNode,options) {
|
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
|
|
|
TiddlerWidget.prototype = new Widget();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
TiddlerWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
this.parentDomNode = parent;
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
this.renderChildren(parent,nextSibling);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
TiddlerWidget.prototype.execute = function() {
|
|
|
|
// Get our parameters
|
2013-11-02 10:12:22 +00:00
|
|
|
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
2013-10-13 20:31:00 +00:00
|
|
|
// Set context variables
|
2013-10-28 23:40:45 +00:00
|
|
|
this.setVariable("currentTiddler",this.tiddlerTitle);
|
2013-10-13 21:46:45 +00:00
|
|
|
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" : "");
|
2013-10-12 16:05:13 +00:00
|
|
|
// Construct the child widgets
|
|
|
|
this.makeChildWidgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
|
|
*/
|
|
|
|
TiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
|
|
|
var changedAttributes = this.computeAttributes();
|
2013-10-30 13:36:44 +00:00
|
|
|
if(changedAttributes.tiddler) {
|
2013-10-12 16:05:13 +00:00
|
|
|
this.refreshSelf();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.refreshChildren(changedTiddlers);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.tiddler = TiddlerWidget;
|
|
|
|
|
|
|
|
})();
|