trumbowyg.fontfamily.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function ($) {
  2. 'use strict';
  3. $.extend(true, $.trumbowyg, {
  4. langs: {
  5. // jshint camelcase:false
  6. en: {
  7. fontFamily: 'Font'
  8. },
  9. da: {
  10. fontFamily: 'Skrifttype'
  11. },
  12. fr: {
  13. fontFamily: 'Police'
  14. },
  15. de: {
  16. fontFamily: 'Schriftart'
  17. },
  18. nl: {
  19. fontFamily: 'Lettertype'
  20. },
  21. tr: {
  22. fontFamily: 'Yazı Tipi'
  23. },
  24. zh_tw:{
  25. fontFamily: '字體',
  26. }
  27. }
  28. });
  29. // jshint camelcase:true
  30. var defaultOptions = {
  31. fontList: [
  32. {name: 'Arial', family: 'Arial, Helvetica, sans-serif'},
  33. {name: 'Arial Black', family: '\'Arial Black\', Gadget, sans-serif'},
  34. {name: 'Comic Sans', family: '\'Comic Sans MS\', Textile, cursive, sans-serif'},
  35. {name: 'Courier New', family: '\'Courier New\', Courier, monospace'},
  36. {name: 'Georgia', family: 'Georgia, serif'},
  37. {name: 'Impact', family: 'Impact, Charcoal, sans-serif'},
  38. {name: 'Lucida Console', family: '\'Lucida Console\', Monaco, monospace'},
  39. {name: 'Lucida Sans', family: '\'Lucida Sans Uncide\', \'Lucida Grande\', sans-serif'},
  40. {name: 'Palatino', family: '\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif'},
  41. {name: 'Tahoma', family: 'Tahoma, Geneva, sans-serif'},
  42. {name: 'Times New Roman', family: '\'Times New Roman\', Times, serif'},
  43. {name: 'Trebuchet', family: '\'Trebuchet MS\', Helvetica, sans-serif'},
  44. {name: 'Verdana', family: 'Verdana, Geneva, sans-serif'}
  45. ]
  46. };
  47. // Add dropdown with web safe fonts
  48. $.extend(true, $.trumbowyg, {
  49. plugins: {
  50. fontfamily: {
  51. init: function (trumbowyg) {
  52. trumbowyg.o.plugins.fontfamily = trumbowyg.o.plugins.fontfamily || defaultOptions;
  53. trumbowyg.addBtnDef('fontfamily', {
  54. dropdown: buildDropdown(trumbowyg),
  55. hasIcon: false,
  56. text: trumbowyg.lang.fontFamily
  57. });
  58. }
  59. }
  60. }
  61. });
  62. function buildDropdown(trumbowyg) {
  63. var dropdown = [];
  64. $.each(trumbowyg.o.plugins.fontfamily.fontList, function (index, font) {
  65. trumbowyg.addBtnDef('fontfamily_' + index, {
  66. title: '<span style="font-family: ' + font.family + ';">' + font.name + '</span>',
  67. hasIcon: false,
  68. fn: function () {
  69. trumbowyg.execCmd('fontName', font.family, true);
  70. }
  71. });
  72. dropdown.push('fontfamily_' + index);
  73. });
  74. return dropdown;
  75. }
  76. })(jQuery);