Created emoji shorcut to HTML code translator

This commit is contained in:
Pierre 2017-06-21 10:44:29 +02:00
parent 2601da21ad
commit 37adf3aa0d
5 changed files with 60 additions and 1 deletions

View File

@ -593,6 +593,13 @@ var ComunicWeb = {
parser: { parser: {
//TODO : implement //TODO : implement
}, },
/**
* Emojies list
*/
list: {
//TODO : implement
},
}, },
}, },

View File

@ -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)": "📽",
}
}

View File

@ -23,6 +23,8 @@ ComunicWeb.components.emoji.parser = {
*/ */
parse: function(infos){ parse: function(infos){
//Peform string parsing
infos.element.innerHTML = this.shorcutToHTMLcode(infos.element.innerHTML);
//Perform Twitter parsing //Perform Twitter parsing
this.twitterEmojiesParsing(infos.element); this.twitterEmojiesParsing(infos.element);
@ -48,4 +50,27 @@ ComunicWeb.components.emoji.parser = {
return true; 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;
}
} }

View File

@ -32,7 +32,7 @@ ComunicWeb.pages.home.home = {
var emojiesArea = createElem2({ var emojiesArea = createElem2({
appendTo: targetElement, appendTo: targetElement,
type: "p", type: "p",
innerHTML: "Emoji test : :) 🇬🇫 🎅🏻" innerHTML: "Emoji test : :) 🇬🇫 🎅🏻 :( (movie) (cool)"
}); });

View File

@ -137,6 +137,7 @@ $config['JSfiles'] = array(
//Emojies //Emojies
"%PATH_ASSETS%js/components/emoji/parser.js", "%PATH_ASSETS%js/components/emoji/parser.js",
"%PATH_ASSETS%js/components/emoji/list.js",
//User scripts //User scripts
"%PATH_ASSETS%js/user/loginTokens.js", "%PATH_ASSETS%js/user/loginTokens.js",