mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-10 15:53:58 +00:00
Ensure that the edit widget refreshes whenever the editor type changes
This commit is contained in:
parent
131874e154
commit
c0a26d2849
@ -30,20 +30,25 @@ EditWidget.prototype.generate = function() {
|
|||||||
this.fieldName = this.renderer.getAttribute("field",this.renderer.renderTree.getContextVariable(this.renderer,"field","text"));
|
this.fieldName = this.renderer.getAttribute("field",this.renderer.renderTree.getContextVariable(this.renderer,"field","text"));
|
||||||
// Choose the editor to use
|
// Choose the editor to use
|
||||||
// TODO: Tiddler field modules should be able to specify a field type from which the editor is derived
|
// TODO: Tiddler field modules should be able to specify a field type from which the editor is derived
|
||||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle),
|
this.editorName = this.chooseEditor();
|
||||||
Editor;
|
var Editor = this.editors[this.editorName];
|
||||||
if(this.fieldName === "text" && tiddler && tiddler.fields.type) {
|
|
||||||
Editor = this.editors[tiddler.fields.type];
|
|
||||||
}
|
|
||||||
if(!Editor) {
|
|
||||||
Editor = this.editors["text/vnd.tiddlywiki"];
|
|
||||||
}
|
|
||||||
// Instantiate the editor
|
// Instantiate the editor
|
||||||
this.editor = new Editor(this,this.tiddlerTitle,this.fieldName);
|
this.editor = new Editor(this,this.tiddlerTitle,this.fieldName);
|
||||||
// Ask the editor to create the widget element
|
// Ask the editor to create the widget element
|
||||||
this.editor.render();
|
this.editor.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return the name of the editor that should handle this tiddler field
|
||||||
|
*/
|
||||||
|
EditWidget.prototype.chooseEditor = function() {
|
||||||
|
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle);
|
||||||
|
if(this.fieldName === "text" && tiddler && tiddler.fields.type && this.editors[tiddler.fields.type]) {
|
||||||
|
return tiddler.fields.type;
|
||||||
|
}
|
||||||
|
return "text/vnd.tiddlywiki";
|
||||||
|
};
|
||||||
|
|
||||||
EditWidget.prototype.postRenderInDom = function() {
|
EditWidget.prototype.postRenderInDom = function() {
|
||||||
if(this.editor && this.editor.postRenderInDom) {
|
if(this.editor && this.editor.postRenderInDom) {
|
||||||
this.editor.postRenderInDom();
|
this.editor.postRenderInDom();
|
||||||
@ -52,7 +57,7 @@ EditWidget.prototype.postRenderInDom = function() {
|
|||||||
|
|
||||||
EditWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
EditWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// We'll completely regenerate ourselves if any of our attributes have changed
|
// We'll completely regenerate ourselves if any of our attributes have changed
|
||||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.format) {
|
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.format || this.chooseEditor() !== this.editorName) {
|
||||||
// Regenerate and rerender the widget and replace the existing DOM node
|
// Regenerate and rerender the widget and replace the existing DOM node
|
||||||
this.generate();
|
this.generate();
|
||||||
var oldDomNode = this.renderer.domNode,
|
var oldDomNode = this.renderer.domNode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user