trumbowyg.specialchars.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* ===========================================================
  2. * trumbowyg.specialchars.js v0.99
  3. * Unicode characters picker plugin for Trumbowyg
  4. * http://alex-d.github.com/Trumbowyg
  5. * ===========================================================
  6. * Author : Renaud Hoyoux (geektortoise)
  7. */
  8. (function ($) {
  9. 'use strict';
  10. var defaultOptions = {
  11. symbolList: [
  12. // currencies
  13. '0024', '20AC', '00A3', '00A2', '00A5', '00A4', '2030', null,
  14. // legal signs
  15. '00A9', '00AE', '2122', null,
  16. // textual sign
  17. '00A7', '00B6', '00C6', '00E6', '0152', '0153', null,
  18. '2022', '25CF', '2023', '25B6', '2B29', '25C6', null,
  19. //maths
  20. '00B1', '00D7', '00F7', '21D2', '21D4', '220F', '2211', '2243', '2264', '2265'
  21. ]
  22. };
  23. $.extend(true, $.trumbowyg, {
  24. langs: {
  25. en: {
  26. specialChars: 'Special characters'
  27. },
  28. fr: {
  29. specialChars: 'Caractères spéciaux'
  30. },
  31. hu: {
  32. specialChars: 'Speciális karakterek'
  33. },
  34. ko: {
  35. specialChars: '특수문자'
  36. },
  37. },
  38. plugins: {
  39. specialchars: {
  40. init: function (trumbowyg) {
  41. trumbowyg.o.plugins.specialchars = trumbowyg.o.plugins.specialchars || defaultOptions;
  42. var specialCharsBtnDef = {
  43. dropdown: buildDropdown(trumbowyg)
  44. };
  45. trumbowyg.addBtnDef('specialChars', specialCharsBtnDef);
  46. }
  47. }
  48. }
  49. });
  50. function buildDropdown(trumbowyg) {
  51. var dropdown = [];
  52. $.each(trumbowyg.o.plugins.specialchars.symbolList, function (i, symbol) {
  53. if (symbol === null) {
  54. symbol = '&nbsp';
  55. } else {
  56. symbol = '&#x' + symbol;
  57. }
  58. var btn = symbol.replace(/:/g, ''),
  59. defaultSymbolBtnName = 'symbol-' + btn,
  60. defaultSymbolBtnDef = {
  61. text: symbol,
  62. hasIcon: false,
  63. fn: function () {
  64. var encodedSymbol = String.fromCodePoint(parseInt(symbol.replace('&#', '0')));
  65. trumbowyg.execCmd('insertText', encodedSymbol);
  66. return true;
  67. }
  68. };
  69. trumbowyg.addBtnDef(defaultSymbolBtnName, defaultSymbolBtnDef);
  70. dropdown.push(defaultSymbolBtnName);
  71. });
  72. return dropdown;
  73. }
  74. })(jQuery);