1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Move initInputEvents to prepareInput

This commit is contained in:
Nick O'Leary 2016-08-26 12:50:18 +01:00
parent c60fb3bc25
commit 4b462eaae9
3 changed files with 14 additions and 11 deletions

View File

@ -64,16 +64,19 @@ RED.text.bidi = (function() {
} }
function onInputChange() { function onInputChange() {
console.log("ic");
$(this).attr("dir", resolveBaseTextDir($(this).val())); $(this).attr("dir", resolveBaseTextDir($(this).val()));
} }
/** /**
* Listens to keyup, paste and cut events of a given input field. Upon one * Adds event listeners to the Input to ensure its text-direction attribute
* of these events the text direction is computed again * is properly set based on its content.
* @param input - the input field * @param input - the input field
*/ */
function initInputEvents(input) { function prepareInput(input) {
input.on("keyup",onInputChange).on("paste",onInputChange).on("cut",onInputChange); input.on("keyup",onInputChange).on("paste",onInputChange).on("cut",onInputChange);
// Set the initial text direction
onInputChange.call(input);
} }
/** /**
@ -123,6 +126,6 @@ RED.text.bidi = (function() {
setTextDirection: setTextDirection, setTextDirection: setTextDirection,
enforceTextDirectionWithUCC: enforceTextDirectionWithUCC, enforceTextDirectionWithUCC: enforceTextDirectionWithUCC,
resolveBaseTextDir: resolveBaseTextDir, resolveBaseTextDir: resolveBaseTextDir,
initInputEvents: initInputEvents prepareInput: prepareInput
} }
})(); })();

View File

@ -307,12 +307,12 @@ RED.editor = (function() {
if (val == null) { if (val == null) {
val = ""; val = "";
} }
if (definition[property].hasOwnProperty("format") && definition[property].format !== "" && input[0].nodeName === "DIV") { if (definition !== undefined && definition[property].hasOwnProperty("format") && definition[property].format !== "" && input[0].nodeName === "DIV") {
input.html(RED.text.format.getHtml(val, definition[property].format, {}, false, "en")); input.html(RED.text.format.getHtml(val, definition[property].format, {}, false, "en"));
RED.text.format.attach(input[0], definition[property].format, {}, false, "en"); RED.text.format.attach(input[0], definition[property].format, {}, false, "en");
} else { } else {
input.val(val).attr("dir", RED.text.bidi.resolveBaseTextDir(val)); input.val(val);
RED.text.bidi.initInputEvents(input); RED.text.bidi.prepareInput(input);
} }
} }
} }
@ -1297,8 +1297,8 @@ RED.editor = (function() {
value: "" value: ""
}); });
$("#subflow-input-name").val(subflow.name).attr("dir", RED.text.bidi.resolveBaseTextDir(subflow.name)); $("#subflow-input-name").val(subflow.name);
RED.text.bidi.initInputEvents($("#subflow-input-name")); RED.text.bidi.prepareInput($("#subflow-input-name"));
subflowEditor.getSession().setValue(subflow.info||"",-1); subflowEditor.getSession().setValue(subflow.info||"",-1);
var userCount = 0; var userCount = 0;
var subflowType = "subflow:"+editing_node.id; var subflowType = "subflow:"+editing_node.id;

View File

@ -109,8 +109,8 @@ RED.workspaces = (function() {
'</div>').appendTo(dialogForm); '</div>').appendTo(dialogForm);
$('<input type="text" style="display: none;" />').prependTo(dialogForm); $('<input type="text" style="display: none;" />').prependTo(dialogForm);
dialogForm.submit(function(e) { e.preventDefault();}); dialogForm.submit(function(e) { e.preventDefault();});
$("#node-input-name").val(workspace.label).attr("dir", RED.text.bidi.resolveBaseTextDir(workspace.label)); $("#node-input-name").val(workspace.label);
RED.text.bidi.initInputEvents($("#node-input-name")); RED.text.bidi.prepareInput($("#node-input-name"))
dialogForm.i18n(); dialogForm.i18n();
}, },
close: function() { close: function() {