From 37adf3aa0df01630869db7f66bca7b0fbbbf4407 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 21 Jun 2017 10:44:29 +0200 Subject: [PATCH] Created emoji shorcut to HTML code translator --- assets/js/common/functionsSchema.js | 7 +++++++ assets/js/components/emoji/list.js | 26 ++++++++++++++++++++++++++ assets/js/components/emoji/parser.js | 25 +++++++++++++++++++++++++ assets/js/pages/home/home.js | 2 +- corePage/config/dev.config.php | 1 + 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 assets/js/components/emoji/list.js diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 87b1e94a..d56ab1ef 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -593,6 +593,13 @@ var ComunicWeb = { parser: { //TODO : implement }, + + /** + * Emojies list + */ + list: { + //TODO : implement + }, }, }, diff --git a/assets/js/components/emoji/list.js b/assets/js/components/emoji/list.js new file mode 100644 index 00000000..de6a0810 --- /dev/null +++ b/assets/js/components/emoji/list.js @@ -0,0 +1,26 @@ +/** + * Emojies list + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.emoji.list = { + + /** + * Emojies translation list + */ + translation: { + //Heads + ":)": "😀", + ":(": "😥", + ":D": "😁", + ":P": "😛", + "(devil)": "😈", + ":O": "😲", + "(cool)": "😎", + + //Objects + "(movie)": "📽", + } + +} \ No newline at end of file diff --git a/assets/js/components/emoji/parser.js b/assets/js/components/emoji/parser.js index ab4c2516..0d280fdd 100644 --- a/assets/js/components/emoji/parser.js +++ b/assets/js/components/emoji/parser.js @@ -23,6 +23,8 @@ ComunicWeb.components.emoji.parser = { */ parse: function(infos){ + //Peform string parsing + infos.element.innerHTML = this.shorcutToHTMLcode(infos.element.innerHTML); //Perform Twitter parsing this.twitterEmojiesParsing(infos.element); @@ -48,4 +50,27 @@ ComunicWeb.components.emoji.parser = { return true; }, + /** + * Perform shorcut emoji to HTML code parsing + * + * @param {String} string The input string + * @return {String} The output string + */ + shorcutToHTMLcode: function(string){ + + //Process all emojie list + var i; + for(i in ComunicWeb.components.emoji.list.translation){ + + //Change smileys as many time as required + while(string.includes(i)) + string = string.replace(i, ComunicWeb.components.emoji.list.translation[i]); + + } + + //Return result + return string; + } + + } \ No newline at end of file diff --git a/assets/js/pages/home/home.js b/assets/js/pages/home/home.js index c2c3c69a..eddac137 100644 --- a/assets/js/pages/home/home.js +++ b/assets/js/pages/home/home.js @@ -32,7 +32,7 @@ ComunicWeb.pages.home.home = { var emojiesArea = createElem2({ appendTo: targetElement, type: "p", - innerHTML: "Emoji test : :) 🇬🇫 🎅🏻" + innerHTML: "Emoji test : :) 🇬🇫 🎅🏻 :( (movie) (cool)" }); diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 768ed06a..f4284c19 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -137,6 +137,7 @@ $config['JSfiles'] = array( //Emojies "%PATH_ASSETS%js/components/emoji/parser.js", + "%PATH_ASSETS%js/components/emoji/list.js", //User scripts "%PATH_ASSETS%js/user/loginTokens.js",