trumbowyg.template.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (function ($) {
  2. 'use strict';
  3. // Adds the language variables
  4. $.extend(true, $.trumbowyg, {
  5. langs: {
  6. en: {
  7. template: 'Template'
  8. },
  9. da: {
  10. template: 'Skabelon'
  11. },
  12. fr: {
  13. template: 'Patron'
  14. },
  15. nl: {
  16. template: 'Sjabloon'
  17. },
  18. ru: {
  19. template: 'Шаблон'
  20. },
  21. ja: {
  22. template: 'テンプレート'
  23. },
  24. tr: {
  25. template: 'Şablon'
  26. },
  27. zh_tw: {
  28. template: '模板',
  29. },
  30. }
  31. });
  32. // Adds the extra button definition
  33. $.extend(true, $.trumbowyg, {
  34. plugins: {
  35. template: {
  36. shouldInit: function (trumbowyg) {
  37. return trumbowyg.o.plugins.hasOwnProperty('templates');
  38. },
  39. init: function (trumbowyg) {
  40. trumbowyg.addBtnDef('template', {
  41. dropdown: templateSelector(trumbowyg),
  42. hasIcon: false,
  43. text: trumbowyg.lang.template
  44. });
  45. }
  46. }
  47. }
  48. });
  49. // Creates the template-selector dropdown.
  50. function templateSelector(trumbowyg) {
  51. var available = trumbowyg.o.plugins.templates;
  52. var templates = [];
  53. $.each(available, function (index, template) {
  54. trumbowyg.addBtnDef('template_' + index, {
  55. fn: function () {
  56. trumbowyg.html(template.html);
  57. },
  58. hasIcon: false,
  59. title: template.name
  60. });
  61. templates.push('template_' + index);
  62. });
  63. return templates;
  64. }
  65. })(jQuery);