From 4b462eaae9ea18de54a045a2eb21e4f15f6e0849 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 26 Aug 2016 12:50:18 +0100 Subject: [PATCH] Move initInputEvents to prepareInput --- editor/js/text/bidi.js | 11 +++++++---- editor/js/ui/editor.js | 10 +++++----- editor/js/ui/workspaces.js | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/editor/js/text/bidi.js b/editor/js/text/bidi.js index 314045c4c..930aada97 100644 --- a/editor/js/text/bidi.js +++ b/editor/js/text/bidi.js @@ -64,16 +64,19 @@ RED.text.bidi = (function() { } function onInputChange() { + console.log("ic"); $(this).attr("dir", resolveBaseTextDir($(this).val())); } /** - * Listens to keyup, paste and cut events of a given input field. Upon one - * of these events the text direction is computed again + * Adds event listeners to the Input to ensure its text-direction attribute + * is properly set based on its content. * @param input - the input field */ - function initInputEvents(input) { + function prepareInput(input) { 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, enforceTextDirectionWithUCC: enforceTextDirectionWithUCC, resolveBaseTextDir: resolveBaseTextDir, - initInputEvents: initInputEvents + prepareInput: prepareInput } })(); diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index 57967777d..c36c54363 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -307,12 +307,12 @@ RED.editor = (function() { if (val == null) { 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")); RED.text.format.attach(input[0], definition[property].format, {}, false, "en"); } else { - input.val(val).attr("dir", RED.text.bidi.resolveBaseTextDir(val)); - RED.text.bidi.initInputEvents(input); + input.val(val); + RED.text.bidi.prepareInput(input); } } } @@ -1297,8 +1297,8 @@ RED.editor = (function() { value: "" }); - $("#subflow-input-name").val(subflow.name).attr("dir", RED.text.bidi.resolveBaseTextDir(subflow.name)); - RED.text.bidi.initInputEvents($("#subflow-input-name")); + $("#subflow-input-name").val(subflow.name); + RED.text.bidi.prepareInput($("#subflow-input-name")); subflowEditor.getSession().setValue(subflow.info||"",-1); var userCount = 0; var subflowType = "subflow:"+editing_node.id; diff --git a/editor/js/ui/workspaces.js b/editor/js/ui/workspaces.js index ec641c217..3b43243fe 100644 --- a/editor/js/ui/workspaces.js +++ b/editor/js/ui/workspaces.js @@ -109,8 +109,8 @@ RED.workspaces = (function() { '').appendTo(dialogForm); $('').prependTo(dialogForm); dialogForm.submit(function(e) { e.preventDefault();}); - $("#node-input-name").val(workspace.label).attr("dir", RED.text.bidi.resolveBaseTextDir(workspace.label)); - RED.text.bidi.initInputEvents($("#node-input-name")); + $("#node-input-name").val(workspace.label); + RED.text.bidi.prepareInput($("#node-input-name")) dialogForm.i18n(); }, close: function() {