Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var emoji = {
- binary_store: {},
- convert: function(str, raw) {
- var ret = [], img;
- for (var i = 0, c; c = str.charCodeAt(i); i++) {
- if (
- 0xE63E <= c && c <= 0xE6A5 ||
- 0xE6AC <= c && c <= 0xE6AE ||
- 0xE6B1 <= c && c <= 0xE6B3 ||
- 0xE6B7 <= c && c <= 0xE6BA ||
- 0xE6CE <= c && c <= 0xE70B ||
- 0xE70C <= c && c <= 0xE757
- ) {
- emoji.binary_store[c] = str.charAt(i);
- img = '<img src="/images/emoji/'+c+'.gif" alt="" width="12" height="12" class="emoji-'+c+'"/>';
- if ($.browser.msie && !raw)
- img = ['<wbr/>', img, '<wbr/>'].join(''); // [IE] wbr
- ret.push(img);
- }
- else
- ret.push(str.charAt(i));
- }
- return ret.join('');
- }
- };
- var EmojiTextarea = function() {};
- EmojiTextarea.prototype = {
- container: null,
- appendTo: function(selector, str, attrs) {
- this.container = $('<div class="emoji-textarea textbox"/>')
- .attr($.extend(attrs, {
- contentEditable: true
- }, attrs))
- .appendTo(selector)
- .html(emoji.convert(str, true));
- return this.container;
- },
- val: function() {
- if (!this.container) return '';
- var str = this.container.clone();
- $('img', str).each(function() {
- var img = $(this);
- if (/emoji-(\d+)/.test(img.attr('class')))
- img.replaceWith(emoji.binary_store[RegExp.$1]);
- });
- return str.text();
- }
- };
Add Comment
Please, Sign In to add comment