Guest User

Untitled

a guest
May 20th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. var emoji = {
  2. binary_store: {},
  3.  
  4. convert: function(str, raw) {
  5. var ret = [], img;
  6. for (var i = 0, c; c = str.charCodeAt(i); i++) {
  7. if (
  8. 0xE63E <= c && c <= 0xE6A5 ||
  9. 0xE6AC <= c && c <= 0xE6AE ||
  10. 0xE6B1 <= c && c <= 0xE6B3 ||
  11. 0xE6B7 <= c && c <= 0xE6BA ||
  12. 0xE6CE <= c && c <= 0xE70B ||
  13. 0xE70C <= c && c <= 0xE757
  14. ) {
  15. emoji.binary_store[c] = str.charAt(i);
  16. img = '<img src="/images/emoji/'+c+'.gif" alt="" width="12" height="12" class="emoji-'+c+'"/>';
  17. if ($.browser.msie && !raw)
  18. img = ['<wbr/>', img, '<wbr/>'].join(''); // [IE] wbr
  19. ret.push(img);
  20. }
  21. else
  22. ret.push(str.charAt(i));
  23. }
  24. return ret.join('');
  25. }
  26. };
  27.  
  28. var EmojiTextarea = function() {};
  29.  
  30. EmojiTextarea.prototype = {
  31. container: null,
  32.  
  33. appendTo: function(selector, str, attrs) {
  34. this.container = $('<div class="emoji-textarea textbox"/>')
  35. .attr($.extend(attrs, {
  36. contentEditable: true
  37. }, attrs))
  38. .appendTo(selector)
  39. .html(emoji.convert(str, true));
  40.  
  41. return this.container;
  42. },
  43.  
  44. val: function() {
  45. if (!this.container) return '';
  46. var str = this.container.clone();
  47. $('img', str).each(function() {
  48. var img = $(this);
  49. if (/emoji-(\d+)/.test(img.attr('class')))
  50. img.replaceWith(emoji.binary_store[RegExp.$1]);
  51. });
  52. return str.text();
  53. }
  54. };
Add Comment
Please, Sign In to add comment