2012-03-29 14:32:36 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/edit.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Renderer = require("../Renderer.js").Renderer,
|
|
|
|
Dependencies = require("../Dependencies.js").Dependencies,
|
|
|
|
utils = require("../Utils.js");
|
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "edit",
|
|
|
|
params: {
|
|
|
|
field: {byPos: 0, type: "text"}
|
|
|
|
},
|
|
|
|
execute: function() {
|
|
|
|
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
|
|
|
field = this.hasParameter("field") ? this.params.field : "title",
|
|
|
|
value;
|
|
|
|
if(tiddler) {
|
|
|
|
value = tiddler[field];
|
|
|
|
} else {
|
|
|
|
switch(field) {
|
|
|
|
case "text":
|
|
|
|
value = "Type the text for the tiddler '" + this.tiddlerTitle + "'";
|
|
|
|
break;
|
|
|
|
case "title":
|
|
|
|
value = this.tiddlerTitle;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-29 16:02:05 +00:00
|
|
|
var type = "div";
|
|
|
|
switch(field) {
|
|
|
|
case "text":
|
|
|
|
type = "pre";
|
|
|
|
break;
|
|
|
|
}
|
2012-03-29 14:32:36 +00:00
|
|
|
var attributes = {
|
|
|
|
"contenteditable": true,
|
|
|
|
"class": ["tw-edit-field"]
|
2012-03-29 14:33:47 +00:00
|
|
|
};
|
2012-03-29 16:02:05 +00:00
|
|
|
return [Renderer.ElementNode(type,attributes,[Renderer.TextNode(value)])];
|
2012-03-29 14:32:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|