2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/treenodes/text.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: treenode
|
|
|
|
|
|
|
|
Text nodes
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Node = require("./node.js").Node;
|
|
|
|
|
|
|
|
var Text = function(text) {
|
|
|
|
if(this instanceof Text) {
|
|
|
|
this.text = text;
|
|
|
|
} else {
|
|
|
|
return new Text(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Text.prototype = new Node();
|
|
|
|
Text.prototype.constructor = Text;
|
|
|
|
|
|
|
|
Text.prototype.render = function(type) {
|
|
|
|
return type === "text/html" ? $tw.utils.htmlEncode(this.text) : this.text;
|
|
|
|
};
|
|
|
|
|
2012-06-13 09:41:36 +00:00
|
|
|
Text.prototype.renderInDom = function(parentDomNode,insertBefore) {
|
2012-04-30 11:23:03 +00:00
|
|
|
this.domNode = document.createTextNode(this.text);
|
2012-06-13 09:41:36 +00:00
|
|
|
if(insertBefore) {
|
|
|
|
parentDomNode.insertBefore(this.domNode,insertBefore);
|
|
|
|
} else {
|
|
|
|
parentDomNode.appendChild(this.domNode);
|
|
|
|
}
|
2012-04-30 11:23:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.Text = Text;
|
|
|
|
|
|
|
|
})();
|