From ccfdd04bc407dd4a3f6c1b1d8940256e53df2550 Mon Sep 17 00:00:00 2001 From: oSkrobuk Date: Mon, 1 Nov 2021 00:52:08 +0300 Subject: [PATCH] Unicode ship names to string --- js/app/map/local.js | 6 +++--- js/app/ui/dialog/map_info.js | 4 ++-- js/app/util.js | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/js/app/map/local.js b/js/app/map/local.js index 0a789579..0aec1636 100644 --- a/js/app/map/local.js +++ b/js/app/map/local.js @@ -411,7 +411,7 @@ define([ }); let localTable = table.DataTable({ - pageLength: 3, // default page length, smaller then max page length (4) if map is vertical resized to min. + pageLength: 3, // default page length, smaller then max page length (4) if map is vertical resized to min. paging: true, pagingType: 'simple', lengthChange: false, @@ -484,7 +484,7 @@ define([ _: (data, type, row, meta) => { let value = data.name; if(type === 'display'){ - value = '
' + data.name + '
'; + value = '
' + Util.unicodeToString(data.name) + '
'; } return value; }, @@ -622,4 +622,4 @@ define([ }); }; -}); \ No newline at end of file +}); diff --git a/js/app/ui/dialog/map_info.js b/js/app/ui/dialog/map_info.js index 2d8a5333..2c55f0b4 100644 --- a/js/app/ui/dialog/map_info.js +++ b/js/app/ui/dialog/map_info.js @@ -771,7 +771,7 @@ define([ if(data){ value = data.name; if(type === 'display'){ - value = '
' + data.name + '
'; + value = '
' + Util.unicodeToString(data.name) + '
'; } } @@ -1395,4 +1395,4 @@ define([ } }; -}); \ No newline at end of file +}); diff --git a/js/app/util.js b/js/app/util.js index 6fc4f76e..f7138ef0 100644 --- a/js/app/util.js +++ b/js/app/util.js @@ -946,6 +946,19 @@ define([ return url; }; + /** + * convert unicode to string + * @param text + * @returns {String} + */ + let unicodeToString = (text) => { + let result = text.replace(/\\u[\dA-F]{4}/gi, + function (match) { + return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16)); + }); + return result.substring(0, 2) == "u'" ? result.substring(2, result.length - 1) : result; + }; + /** * polyfill for "passive" events * -> see https://github.com/zzarcon/default-passive-events @@ -3687,6 +3700,7 @@ define([ showVersionInfo: showVersionInfo, imgRoot: imgRoot, eveImageUrl: eveImageUrl, + unicodeToString: unicodeToString, initPassiveEvents: initPassiveEvents, initDefaultBootboxConfig: initDefaultBootboxConfig, initDefaultTooltipConfig: initDefaultTooltipConfig, @@ -3789,4 +3803,4 @@ define([ setCookie: setCookie, getCookie: getCookie }; -}); \ No newline at end of file +});