1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 02:27:19 +00:00

Add wiki.setText() method

This commit is contained in:
Jermolene 2014-05-31 18:37:27 +01:00
parent 4d70d5780e
commit f999b2e931

View File

@ -55,15 +55,19 @@ exports.getTextReference = function(textRef,defaultText,currTiddlerTitle) {
exports.setTextReference = function(textRef,value,currTiddlerTitle) { exports.setTextReference = function(textRef,value,currTiddlerTitle) {
var tr = $tw.utils.parseTextReference(textRef), var tr = $tw.utils.parseTextReference(textRef),
title = tr.title || currTiddlerTitle; title = tr.title || currTiddlerTitle;
this.setText(title,tr.field,tr.index,value);
};
exports.setText = function(title,field,index,value) {
// Check if it is a reference to a tiddler field // Check if it is a reference to a tiddler field
if(tr.index) { if(index) {
var data = this.getTiddlerData(title,Object.create(null)); var data = this.getTiddlerData(title,Object.create(null));
data[tr.index] = value; data[index] = value;
this.setTiddlerData(title,data,this.getModificationFields()); this.setTiddlerData(title,data,this.getModificationFields());
} else { } else {
var tiddler = this.getTiddler(title), var tiddler = this.getTiddler(title),
fields = {title: title}; fields = {title: title};
fields[tr.field || "text"] = value; fields[field || "text"] = value;
this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields()));
} }
}; };