Snippet · Mecha CMS

Code snippet collection for developers.

Emoji in Comment Form

Author: Taufik Nurrohman · 505 Views

Tweet

Add minimalist native emoji insertion helper in the comment form.

1

Requires comment extension.

Hook::set('asset:body', function($content) use($site) {
    if ($site->is !== 'page') return $content;
    return '<script>!function(e,n){function t(){var e=i.value,n=i.selectionStart,t=i.selectionEnd,r=this.innerHTML;i.value=e.substring(0,n)+r+e.substring(t),i.setSelectionRange(n+r.length,t+r.length),i.focus()}var i,r=n.querySelector("#' . Extend::state('comment', 'anchor', [1 => 'form-comment'])[1] . '");if(r&&(i=r.content)){var l=n.createElement("p"),a=l.style;a.fontSize="110%",a.marginLeft="-.25em",a.marginRight="-.25em";var o,c,s="\uD83D\uDE00 \uD83D\uDE01 \uD83D\uDE02 \uD83D\uDE03 \uD83D\uDE04 \uD83D\uDE05 \uD83D\uDE06 \uD83D\uDE09 \uD83D\uDE0A \uD83D\uDE0B \uD83D\uDE0E \uD83D\uDE0D \uD83D\uDE18 \uD83D\uDE17 \uD83D\uDE19 \uD83D\uDE1A \uD83D\uDE10 \uD83D\uDE11 \uD83D\uDE36 \uD83D\uDE0F \uD83D\uDE23 \uD83D\uDE25 \uD83D\uDE2E \uD83D\uDE2F \uD83D\uDE2A \uD83D\uDE2B \uD83D\uDE34 \uD83D\uDE0C \uD83D\uDE1B \uD83D\uDE1C \uD83D\uDE1D \uD83D\uDE12 \uD83D\uDE13 \uD83D\uDE14 \uD83D\uDE15 \uD83D\uDE16 \uD83D\uDE1E \uD83D\uDE1F \uD83D\uDE24 \uD83D\uDE22 \uD83D\uDE2D \uD83D\uDE26 \uD83D\uDE27 \uD83D\uDE28 \uD83D\uDE29 \uD83D\uDE2C \uD83D\uDE30 \uD83D\uDE31 \uD83D\uDE33 \uD83D\uDE35 \uD83D\uDE21 \uD83D\uDE20 \uD83D\uDE07 \uD83D\uDE37".split(" ");for(o=0,c=s.length;c>o;++o){var a=n.createElement("span"),m=a.style;m.cursor="pointer",m.display="inline-block",m.width=m.height="1.5em",m.verticalAlign="middle",m.textAlign="center",a.onclick=t,a.innerHTML=s[o],l.appendChild(a)}i.parentNode.appendChild(l)}}(window,document);</script>' . $content;
});

2 Comments

  • Alexander Liebrecht

    I have just inserted the hook in the index.php of the Shield “normal”. Unfortunately the eMojis are not displayed.

    What am I doing wrong?

    Thanks in advance.

    • Taufik Nurrohman

      Works just fine for me.