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",
|
|
|
|
params: {
|
2012-07-13 12:02:14 +00:00
|
|
|
tiddler: {byName: true, type: "tiddler"},
|
2012-10-17 18:10:18 +00:00
|
|
|
field: {byPos: 0, type: "text"},
|
2012-10-17 17:03:17 +00:00
|
|
|
type: {byName: true, type: "text"},
|
2012-10-17 18:10:18 +00:00
|
|
|
"default": {byName: true, type: "text"},
|
|
|
|
requireFocus: {byName: true, type: "text"}
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-13 10:26:34 +00:00
|
|
|
exports.evaluateDependencies = function() {
|
|
|
|
var dependencies = new $tw.Dependencies();
|
|
|
|
if(!this.srcParams.tiddler) {
|
|
|
|
dependencies.dependentOnContextTiddler = true;
|
|
|
|
}
|
|
|
|
for(var m in this.info.params) {
|
|
|
|
var paramInfo = this.info.params[m];
|
|
|
|
if(m in this.srcParams && paramInfo.type === "tiddler") {
|
|
|
|
if(typeof this.srcParams[m] === "function") {
|
|
|
|
dependencies.dependentAll = true;
|
|
|
|
} else {
|
|
|
|
dependencies.addDependency(this.srcParams[m],!paramInfo.skinny);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dependencies;
|
|
|
|
};
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
exports.executeMacro = function() {
|
|
|
|
// Get the tiddler being editted
|
2012-07-13 10:26:34 +00:00
|
|
|
this.editField = this.hasParameter("field") ? this.params.field : "text";
|
|
|
|
this.editTiddler = this.hasParameter("tiddler") ? this.params.tiddler : this.tiddlerTitle;
|
|
|
|
var tiddler = this.wiki.getTiddler(this.editTiddler),
|
2012-04-30 11:23:03 +00:00
|
|
|
Editor;
|
|
|
|
// Figure out which editor to use
|
2012-08-03 14:09:48 +00:00
|
|
|
// TODO: Tiddler field modules should be able to specify a field type from which the editor is derived
|
2012-07-13 10:26:34 +00:00
|
|
|
if(this.editField === "text" && tiddler && tiddler.fields.type) {
|
2012-04-30 11:23:03 +00:00
|
|
|
Editor = this.wiki.macros.edit.editors[tiddler.fields.type];
|
|
|
|
}
|
|
|
|
if(!Editor) {
|
2012-11-18 15:22:13 +00:00
|
|
|
Editor = this.wiki.macros.edit.editors["text/vnd.tiddlywiki"];
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
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)) {
|
2012-07-11 14:52:15 +00:00
|
|
|
if(this.editor.refreshInDom) {
|
|
|
|
this.editor.refreshInDom();
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|