plugin.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * plugin.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*global tinymce:true */
  11. tinymce.PluginManager.add('emoticons', function(editor, url) {
  12. var emoticons = [
  13. ["cool", "cry", "embarassed", "foot-in-mouth"],
  14. ["frown", "innocent", "kiss", "laughing"],
  15. ["money-mouth", "sealed", "smile", "surprised"],
  16. ["tongue-out", "undecided", "wink", "yell"]
  17. ];
  18. function getHtml() {
  19. var emoticonsHtml;
  20. emoticonsHtml = '<table role="list" class="mce-grid">';
  21. tinymce.each(emoticons, function(row) {
  22. emoticonsHtml += '<tr>';
  23. tinymce.each(row, function(icon) {
  24. var emoticonUrl = url + '/img/smiley-' + icon + '.gif';
  25. emoticonsHtml += '<td><a href="#" data-mce-url="' + emoticonUrl + '" data-mce-alt="' + icon + '" tabindex="-1" ' +
  26. 'role="option" aria-label="' + icon + '"><img src="' +
  27. emoticonUrl + '" style="width: 18px; height: 18px" role="presentation" /></a></td>';
  28. });
  29. emoticonsHtml += '</tr>';
  30. });
  31. emoticonsHtml += '</table>';
  32. return emoticonsHtml;
  33. }
  34. editor.addButton('emoticons', {
  35. type: 'panelbutton',
  36. panel: {
  37. role: 'application',
  38. autohide: true,
  39. html: getHtml,
  40. onclick: function(e) {
  41. var linkElm = editor.dom.getParent(e.target, 'a');
  42. if (linkElm) {
  43. editor.insertContent(
  44. '<img src="' + linkElm.getAttribute('data-mce-url') + '" alt="' + linkElm.getAttribute('data-mce-alt') + '" />'
  45. );
  46. this.hide();
  47. }
  48. }
  49. },
  50. tooltip: 'Emoticons'
  51. });
  52. });