2012-10-18 17:27:27 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/macros/view/viewers/text.js
|
|
|
|
type: application/javascript
|
2012-10-23 15:40:22 +00:00
|
|
|
module-type: fieldviewer
|
2012-10-18 17:27:27 +00:00
|
|
|
|
|
|
|
A viewer for viewing tiddler fields as plain text
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-10-28 18:18:05 +00:00
|
|
|
var TextViewer = function(viewMacro,tiddler,field,value) {
|
|
|
|
this.viewMacro = viewMacro;
|
|
|
|
this.tiddler = tiddler;
|
|
|
|
this.field = field;
|
|
|
|
this.value = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextViewer.prototype.render = function() {
|
2012-10-18 17:27:27 +00:00
|
|
|
// Get the value as a string
|
2012-10-28 18:18:05 +00:00
|
|
|
if(this.field !== "text" && this.tiddler) {
|
|
|
|
this.value = this.tiddler.getFieldString(this.field);
|
2012-10-18 17:27:27 +00:00
|
|
|
}
|
|
|
|
// Return the text
|
2012-10-28 18:18:05 +00:00
|
|
|
if(this.value === undefined || this.value === null) {
|
2012-10-18 17:27:27 +00:00
|
|
|
return $tw.Tree.Text("");
|
|
|
|
} else {
|
2012-10-28 18:18:05 +00:00
|
|
|
return $tw.Tree.Text(this.value);
|
2012-10-18 17:27:27 +00:00
|
|
|
}
|
2012-11-06 17:21:56 +00:00
|
|
|
};
|
2012-10-18 17:27:27 +00:00
|
|
|
|
2012-11-06 17:21:56 +00:00
|
|
|
exports.text = TextViewer;
|
2012-10-18 17:27:27 +00:00
|
|
|
|
|
|
|
})();
|