...
Code Block | ||
---|---|---|
| ||
LIVECHATSDK.LIVECHAT.emojiShortNamesSDK.getEmojiShortcut().then( function(EmojiShortcutClass) { // Deep copy into new object window.Emoji_by_ShortName = jQuery.extend(true, {}, EmojiShortcutClass); } ); |
...
Using a regular expression pattern we can define a special sequence of characters (like : shortname:) to search and replace with the equivalent emoji stored in the LIVECHATSDK.LIVECHAT.emojiShortNames
hash.
...
Code Block | ||
---|---|---|
| ||
jQuery("#mytextarea#myTextArea").on("change keyup", function() { var text = jQuery("#mytextarea#myTextArea").val(); text = text.replace( // Regular Expression: search for :shortname: or shortcut (':-)', ':)', ...) new RegExp("(\\:\\w+):$/gi\\:)$|(.{2,3}\\ )$", "gi"), function(all, code) {(match) { console.log("[CTLIVE] Emoji match", match); if (typeof Emoji_by_ShortName[ match.replace(/\:/g, "") ] !== "undefined") { return Emoji_by_ShortName[ match.replace(/\:/g, "") ]; } else if (typeof Emoji Match_by_ShortName[ match.trim() ] !== "undefined") { return LIVECHATSDK.LIVECHAT.emojiShortNames[code] || code " " + Emoji_by_ShortName[ match.trim() ] + " "; } else { return match; } } ); jQuery("#mytextarea#myTextArea").val( text ); } ); |