plugin.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.2.0 (2020-02-13)
  8. */
  9. (function () {
  10. 'use strict';
  11. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  13. var getFontSizeFormats = function (editor) {
  14. return editor.getParam('fontsize_formats');
  15. };
  16. var setFontSizeFormats = function (editor, fontsize_formats) {
  17. editor.settings.fontsize_formats = fontsize_formats;
  18. };
  19. var getFontFormats = function (editor) {
  20. return editor.getParam('font_formats');
  21. };
  22. var setFontFormats = function (editor, font_formats) {
  23. editor.settings.font_formats = font_formats;
  24. };
  25. var getFontSizeStyleValues = function (editor) {
  26. return editor.getParam('font_size_style_values', 'xx-small,x-small,small,medium,large,x-large,xx-large');
  27. };
  28. var setInlineStyles = function (editor, inline_styles) {
  29. editor.settings.inline_styles = inline_styles;
  30. };
  31. var Settings = {
  32. getFontFormats: getFontFormats,
  33. getFontSizeFormats: getFontSizeFormats,
  34. setFontSizeFormats: setFontSizeFormats,
  35. setFontFormats: setFontFormats,
  36. getFontSizeStyleValues: getFontSizeStyleValues,
  37. setInlineStyles: setInlineStyles
  38. };
  39. var overrideFormats = function (editor) {
  40. var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table', fontSizes = global$1.explode(Settings.getFontSizeStyleValues(editor)), schema = editor.schema;
  41. editor.formatter.register({
  42. alignleft: {
  43. selector: alignElements,
  44. attributes: { align: 'left' }
  45. },
  46. aligncenter: {
  47. selector: alignElements,
  48. attributes: { align: 'center' }
  49. },
  50. alignright: {
  51. selector: alignElements,
  52. attributes: { align: 'right' }
  53. },
  54. alignjustify: {
  55. selector: alignElements,
  56. attributes: { align: 'justify' }
  57. },
  58. bold: [
  59. {
  60. inline: 'b',
  61. remove: 'all'
  62. },
  63. {
  64. inline: 'strong',
  65. remove: 'all'
  66. },
  67. {
  68. inline: 'span',
  69. styles: { fontWeight: 'bold' }
  70. }
  71. ],
  72. italic: [
  73. {
  74. inline: 'i',
  75. remove: 'all'
  76. },
  77. {
  78. inline: 'em',
  79. remove: 'all'
  80. },
  81. {
  82. inline: 'span',
  83. styles: { fontStyle: 'italic' }
  84. }
  85. ],
  86. underline: [
  87. {
  88. inline: 'u',
  89. remove: 'all'
  90. },
  91. {
  92. inline: 'span',
  93. styles: { textDecoration: 'underline' },
  94. exact: true
  95. }
  96. ],
  97. strikethrough: [
  98. {
  99. inline: 'strike',
  100. remove: 'all'
  101. },
  102. {
  103. inline: 'span',
  104. styles: { textDecoration: 'line-through' },
  105. exact: true
  106. }
  107. ],
  108. fontname: {
  109. inline: 'font',
  110. toggle: false,
  111. attributes: { face: '%value' }
  112. },
  113. fontsize: {
  114. inline: 'font',
  115. toggle: false,
  116. attributes: {
  117. size: function (vars) {
  118. return String(global$1.inArray(fontSizes, vars.value) + 1);
  119. }
  120. }
  121. },
  122. forecolor: {
  123. inline: 'font',
  124. attributes: { color: '%value' },
  125. links: true,
  126. remove_similar: true,
  127. clear_child_styles: true
  128. },
  129. hilitecolor: {
  130. inline: 'font',
  131. styles: { backgroundColor: '%value' },
  132. links: true,
  133. remove_similar: true,
  134. clear_child_styles: true
  135. }
  136. });
  137. global$1.each('b,i,u,strike'.split(','), function (name) {
  138. schema.addValidElements(name + '[*]');
  139. });
  140. if (!schema.getElementRule('font')) {
  141. schema.addValidElements('font[face|size|color|style]');
  142. }
  143. global$1.each(alignElements.split(','), function (name) {
  144. var rule = schema.getElementRule(name);
  145. if (rule) {
  146. if (!rule.attributes.align) {
  147. rule.attributes.align = {};
  148. rule.attributesOrder.push('align');
  149. }
  150. }
  151. });
  152. };
  153. var overrideSettings = function (editor) {
  154. var defaultFontsizeFormats = '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7';
  155. var defaultFontsFormats = 'Andale Mono=andale mono,monospace;' + 'Arial=arial,helvetica,sans-serif;' + 'Arial Black=arial black,sans-serif;' + 'Book Antiqua=book antiqua,palatino,serif;' + 'Comic Sans MS=comic sans ms,sans-serif;' + 'Courier New=courier new,courier,monospace;' + 'Georgia=georgia,palatino,serif;' + 'Helvetica=helvetica,arial,sans-serif;' + 'Impact=impact,sans-serif;' + 'Symbol=symbol;' + 'Tahoma=tahoma,arial,helvetica,sans-serif;' + 'Terminal=terminal,monaco,monospace;' + 'Times New Roman=times new roman,times,serif;' + 'Trebuchet MS=trebuchet ms,geneva,sans-serif;' + 'Verdana=verdana,geneva,sans-serif;' + 'Webdings=webdings;' + 'Wingdings=wingdings,zapf dingbats';
  156. Settings.setInlineStyles(editor, false);
  157. if (!Settings.getFontSizeFormats(editor)) {
  158. Settings.setFontSizeFormats(editor, defaultFontsizeFormats);
  159. }
  160. if (!Settings.getFontFormats(editor)) {
  161. Settings.setFontFormats(editor, defaultFontsFormats);
  162. }
  163. };
  164. var setup = function (editor) {
  165. overrideSettings(editor);
  166. editor.on('PreInit', function () {
  167. return overrideFormats(editor);
  168. });
  169. };
  170. var Formats = { setup: setup };
  171. function Plugin () {
  172. global.add('legacyoutput', function (editor) {
  173. Formats.setup(editor);
  174. });
  175. }
  176. Plugin();
  177. }());