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

Move bidi code under RED.text

This commit is contained in:
Nick O'Leary 2016-08-25 17:09:56 +01:00
parent ccc08be0ee
commit 6ad71bd222
12 changed files with 1395 additions and 1394 deletions

View File

@ -104,8 +104,8 @@ module.exports = function(grunt) {
"editor/js/settings.js", "editor/js/settings.js",
"editor/js/user.js", "editor/js/user.js",
"editor/js/comms.js", "editor/js/comms.js",
"editor/js/bidi.js", "editor/js/text/bidi.js",
"editor/js/format.js", "editor/js/text/format.js",
"editor/js/ui/state.js", "editor/js/ui/state.js",
"editor/js/nodes.js", "editor/js/nodes.js",
"editor/js/history.js", "editor/js/history.js",

File diff suppressed because it is too large Load Diff

View File

@ -236,7 +236,7 @@ RED.history = (function() {
}); });
if (ev.node.type === 'subflow') { if (ev.node.type === 'subflow') {
$("#menu-item-workspace-menu-"+ev.node.id.replace(".","-")).text(RED.bidi.enforceTextDirectionWithUCC(ev.node.name)); $("#menu-item-workspace-menu-"+ev.node.id.replace(".","-")).text(RED.text.bidi.enforceTextDirectionWithUCC(ev.node.name));
} }
} else { } else {
RED.editor.updateNodeProperties(ev.node); RED.editor.updateNodeProperties(ev.node);

View File

@ -176,13 +176,14 @@ var RED = (function() {
{id:"menu-item-view-snap-grid",label:RED._("menu.label.view.snapGrid"),toggle:true,onselect:RED.view.toggleSnapGrid}, {id:"menu-item-view-snap-grid",label:RED._("menu.label.view.snapGrid"),toggle:true,onselect:RED.view.toggleSnapGrid},
{id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true}, {id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true},
null, null,
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true},
{id:"menu-item-bidi",label:RED._("menu.label.view.textDir"),options:[ {id:"menu-item-bidi",label:RED._("menu.label.view.textDir"),options:[
{id:"menu-item-bidi-default",toggle:"text-direction",label:RED._("menu.label.view.defaultDir"),selected: true, onselect:function(s) { if(s){RED.view.toggleTextDir("")}}}, {id:"menu-item-bidi-default",toggle:"text-direction",label:RED._("menu.label.view.defaultDir"),selected: true, onselect:function(s) { if(s){RED.view.toggleTextDir("")}}},
{id:"menu-item-bidi-ltr",toggle:"text-direction",label:RED._("menu.label.view.ltr"), onselect:function(s) { if(s){RED.view.toggleTextDir("ltr")}}}, {id:"menu-item-bidi-ltr",toggle:"text-direction",label:RED._("menu.label.view.ltr"), onselect:function(s) { if(s){RED.view.toggleTextDir("ltr")}}},
{id:"menu-item-bidi-rtl",toggle:"text-direction",label:RED._("menu.label.view.rtl"), onselect:function(s) { if(s){RED.view.toggleTextDir("rtl")}}}, {id:"menu-item-bidi-rtl",toggle:"text-direction",label:RED._("menu.label.view.rtl"), onselect:function(s) { if(s){RED.view.toggleTextDir("rtl")}}},
{id:"menu-item-bidi-auto",toggle:"text-direction",label:RED._("menu.label.view.auto"), onselect:function(s) { if(s){RED.view.toggleTextDir("auto")}}} {id:"menu-item-bidi-auto",toggle:"text-direction",label:RED._("menu.label.view.auto"), onselect:function(s) { if(s){RED.view.toggleTextDir("auto")}}}
]} ]},
null,
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true}
]}, ]},
null, null,
{id:"menu-item-import",label:RED._("menu.label.import"),options:[ {id:"menu-item-import",label:RED._("menu.label.import"),options:[

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.text = {};
RED.bidi = (function() { RED.text.bidi = (function() {
var textDir = ""; var textDir = "";
var LRE = "\u202A", var LRE = "\u202A",
RLE = "\u202B", RLE = "\u202B",
PDF = "\u202C"; PDF = "\u202C";
function isRTLValue(stringValue) { function isRTLValue(stringValue) {
for (var ch in stringValue) { for (var ch in stringValue) {
if (isBidiChar(stringValue.charCodeAt(ch))) { if (isBidiChar(stringValue.charCodeAt(ch))) {
@ -27,7 +27,7 @@ RED.bidi = (function() {
} }
else if(isLatinChar(stringValue.charCodeAt(ch))) { else if(isLatinChar(stringValue.charCodeAt(ch))) {
return false; return false;
} }
} }
return false; return false;
} }
@ -60,14 +60,14 @@ RED.bidi = (function() {
if((c > 64 && c < 91)||(c > 96 && c < 123)) { if((c > 64 && c < 91)||(c > 96 && c < 123)) {
return true; return true;
} }
else { else {
return false; return false;
} }
} }
/** /**
* Determines the text direction of a given string. * Determines the text direction of a given string.
* @param value - the string * @param value - the string
*/ */
function resolveBaseTextDir(value) { function resolveBaseTextDir(value) {
if (textDir == "auto") { if (textDir == "auto") {
@ -76,27 +76,27 @@ RED.bidi = (function() {
} else { } else {
return "ltr"; return "ltr";
} }
} }
else { else {
return textDir; return textDir;
} }
} }
function onInputChange() { function onInputChange() {
$(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 of these events the text direction is computed again * Listens to keyup, paste and cut events of a given input field. Upon one of these events the text direction is computed again
* @param input - the input field * @param input - the input field
*/ */
function initInputEvents(input) { function initInputEvents(input) {
input.on("keyup",onInputChange).on("paste",onInputChange).on("cut",onInputChange); input.on("keyup",onInputChange).on("paste",onInputChange).on("cut",onInputChange);
} }
/** /**
* Enforces the text direction of a given string by adding UCC (Unicode Control Characters) * Enforces the text direction of a given string by adding UCC (Unicode Control Characters)
* @param value - the string * @param value - the string
*/ */
function enforceTextDirectionWithUCC(value) { function enforceTextDirectionWithUCC(value) {
if (value) { if (value) {
@ -110,27 +110,27 @@ RED.bidi = (function() {
} }
return value; return value;
} }
/** /**
* Enforces the text direction for all the spans with style bidiAware under workpsace or sidebar div * Enforces the text direction for all the spans with style bidiAware under workpsace or sidebar div
*/ */
function enforceTextDirectionOnPage() { function enforceTextDirectionOnPage() {
$("#workspace").find('span.bidiAware').each(function() { $("#workspace").find('span.bidiAware').each(function() {
$(this).attr("dir", resolveBaseTextDir($(this).html())); $(this).attr("dir", resolveBaseTextDir($(this).html()));
}); });
$("#sidebar").find('span.bidiAware').each(function() { $("#sidebar").find('span.bidiAware').each(function() {
$(this).attr("dir", resolveBaseTextDir($(this).text())); $(this).attr("dir", resolveBaseTextDir($(this).text()));
}); });
} }
/** /**
* Sets the text direction preference * Sets the text direction preference
* @param dir - the text direction preference * @param dir - the text direction preference
*/ */
function setTextDirection(dir) { function setTextDirection(dir) {
textDir = dir; textDir = dir;
} }
return { return {
setTextDirection: setTextDirection, setTextDirection: setTextDirection,
enforceTextDirectionOnPage: enforceTextDirectionOnPage, enforceTextDirectionOnPage: enforceTextDirectionOnPage,

1329
editor/js/text/format.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -301,19 +301,19 @@ RED.editor = (function() {
var input = $("#"+prefix+"-"+property); var input = $("#"+prefix+"-"+property);
if (input.attr('type') === "checkbox") { if (input.attr('type') === "checkbox") {
input.prop('checked',node[property]); input.prop('checked',node[property]);
} }
else { else {
var val = node[property]; var val = node[property];
if (val == null) { if (val == null) {
val = ""; val = "";
} }
if ("format" in definition[property] && definition[property].format !== "" && input[0].nodeName === "DIV") { if (definition[property].hasOwnProperty("format") && definition[property].format !== "" && input[0].nodeName === "DIV") {
input.html(RED.format.getHtml(val, definition[property].format, {}, false, "en")); input.html(RED.text.format.getHtml(val, definition[property].format, {}, false, "en"));
RED.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.bidi.resolveBaseTextDir(val)); input.val(val).attr("dir", RED.text.bidi.resolveBaseTextDir(val));
RED.bidi.initInputEvents(input); RED.text.bidi.initInputEvents(input);
} }
} }
} }
@ -1205,7 +1205,7 @@ RED.editor = (function() {
changes['name'] = editing_node.name; changes['name'] = editing_node.name;
editing_node.name = newName; editing_node.name = newName;
changed = true; changed = true;
$("#menu-item-workspace-menu-"+editing_node.id.replace(".","-")).text(RED.bidi.enforceTextDirectionWithUCC(newName)); $("#menu-item-workspace-menu-"+editing_node.id.replace(".","-")).text(RED.text.bidi.enforceTextDirectionWithUCC(newName));
} }
var newDescription = subflowEditor.getValue(); var newDescription = subflowEditor.getValue();
@ -1297,8 +1297,8 @@ RED.editor = (function() {
value: "" value: ""
}); });
$("#subflow-input-name").val(subflow.name).attr("dir", RED.bidi.resolveBaseTextDir(subflow.name)); $("#subflow-input-name").val(subflow.name).attr("dir", RED.text.bidi.resolveBaseTextDir(subflow.name));
RED.bidi.initInputEvents($("#subflow-input-name")); RED.text.bidi.initInputEvents($("#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

@ -91,15 +91,15 @@ RED.palette = (function() {
el.css({height:multiLineNodeHeight+"px"}); el.css({height:multiLineNodeHeight+"px"});
var labelElement = el.find(".palette_label"); var labelElement = el.find(".palette_label");
labelElement.html(lines).attr('dir', RED.bidi.resolveBaseTextDir(lines)); labelElement.html(lines).attr('dir', RED.text.bidi.resolveBaseTextDir(lines));
el.find(".palette_port").css({top:(multiLineNodeHeight/2-5)+"px"}); el.find(".palette_port").css({top:(multiLineNodeHeight/2-5)+"px"});
var popOverContent; var popOverContent;
try { try {
var l = "<p><b>"+RED.bidi.enforceTextDirectionWithUCC(label)+"</b></p>"; var l = "<p><b>"+RED.text.bidi.enforceTextDirectionWithUCC(label)+"</b></p>";
if (label != type) { if (label != type) {
l = "<p><b>"+RED.bidi.enforceTextDirectionWithUCC(label)+"</b><br/><i>"+type+"</i></p>"; l = "<p><b>"+RED.text.bidi.enforceTextDirectionWithUCC(label)+"</b><br/><i>"+type+"</i></p>";
} }
popOverContent = $(l+(info?info:$("script[data-help-name|='"+type+"']").html()||"<p>"+RED._("palette.noInfo")+"</p>").trim()) popOverContent = $(l+(info?info:$("script[data-help-name|='"+type+"']").html()||"<p>"+RED._("palette.noInfo")+"</p>").trim())
.filter(function(n) { .filter(function(n) {

View File

@ -70,7 +70,7 @@ RED.sidebar.info = (function() {
var table = '<table class="node-info"><tbody>'; var table = '<table class="node-info"><tbody>';
table += '<tr class="blank"><td colspan="2">'+RED._("sidebar.info.node")+'</td></tr>'; table += '<tr class="blank"><td colspan="2">'+RED._("sidebar.info.node")+'</td></tr>';
if (node.type != "subflow" && node.name) { if (node.type != "subflow" && node.name) {
table += '<tr><td>'+RED._("common.label.name")+'</td><td>&nbsp;<span class="bidiAware" dir="'+RED.bidi.resolveBaseTextDir(node.name)+'">'+node.name+'</span></td></tr>'; table += '<tr><td>'+RED._("common.label.name")+'</td><td>&nbsp;<span class="bidiAware" dir="'+RED.text.bidi.resolveBaseTextDir(node.name)+'">'+node.name+'</span></td></tr>';
} }
table += "<tr><td>"+RED._("sidebar.info.type")+"</td><td>&nbsp;"+node.type+"</td></tr>"; table += "<tr><td>"+RED._("sidebar.info.type")+"</td><td>&nbsp;"+node.type+"</td></tr>";
table += "<tr><td>"+RED._("sidebar.info.id")+"</td><td>&nbsp;"+node.id+"</td></tr>"; table += "<tr><td>"+RED._("sidebar.info.id")+"</td><td>&nbsp;"+node.id+"</td></tr>";
@ -93,7 +93,7 @@ RED.sidebar.info = (function() {
userCount++; userCount++;
} }
}); });
table += '<tr><td>'+RED._("common.label.name")+'</td><td><span class="bidiAware" dir=\"'+RED.bidi.resolveBaseTextDir(subflowNode.name)+'">'+subflowNode.name+'</span></td></tr>'; table += '<tr><td>'+RED._("common.label.name")+'</td><td><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.name)+'">'+subflowNode.name+'</span></td></tr>';
table += "<tr><td>"+RED._("sidebar.info.instances")+"</td><td>"+userCount+"</td></tr>"; table += "<tr><td>"+RED._("sidebar.info.instances")+"</td><td>"+userCount+"</td></tr>";
} }
@ -140,14 +140,14 @@ RED.sidebar.info = (function() {
table += "</tbody></table><hr/>"; table += "</tbody></table><hr/>";
if (!subflowNode && node.type != "comment") { if (!subflowNode && node.type != "comment") {
var helpText = $("script[data-help-name|='"+node.type+"']").html()||""; var helpText = $("script[data-help-name|='"+node.type+"']").html()||"";
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.bidi.resolveBaseTextDir(helpText)+'">'+helpText+'</span></div>'; table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(helpText)+'">'+helpText+'</span></div>';
} }
if (subflowNode) { if (subflowNode) {
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.bidi.resolveBaseTextDir(subflowNode.info||"")+'">'+marked(subflowNode.info||"")+'</span></div>'; table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(subflowNode.info||"")+'">'+marked(subflowNode.info||"")+'</span></div>';
} else if (node._def && node._def.info) { } else if (node._def && node._def.info) {
var info = node._def.info; var info = node._def.info;
var textInfo = (typeof info === "function" ? info.call(node) : info); var textInfo = (typeof info === "function" ? info.call(node) : info);
table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.bidi.resolveBaseTextDir(textInfo)+'">'+marked(textInfo)+'</span></div>'; table += '<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(textInfo)+'">'+marked(textInfo)+'</span></div>';
//table += '<div class="node-help">'+(typeof info === "function" ? info.call(node) : info)+'</div>'; //table += '<div class="node-help">'+(typeof info === "function" ? info.call(node) : info)+'</div>';
} }

View File

@ -127,7 +127,7 @@ RED.tabs = (function() {
$('<img src="'+tab.icon+'" class="red-ui-tab-icon"/>').appendTo(link); $('<img src="'+tab.icon+'" class="red-ui-tab-icon"/>').appendTo(link);
} }
var span = $('<span/>',{class:"bidiAware"}).text(tab.label).appendTo(link); var span = $('<span/>',{class:"bidiAware"}).text(tab.label).appendTo(link);
span.attr('dir', RED.bidi.resolveBaseTextDir(tab.label)); span.attr('dir', RED.text.bidi.resolveBaseTextDir(tab.label));
link.on("click",onTabClick); link.on("click",onTabClick);
link.on("dblclick",onTabDblClick); link.on("dblclick",onTabDblClick);
@ -240,7 +240,7 @@ RED.tabs = (function() {
tabs[id].label = label; tabs[id].label = label;
var tab = ul.find("a[href='#"+id+"']"); var tab = ul.find("a[href='#"+id+"']");
tab.attr("title",label); tab.attr("title",label);
tab.find("span").text(label).attr('dir', RED.bidi.resolveBaseTextDir(label)); tab.find("span").text(label).attr('dir', RED.text.bidi.resolveBaseTextDir(label));
updateTabWidths(); updateTabWidths();
}, },
order: function(order) { order: function(order) {

View File

@ -1792,7 +1792,7 @@ RED.view = (function() {
l = d._def.label; l = d._def.label;
try { try {
l = (typeof l === "function" ? l.call(d) : l)||""; l = (typeof l === "function" ? l.call(d) : l)||"";
l = RED.bidi.enforceTextDirectionWithUCC(l); l = RED.text.bidi.enforceTextDirectionWithUCC(l);
} catch(err) { } catch(err) {
console.log("Definition error: "+d.type+".label",err); console.log("Definition error: "+d.type+".label",err);
l = d.type; l = d.type;
@ -2155,7 +2155,7 @@ RED.view = (function() {
).classed("link_selected", false); ).classed("link_selected", false);
} }
RED.bidi.enforceTextDirectionOnPage(); RED.text.bidi.enforceTextDirectionOnPage();
if (d3.event) { if (d3.event) {
d3.event.preventDefault(); d3.event.preventDefault();
@ -2361,7 +2361,7 @@ RED.view = (function() {
redraw(); redraw();
}, },
toggleTextDir: function(value) { toggleTextDir: function(value) {
RED.bidi.setTextDirection(value); RED.text.bidi.setTextDirection(value);
RED.nodes.eachNode(function(n) { n.dirty = true;}); RED.nodes.eachNode(function(n) { n.dirty = true;});
redraw(); redraw();
RED.palette.refresh(); RED.palette.refresh();

View File

@ -94,7 +94,7 @@ RED.workspaces = (function() {
workspace_tabs.renameTab(workspace.id,label); workspace_tabs.renameTab(workspace.id,label);
RED.nodes.dirty(true); RED.nodes.dirty(true);
RED.sidebar.config.refresh(); RED.sidebar.config.refresh();
$("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(RED.bidi.enforceTextDirectionWithUCC(label)); $("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(RED.text.bidi.enforceTextDirectionWithUCC(label));
} }
RED.tray.close(); RED.tray.close();
} }
@ -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.bidi.resolveBaseTextDir(workspace.label)); $("#node-input-name").val(workspace.label).attr("dir", RED.text.bidi.resolveBaseTextDir(workspace.label));
RED.bidi.initInputEvents($("#node-input-name")); RED.text.bidi.initInputEvents($("#node-input-name"));
dialogForm.i18n(); dialogForm.i18n();
}, },
close: function() { close: function() {
@ -226,7 +226,7 @@ RED.workspaces = (function() {
refresh: function() { refresh: function() {
RED.nodes.eachWorkspace(function(ws) { RED.nodes.eachWorkspace(function(ws) {
workspace_tabs.renameTab(ws.id,ws.label); workspace_tabs.renameTab(ws.id,ws.label);
$("#menu-item-workspace-menu-"+ws.id.replace(".","-")).text(RED.bidi.enforceTextDirectionWithUCC(ws.label)); $("#menu-item-workspace-menu-"+ws.id.replace(".","-")).text(RED.text.bidi.enforceTextDirectionWithUCC(ws.label));
}) })
RED.nodes.eachSubflow(function(sf) { RED.nodes.eachSubflow(function(sf) {