Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
LIVECHATSDK.LIVECHAT.emojiShortNames

...

SDK.getEmojiShortcut().then(
  function(EmojiShortcutClass) {
    // Deep copy into new object
    window.Emoji_by_ShortName = jQuery.extend(true, {}, EmojiShortcutClass);
  }
);

...

Download the complete JSON Emoji shortnames and shortcuts file by clicking on the following box:

View file
nameemoji_shortcut.js

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 Emoji_by_ShortName hash.

The following code search for any shortname that matches the last typed word with preceding and following “:” character. Example :grinning_face: (big grin)

Code Block
languagejs
// Match <shortcut> + space
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+\\:)$|(.{2,3}\\ )$", "gi"),
      function(match) {
        //console.log("[CTLIVE] Emoji Match match", match);
        if (typeof LIVECHATSDK.LIVECHAT.emojiShortNamesEmoji_by_ShortName[ match.replace(/\:/g, "") ] !== "undefined") {
          return LIVECHATSDK.LIVECHAT.emojiShortNamesEmoji_by_ShortName[ match.replace(/\:/g, "") ];
        } else if (typeof Emoji_by_ShortName[ match.trim() ] !== "undefined") {
          return " " + Emoji_by_ShortName[ match.trim() ] + " ";
        } else {
          return match;
        }
      }
    );
    jQuery("#mytextarea#myTextArea").val( text );
  }
);

// Match <shortcut> + new line
jQuery("#myTextArea").on("keydown", 
  function(e){
    if (e.which == 13) {
    }
  }
);