mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-02 00:40:47 +00:00
Give the edit-text widget some extensibility hooks
So that the upcoming CodeMirror plugin can do its stuff
This commit is contained in:
parent
a5f5f1bd9c
commit
8a709a0b00
@ -61,6 +61,9 @@ EditTextWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
// Insert the element into the DOM
|
// Insert the element into the DOM
|
||||||
parent.insertBefore(domNode,nextSibling);
|
parent.insertBefore(domNode,nextSibling);
|
||||||
this.domNodes.push(domNode);
|
this.domNodes.push(domNode);
|
||||||
|
if(this.postRender) {
|
||||||
|
this.postRender();
|
||||||
|
}
|
||||||
// Fix height
|
// Fix height
|
||||||
this.fixHeight();
|
this.fixHeight();
|
||||||
};
|
};
|
||||||
@ -141,24 +144,39 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
|||||||
EditTextWidget.prototype.refresh = function(changedTiddlers) {
|
EditTextWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
var changedAttributes = this.computeAttributes();
|
var changedAttributes = this.computeAttributes();
|
||||||
// Completely rerender if any of our attributes have changed
|
// Completely rerender if any of our attributes have changed
|
||||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index) {
|
if(changedAttributes.title || changedAttributes.field || changedAttributes.index) {
|
||||||
this.refreshSelf();
|
this.refreshSelf();
|
||||||
return true;
|
return true;
|
||||||
} else if(changedTiddlers[this.editTitle]){
|
} else if(changedTiddlers[this.editTitle]) {
|
||||||
// Replace the edit value if the tiddler we're editing has changed
|
this.updateEditor(this.getEditInfo().value);
|
||||||
var domNode = this.domNodes[0];
|
return true;
|
||||||
if(!domNode.isTiddlyWikiFakeDom) {
|
|
||||||
if(this.document.activeElement !== domNode) {
|
|
||||||
var editInfo = this.getEditInfo();
|
|
||||||
domNode.value = editInfo.value;
|
|
||||||
}
|
|
||||||
// Fix the height if needed
|
|
||||||
this.fixHeight();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Update the editor with new text. This method is separate from updateEditorDomNode()
|
||||||
|
so that subclasses can override updateEditor() and still use updateEditorDomNode()
|
||||||
|
*/
|
||||||
|
EditTextWidget.prototype.updateEditor = function(text) {
|
||||||
|
this.updateEditorDomNode(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Update the editor dom node with new text
|
||||||
|
*/
|
||||||
|
EditTextWidget.prototype.updateEditorDomNode = function(text) {
|
||||||
|
// Replace the edit value if the tiddler we're editing has changed
|
||||||
|
var domNode = this.domNodes[0];
|
||||||
|
if(!domNode.isTiddlyWikiFakeDom) {
|
||||||
|
if(this.document.activeElement !== domNode) {
|
||||||
|
domNode.value = text;
|
||||||
|
}
|
||||||
|
// Fix the height if needed
|
||||||
|
this.fixHeight();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Fix the height of textareas to fit their content
|
Fix the height of textareas to fit their content
|
||||||
*/
|
*/
|
||||||
@ -191,7 +209,7 @@ EditTextWidget.prototype.fixHeight = function() {
|
|||||||
Handle a dom "input" event
|
Handle a dom "input" event
|
||||||
*/
|
*/
|
||||||
EditTextWidget.prototype.handleInputEvent = function(event) {
|
EditTextWidget.prototype.handleInputEvent = function(event) {
|
||||||
this.saveChanges();
|
this.saveChanges(this.domNodes[0].value);
|
||||||
this.fixHeight();
|
this.fixHeight();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -208,8 +226,7 @@ EditTextWidget.prototype.handleFocusEvent = function(event) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
EditTextWidget.prototype.saveChanges = function() {
|
EditTextWidget.prototype.saveChanges = function(text) {
|
||||||
var text = this.domNodes[0].value
|
|
||||||
if(this.editField) {
|
if(this.editField) {
|
||||||
var tiddler = this.wiki.getTiddler(this.editTitle);
|
var tiddler = this.wiki.getTiddler(this.editTitle);
|
||||||
if(!tiddler) {
|
if(!tiddler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user