mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-23 06:20:01 +00:00
First version of the edit macro
This commit is contained in:
parent
ddf4b15a3e
commit
1dd6e43a6f
@ -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
Normal file
47
js/macros/edit.js
Normal file
@ -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)])];
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -3,6 +3,7 @@ type: application/json
|
||||
|
||||
{
|
||||
"tiddlers": [
|
||||
{"title": "DraftTiddler", "template": "EditTemplate"},
|
||||
{"title": "HelloThere", "template": "SimpleTemplate"},
|
||||
{"title": "Introduction", "template": "SimpleTemplate"},
|
||||
{"title": "NewWikiTextFeatures", "template": "SimpleTemplate"}
|
||||
|
@ -10,6 +10,11 @@ body {
|
||||
|
||||
.tiddlerMissing .title {
|
||||
font-style: italic;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.tw-edit-field {
|
||||
border: 1px dotted #888;
|
||||
}
|
||||
|
||||
img {
|
||||
|
7
tiddlywiki5/shadows/templates/EditTemplate.tid
Normal file
7
tiddlywiki5/shadows/templates/EditTemplate.tid
Normal file
@ -0,0 +1,7 @@
|
||||
title: EditTemplate
|
||||
modifier: JeremyRuston
|
||||
|
||||
{{title{
|
||||
<<edit draft.title>>}}}
|
||||
{{body{
|
||||
<<edit text>>}}}
|
@ -6,6 +6,4 @@ modifier: JeremyRuston
|
||||
{{small{
|
||||
<<view modifier link>> <<view modified date>>}}}
|
||||
{{body{
|
||||
<<view text wikified>>}}}
|
||||
<<ianfo parsetree>>
|
||||
<<ianfo compiled>>
|
||||
<<view text wikified>>}}}
|
4
tiddlywiki5/tiddlers/DraftTiddler.tid
Normal file
4
tiddlywiki5/tiddlers/DraftTiddler.tid
Normal file
@ -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>>.
|
Loading…
x
Reference in New Issue
Block a user