-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.demoji.js
43 lines (41 loc) · 1.38 KB
/
jquery.demoji.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* demoji.js | (c) 2015 | https://github.com/jadwigo/demoji.js */
/**
* This script will rewrite the input of all input[type=text] and textarea fields when a form is submitted.
* If any emojis are found in the submitted value, this script will replace it for a shortcode.
*
* You need to add jQuery and the following codes to the head of your page too.
<script src="//cdn.jsdelivr.net/emojione/1.5.0/lib/js/emojione.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/emojione/1.5.0/assets/css/emojione.min.css"/>
*
* Emoji provided free by http://emojione.com/
*/
(function($) {
$.fn.demoji = function() {
return this.each(function() {
$('input[type=text], textarea').each(function(){
if ('undefined' != $(this).val() && $(this).val() != '') {
$(this).val(emojione.toShort($(this).val()));
}
});
});
};
$.fn.remoji = function() {
return this.each(function() {
var input = $(this).html();
var output = emojione.toImage(input);
$(this).html(output);
});
};
}(jQuery));
jQuery(document).ready(function($) {
// convert emoji to shortcodes
$('form').submit (function(e) {
$(this).demoji();
});
// and make images from the emoji shortcodes in your html
// but only convert elements that have the class '.hasemoji'
// you can also add other classes or selectors
$('.hasemoji', 'body').each(function(e) {
$(this).remoji();
});
});