plugin.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.9.1 (2021-08-27)
  8. */
  9. (function () {
  10. 'use strict';
  11. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var global = 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 overrideFormats = function (editor) {
  32. var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table', fontSizes = global.explode(getFontSizeStyleValues(editor)), schema = editor.schema;
  33. editor.formatter.register({
  34. alignleft: {
  35. selector: alignElements,
  36. attributes: { align: 'left' }
  37. },
  38. aligncenter: {
  39. selector: alignElements,
  40. attributes: { align: 'center' }
  41. },
  42. alignright: {
  43. selector: alignElements,
  44. attributes: { align: 'right' }
  45. },
  46. alignjustify: {
  47. selector: alignElements,
  48. attributes: { align: 'justify' }
  49. },
  50. bold: [
  51. {
  52. inline: 'b',
  53. remove: 'all',
  54. preserve_attributes: [
  55. 'class',
  56. 'style'
  57. ]
  58. },
  59. {
  60. inline: 'strong',
  61. remove: 'all',
  62. preserve_attributes: [
  63. 'class',
  64. 'style'
  65. ]
  66. },
  67. {
  68. inline: 'span',
  69. styles: { fontWeight: 'bold' }
  70. }
  71. ],
  72. italic: [
  73. {
  74. inline: 'i',
  75. remove: 'all',
  76. preserve_attributes: [
  77. 'class',
  78. 'style'
  79. ]
  80. },
  81. {
  82. inline: 'em',
  83. remove: 'all',
  84. preserve_attributes: [
  85. 'class',
  86. 'style'
  87. ]
  88. },
  89. {
  90. inline: 'span',
  91. styles: { fontStyle: 'italic' }
  92. }
  93. ],
  94. underline: [
  95. {
  96. inline: 'u',
  97. remove: 'all',
  98. preserve_attributes: [
  99. 'class',
  100. 'style'
  101. ]
  102. },
  103. {
  104. inline: 'span',
  105. styles: { textDecoration: 'underline' },
  106. exact: true
  107. }
  108. ],
  109. strikethrough: [
  110. {
  111. inline: 'strike',
  112. remove: 'all',
  113. preserve_attributes: [
  114. 'class',
  115. 'style'
  116. ]
  117. },
  118. {
  119. inline: 'span',
  120. styles: { textDecoration: 'line-through' },
  121. exact: true
  122. }
  123. ],
  124. fontname: {
  125. inline: 'font',
  126. toggle: false,
  127. attributes: { face: '%value' }
  128. },
  129. fontsize: {
  130. inline: 'font',
  131. toggle: false,
  132. attributes: {
  133. size: function (vars) {
  134. return String(global.inArray(fontSizes, vars.value) + 1);
  135. }
  136. }
  137. },
  138. forecolor: {
  139. inline: 'font',
  140. attributes: { color: '%value' },
  141. links: true,
  142. remove_similar: true,
  143. clear_child_styles: true
  144. },
  145. hilitecolor: {
  146. inline: 'font',
  147. styles: { backgroundColor: '%value' },
  148. links: true,
  149. remove_similar: true,
  150. clear_child_styles: true
  151. }
  152. });
  153. global.each('b,i,u,strike'.split(','), function (name) {
  154. schema.addValidElements(name + '[*]');
  155. });
  156. if (!schema.getElementRule('font')) {
  157. schema.addValidElements('font[face|size|color|style]');
  158. }
  159. global.each(alignElements.split(','), function (name) {
  160. var rule = schema.getElementRule(name);
  161. if (rule) {
  162. if (!rule.attributes.align) {
  163. rule.attributes.align = {};
  164. rule.attributesOrder.push('align');
  165. }
  166. }
  167. });
  168. };
  169. var overrideSettings = function (editor) {
  170. var defaultFontsizeFormats = '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7';
  171. 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';
  172. setInlineStyles(editor, false);
  173. if (!getFontSizeFormats(editor)) {
  174. setFontSizeFormats(editor, defaultFontsizeFormats);
  175. }
  176. if (!getFontFormats(editor)) {
  177. setFontFormats(editor, defaultFontsFormats);
  178. }
  179. };
  180. var setup = function (editor) {
  181. overrideSettings(editor);
  182. editor.on('PreInit', function () {
  183. return overrideFormats(editor);
  184. });
  185. };
  186. function Plugin () {
  187. global$1.add('legacyoutput', function (editor) {
  188. console.warn('The legacyoutput plugin has been deprecated and marked for removal in TinyMCE 6.0');
  189. setup(editor);
  190. });
  191. }
  192. Plugin();
  193. }());