diff --git a/js/App.js b/js/App.js index 930acd42d..bbc466e4e 100644 --- a/js/App.js +++ b/js/App.js @@ -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); diff --git a/js/macros/edit.js b/js/macros/edit.js new file mode 100644 index 000000000..b18e3fe49 --- /dev/null +++ b/js/macros/edit.js @@ -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)])]; + } +}; + +})(); + diff --git a/tiddlywiki5/shadows/StoryTiddlers.tid b/tiddlywiki5/shadows/StoryTiddlers.tid index 09e17e160..968a773a3 100644 --- a/tiddlywiki5/shadows/StoryTiddlers.tid +++ b/tiddlywiki5/shadows/StoryTiddlers.tid @@ -3,6 +3,7 @@ type: application/json { "tiddlers": [ + {"title": "DraftTiddler", "template": "EditTemplate"}, {"title": "HelloThere", "template": "SimpleTemplate"}, {"title": "Introduction", "template": "SimpleTemplate"}, {"title": "NewWikiTextFeatures", "template": "SimpleTemplate"} diff --git a/tiddlywiki5/shadows/css/styles.css b/tiddlywiki5/shadows/css/styles.css index 741c1eeca..9b240813e 100644 --- a/tiddlywiki5/shadows/css/styles.css +++ b/tiddlywiki5/shadows/css/styles.css @@ -10,6 +10,11 @@ body { .tiddlerMissing .title { font-style: italic; + font-weight: normal; +} + +.tw-edit-field { + border: 1px dotted #888; } img { diff --git a/tiddlywiki5/shadows/templates/EditTemplate.tid b/tiddlywiki5/shadows/templates/EditTemplate.tid new file mode 100644 index 000000000..c429af4f8 --- /dev/null +++ b/tiddlywiki5/shadows/templates/EditTemplate.tid @@ -0,0 +1,7 @@ +title: EditTemplate +modifier: JeremyRuston + +{{title{ +<>}}} +{{body{ +<>}}} \ No newline at end of file diff --git a/tiddlywiki5/shadows/templates/SimpleTemplate.tid b/tiddlywiki5/shadows/templates/SimpleTemplate.tid index 6d9674fe0..1a8d25f2d 100644 --- a/tiddlywiki5/shadows/templates/SimpleTemplate.tid +++ b/tiddlywiki5/shadows/templates/SimpleTemplate.tid @@ -6,6 +6,4 @@ modifier: JeremyRuston {{small{ <> <>}}} {{body{ -<>}}} -<> -<> \ No newline at end of file +<>}}} \ No newline at end of file diff --git a/tiddlywiki5/tiddlers/DraftTiddler.tid b/tiddlywiki5/tiddlers/DraftTiddler.tid new file mode 100644 index 000000000..8f6db4a7d --- /dev/null +++ b/tiddlywiki5/tiddlers/DraftTiddler.tid @@ -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 <>.