From 67791db1a8e7c59251607b98aebca90cc1a01f58 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 14 Apr 2014 11:06:39 +0100 Subject: [PATCH] styleText moved into helpers --- client/build.js | 1 - client/src/helpers/utils.js | 43 +++++++++++++++++++++++++++++++---- client/src/views/texttheme.js | 42 ---------------------------------- server/settingsgenerator.js | 1 - 4 files changed, 39 insertions(+), 48 deletions(-) delete mode 100644 client/src/views/texttheme.js diff --git a/client/build.js b/client/build.js index 0956e07..746cd6c 100644 --- a/client/build.js +++ b/client/build.js @@ -81,7 +81,6 @@ var source_files = [ __dirname + '/src/views/userbox.js', __dirname + '/src/views/channeltools.js', __dirname + '/src/views/channelinfo.js', - __dirname + '/src/views/texttheme.js', __dirname + '/src/applets/settings.js', __dirname + '/src/applets/chanlist.js', __dirname + '/src/applets/scripteditor.js', diff --git a/client/src/helpers/utils.js b/client/src/helpers/utils.js index 9c32e02..e07c16b 100644 --- a/client/src/helpers/utils.js +++ b/client/src/helpers/utils.js @@ -505,11 +505,46 @@ function parseISO8601(str) { // Simplyfy the translation syntax function translateText(string_id, params) { - if (params === undefined) var params = ''; - + params = params || ''; + return _kiwi.global.i18n.translate(string_id).fetch(params); } -// Simplyfy the text styling syntax + +/** + * Simplyfy the text styling syntax + * + * Syntax: + * %N: nickname + * %C: channel + * %J: ident + * %H: host + * %R: realname + * %C[digit]: color + * %B: bold + * %I: italic + * %U: underline + * %O: cancel styles + * %T: translated text + **/ function styleText(string_id, params) { - return _kiwi.global.text_theme.styleText(string_id, params); + var style, text; + + style = formatToIrcMsg(_kiwi.global.text_theme.options[string_id]); + + // Bring member info back to first level of params + if (params['%M']) { + _.each(params['%M'], function(val, key) { + params[key] = val; + }); + } + + // Do the magic. Use the shorthand syntax to produce output. + text = style.replace(/%([TJHNCR])/g, function(match, key) { + key = '%' + key; + + if (typeof params[key.toUpperCase()] !== 'undefined') + return params[key.toUpperCase()]; + }); + + return text; } \ No newline at end of file diff --git a/client/src/views/texttheme.js b/client/src/views/texttheme.js deleted file mode 100644 index c85f1c2..0000000 --- a/client/src/views/texttheme.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * TEXT THEMES SYNTAX - * - * %N: nickname - * %C[digit]: color - * %C: channel - * %J: ident - * %H: host - * %R: realname - * %B: bold - * %I: italic - * %U: underline - * %O: cancel styles - * %T: translated text - **/ - -_kiwi.view.TextTheme = _kiwi.view.Panel.extend({ - initialize: function(text_theme) { - this.text_theme = text_theme; - }, - styleText: function(string_id, params) { - var style, text; - - style = formatToIrcMsg(_kiwi.global.text_theme.options[string_id]); - - // Bring member info back to first level of params - if (params['%M']) { - for(key in params['%M']) { - params[key] = params['%M'][key]; - } - } - - // Do the magic. Use the shorthand syntax to produce output. - text = style.replace(/%([TJHNCR])/g, function(match, key) { - key = '%' + key; - - if (typeof params[key.toUpperCase()] !== 'undefined') - return params[key.toUpperCase()]; - }); - return text; - } -}); \ No newline at end of file diff --git a/server/settingsgenerator.js b/server/settingsgenerator.js index 0f8b878..2c8360e 100644 --- a/server/settingsgenerator.js +++ b/server/settingsgenerator.js @@ -244,7 +244,6 @@ function addScripts(vars, debug) { 'src/views/userbox.js', 'src/views/channeltools.js', 'src/views/channelinfo.js', - 'src/views/texttheme.js', 'src/applets/settings.js', 'src/applets/chanlist.js', 'src/applets/scripteditor.js', -- 2.25.1