First version of the edit macro

print-window-tiddler
Jeremy Ruston 2012-03-29 15:32:36 +01:00
rodzic ddf4b15a3e
commit 1dd6e43a6f
7 zmienionych plików z 66 dodań i 3 usunięć

Wyświetl plik

@ -84,6 +84,7 @@ var App = function() {
// Bit of a hack to set up the macros
this.store.installMacro(require("./macros/chooser.js").macro);
this.store.installMacro(require("./macros/echo.js").macro);
this.store.installMacro(require("./macros/edit.js").macro);
this.store.installMacro(require("./macros/image.js").macro);
this.store.installMacro(require("./macros/link.js").macro);
this.store.installMacro(require("./macros/list.js").macro);

47
js/macros/edit.js 100644
Wyświetl plik

@ -0,0 +1,47 @@
/*\
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;
}
}
var attributes = {
"contenteditable": true,
"class": ["tw-edit-field"]
}
return [Renderer.ElementNode("div",attributes,[Renderer.TextNode(value)])];
}
};
})();

Wyświetl plik

@ -3,6 +3,7 @@ type: application/json
{
"tiddlers": [
{"title": "DraftTiddler", "template": "EditTemplate"},
{"title": "HelloThere", "template": "SimpleTemplate"},
{"title": "Introduction", "template": "SimpleTemplate"},
{"title": "NewWikiTextFeatures", "template": "SimpleTemplate"}

Wyświetl plik

@ -10,6 +10,11 @@ body {
.tiddlerMissing .title {
font-style: italic;
font-weight: normal;
}
.tw-edit-field {
border: 1px dotted #888;
}
img {

Wyświetl plik

@ -0,0 +1,7 @@
title: EditTemplate
modifier: JeremyRuston
{{title{
<<edit draft.title>>}}}
{{body{
<<edit text>>}}}

Wyświetl plik

@ -6,6 +6,4 @@ modifier: JeremyRuston
{{small{
<<view modifier link>> <<view modified date>>}}}
{{body{
<<view text wikified>>}}}
<<ianfo parsetree>>
<<ianfo compiled>>
<<view text wikified>>}}}

Wyświetl plik

@ -0,0 +1,4 @@
title: DraftTiddler
draft.title: New Tiddler
This is a sample draft tiddler. It is a draft of the tiddler titled in the `draft.title` field, in this case <<view draft.title>>.