jmadler / emoji-picker

Add a slick emoji selector to input fields and textareas on your website.
Other
1.31k stars 318 forks source link

How to show emoji on p / span tag #134

Open fammifarendra opened 5 years ago

fammifarendra commented 5 years ago

We create emoji then save it to db, after that how to show the emoji that we saved into p or span tag ?

fammifarendra commented 5 years ago

there's no further explanation on this, so i try myself and create js function

function showsmiley( input) { var k, len, split_on_unicode, text, val; if (!input) { return ''; } if (!Config.rx_codes) { Config.init_unified(); } split_on_unicode = input.split(Config.rx_codes); for (k = 0, len = split_on_unicode.length; k < len; k++) { text = split_on_unicode[k]; val = ''; if (Config.rx_codes.test(text)) { val = Config.reversemap[text]; if (val) { val = ':' + val + ':'; val = $.emojiarea.createIcon($.emojiarea.icons[val]); } } else { // val = document.createTextNode(text); } // element.append(val); } return input.replace(Config.rx_codes, function(m) { var $img; val = Config.reversemap[m]; if (val) { val = ':' + val + ':'; $img = $.emojiarea.createIcon($.emojiarea.icons[val]); return $img; } else { return ''; } }); };

and this is how to call it showsmiley(yourunicodeinput);

patrick-mcdougle commented 5 years ago

Your database probably needs to be configured to accept 4 byte utf-8 characters. Here's the documentation for mysql.