2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/macros/edit/edit.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: macro
|
|
|
|
|
2012-05-19 17:23:14 +00:00
|
|
|
Edit macro for editting fields and tiddlers
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
2012-05-04 17:49:04 +00:00
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "edit",
|
|
|
|
dependentOnContextTiddler: true,
|
|
|
|
params: {
|
|
|
|
field: {byPos: 0, type: "text"}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.executeMacro = function() {
|
|
|
|
// Get the tiddler being editted
|
|
|
|
var field = this.hasParameter("field") ? this.params.field : "text",
|
|
|
|
tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
|
|
|
Editor;
|
|
|
|
// Figure out which editor to use
|
|
|
|
// TODO: Tiddler field plugins should be able to specify a field type from which the editor is derived
|
|
|
|
if(field === "text" && tiddler.fields.type) {
|
|
|
|
Editor = this.wiki.macros.edit.editors[tiddler.fields.type];
|
|
|
|
}
|
|
|
|
if(!Editor) {
|
|
|
|
Editor = this.wiki.macros.edit.editors["text/x-tiddlywiki"];
|
|
|
|
}
|
|
|
|
this.editor = new Editor(this);
|
|
|
|
// Call the editor to generate the child nodes
|
2012-06-09 17:36:32 +00:00
|
|
|
var child = this.editor.getChild();
|
|
|
|
child.execute(this.parents,this.tiddlerTitle);
|
|
|
|
return child;
|
2012-04-30 11:23:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.postRenderInDom = function() {
|
|
|
|
if(this.editor.postRenderInDom) {
|
|
|
|
this.editor.postRenderInDom();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.refreshInDom = function(changes) {
|
|
|
|
var t;
|
|
|
|
// Only refresh if a dependency is triggered
|
|
|
|
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
|
|
|
|
// Only refresh if the editor lets us
|
|
|
|
if(this.editor.isRefreshable()) {
|
2012-06-09 17:36:32 +00:00
|
|
|
// Remove the previous child
|
|
|
|
var parent = this.child.domNode.parentNode,
|
|
|
|
nextSibling = this.child.domNode.nextSibling;
|
|
|
|
parent.removeChild(this.child.domNode);
|
|
|
|
// Execute the macro
|
2012-04-30 11:23:03 +00:00
|
|
|
this.execute(this.parents,this.tiddlerTitle);
|
|
|
|
// Render to the DOM
|
2012-06-09 17:36:32 +00:00
|
|
|
this.child.renderInDom(parent,nextSibling);
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Refresh any children
|
2012-06-09 17:36:32 +00:00
|
|
|
this.child.refreshInDom(changes);
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|