core/modules/editor/engines/simple.js contains unimplemented createTextOperation and executeTextOperation functions:
Create a blank structure representing a text operation
*/
SimpleEngine.prototype.createTextOperation = function() {
return null;
};
/*
Execute a text operation
*/
SimpleEngine.prototype.executeTextOperation = function(operation) {
};
Due to some SOP constraints in environment where TiddlyWiki is run (ZeroNet)
it's not always possible to use framed.js editor. I've patched
core/modules/widgets/edit-text.js to load only simple.js version editor and
copy-pasted these functions from frames.js with minor modifications. It works
without any problems.
I'm a beginner in JavaScript and not aware of possible problems introduced by
this change. May I ask why these functions are not implemented? Is my fix is a
proper fix? Could I commit it to the core? Visually everything seems to be OK,
it works fine.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywikidev/00f96b36-b86e-9644-69b6-5260c009230e%40valdikss.org.ru.
/*\
title: $:/plugins/ValdikSS/zeronet-saver/editor-simple-fix.js
type: application/javascript
module-type: library
Text editor engine based on a simple input or textarea tag
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var HEIGHT_VALUE_TITLE = "$:/config/TextEditor/EditorHeight/Height";
function SimpleEngine2(options) {
// Save our options
options = options || {};
this.widget = options.widget;
this.value = options.value;
this.parentNode = options.parentNode;
this.nextSibling = options.nextSibling;
// Construct the textarea or input node
var tag = this.widget.editTag;
if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) {
tag = "input";
}
this.domNode = this.widget.document.createElement(tag);
// Set the text
if(this.widget.editTag === "textarea") {
this.domNode.appendChild(this.widget.document.createTextNode(this.value));
} else {
this.domNode.value = this.value;
}
// Set the attributes
if(this.widget.editType) {
this.domNode.setAttribute("type",this.widget.editType);
}
if(this.widget.editPlaceholder) {
this.domNode.setAttribute("placeholder",this.widget.editPlaceholder);
}
if(this.widget.editSize) {
this.domNode.setAttribute("size",this.widget.editSize);
}
if(this.widget.editRows) {
this.domNode.setAttribute("rows",this.widget.editRows);
}
if(this.widget.editClass) {
this.domNode.className = this.widget.editClass;
}
if(this.widget.editTabIndex) {
this.domNode.setAttribute("tabindex",this.widget.editTabIndex);
}
// Add an input event handler
$tw.utils.addEventListeners(this.domNode,[
{name: "focus", handlerObject: this, handlerMethod:
"handleFocusEvent"},
{name: "input", handlerObject: this, handlerMethod:
"handleInputEvent"}
]);
// Insert the element into the DOM
this.parentNode.insertBefore(this.domNode,this.nextSibling);
this.widget.domNodes.push(this.domNode);
}
/*
Set the text of the engine if it doesn't currently have focus
*/
SimpleEngine2.prototype.setText = function(text,type) {
if(!this.domNode.isTiddlyWikiFakeDom) {
if(this.domNode.ownerDocument.activeElement !== this.domNode ||
text === "") {
this.domNode.value = text;
}
// Fix the height if needed
this.fixHeight();
}
};
/*
Get the text of the engine
*/
SimpleEngine2.prototype.getText = function() {
return this.domNode.value;
};
/*
Fix the height of textarea to fit content
*/
SimpleEngine2.prototype.fixHeight = function() {
if(this.widget.editTag === "textarea") {
if(this.widget.editAutoHeight) {
if(this.domNode && !this.domNode.isTiddlyWikiFakeDom) {
$tw.utils.resizeTextAreaToFit(this.domNode,this.widget.editMinHeight);
}
} else {
var fixedHeight =
parseInt(this.widget.wiki.getTiddlerText(HEIGHT_VALUE_TITLE,"400px"),10);
fixedHeight = Math.max(fixedHeight,20);
this.domNode.style.height = fixedHeight + "px";
}
}
};
/*
Focus the engine node
*/
SimpleEngine2.prototype.focus = function() {
if(this.domNode.focus && this.domNode.select) {
this.domNode.focus();
this.domNode.select();
}
};
/*
Handle a dom "input" event which occurs when the text has changed
*/
SimpleEngine2.prototype.handleInputEvent = function(event) {
this.widget.saveChanges(this.getText());
this.fixHeight();
return true;
};
/*
Handle a dom "focus" event
*/
SimpleEngine2.prototype.handleFocusEvent = function(event) {
this.widget.cancelPopups();
if(this.widget.editFocusPopup) {
$tw.popup.triggerPopup({
domNode: this.domNode,
title: this.widget.editFocusPopup,
wiki: this.widget.wiki,
force: true
});
}
return true;
};
/*
Create a blank structure representing a text operation
*/
SimpleEngine2.prototype.createTextOperation = function() {
var operation = {
text: this.domNode.value,
selStart: this.domNode.selectionStart,
selEnd: this.domNode.selectionEnd,
cutStart: null,
cutEnd: null,
replacement: null,
newSelStart: null,
newSelEnd: null
};
operation.selection =
operation.text.substring(operation.selStart,operation.selEnd);
return operation;
};
/*
Execute a text operation
*/
SimpleEngine2.prototype.executeTextOperation = function(operation) {
// Perform the required changes to the text area and the underlying
tiddler
var newText = operation.text;
this.iframeDoc = document;
if(operation.replacement !== null) {
newText = operation.text.substring(0,operation.cutStart) +
operation.replacement + operation.text.substring(operation.cutEnd);
// Attempt to use a execCommand to modify the value of the
control
if(this.iframeDoc.queryCommandSupported("insertText") &&
this.iframeDoc.queryCommandSupported("delete") && !$tw.browser.isFirefox) {
this.domNode.focus();
this.domNode.setSelectionRange(operation.cutStart,operation.cutEnd);
if(operation.replacement === "") {
this.iframeDoc.execCommand("delete",false,"");
} else {
this.iframeDoc.execCommand("insertText",false,operation.replacement);
}
} else {
this.domNode.value = newText;
}
this.domNode.focus();
this.domNode.setSelectionRange(operation.newSelStart,operation.newSelEnd);
}
this.domNode.focus();
return newText;
};
exports.SimpleEngine2 = SimpleEngine2;
})();
signature.asc
Description: OpenPGP digital signature
