O HTML 5 possui uma lista de entities (caracteres especiais) na qual inclui algumas figuras semelhantes aos conhecidos รญcones de emojis.
O site que mais gosto de consultar รฉ este: https://apps.timwhitlock.info/emoji/tables/unicode
Outro site bem legal รฉ esse outro aqui: https://getemoji.com/
Ao acessar a pรกgina vocรช irรก perceber o quanto extensa รฉ a lista de entities. Com base nesta lista vamos criar um caixa de texto que aceite estes caracteres especiais, podemos usar o DOM do Javascript ou jQuery.
Criando o textarea
O documento que iremos programar possui apenas um form, um textarea e vรกrios botรตes de emoji. Vamos ao cรณdigo! Note que eu uso BootStrap 4, veja o template padrรฃo aqui: https://getbootstrap.com/docs/4.0/getting-started/introduction/#starter-template
<!doctype html> <html lang="pt-br"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <title>Textarea com emojis</title> </head> <body> <div class="container"> <div class="row"> <h1>SuperChat</h1> </div> <div class="row"> <textarea class="form-control" id="conteudo" rows="3"></textarea> </div> <div class="row"> <!-- Fonte: https://apps.timwhitlock.info/emoji/tables/unicode IMPORTANTE! Copie os emojis da coluna NATIVE --> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐ </button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐ </button> <button type="button" class="btn btn-sm">๐ข</button> <button type="button" class="btn btn-sm">๐ค</button> <button type="button" class="btn btn-sm">๐ฅ</button> <button type="button" class="btn btn-sm">๐จ</button> <button type="button" class="btn btn-sm">๐ฉ</button> <button type="button" class="btn btn-sm">๐ช</button> <button type="button" class="btn btn-sm">๐ซ</button> <button type="button" class="btn btn-sm">๐ญ</button> <button type="button" class="btn btn-sm">๐ฐ</button> <button type="button" class="btn btn-sm">๐ฑ</button> <button type="button" class="btn btn-sm">๐ฒ</button> <button type="button" class="btn btn-sm">๐ณ</button> <button type="button" class="btn btn-sm">๐ต</button> <button type="button" class="btn btn-sm">๐ท</button> <button type="button" class="btn btn-sm">๐ธ</button> <button type="button" class="btn btn-sm">๐น</button> <button type="button" class="btn btn-sm">๐บ</button> <button type="button" class="btn btn-sm">๐ป</button> <button type="button" class="btn btn-sm">๐ผ</button> <button type="button" class="btn btn-sm">๐ฝ</button> <button type="button" class="btn btn-sm">๐พ</button> <button type="button" class="btn btn-sm">๐ฟ</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐ </button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> <button type="button" class="btn btn-sm">๐</button> </div> </div> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> </body> </html>
Agora vamos programar as interaรงรตes JavaScript.
Funรงรฃo JS para colocar o emoji dentro do Textarea
Vamos escrever a seguinte funรงรฃo, que pode ser inserida antes do </body> do seu cรณdigo HTML:
<script> //usando jQuery, tudo fica mais fรกcil!! :) $("button").click(function() { var emoji = $( this ).text(); $('#conteudo').val($('#conteudo').val() + emoji); }); </script>
Pronto!
Download e teste
Faรงa o teste aqui: emoji. Para fazer o download, basta salvar a pรกgina, ou, exibir o cรณdigo fonte. Bons estudos!