plugin.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.10.2 (2021-11-17)
  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(
  27. 'font_size_style_values',
  28. 'xx-small,x-small,small,medium,large,x-large,xx-large'
  29. )
  30. }
  31. var setInlineStyles = function (editor, inline_styles) {
  32. editor.settings.inline_styles = inline_styles
  33. }
  34. var overrideFormats = function (editor) {
  35. var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table',
  36. fontSizes = global.explode(getFontSizeStyleValues(editor)),
  37. schema = editor.schema
  38. editor.formatter.register({
  39. alignleft: {
  40. selector: alignElements,
  41. attributes: { align: 'left' },
  42. },
  43. aligncenter: {
  44. selector: alignElements,
  45. attributes: { align: 'center' },
  46. },
  47. alignright: {
  48. selector: alignElements,
  49. attributes: { align: 'right' },
  50. },
  51. alignjustify: {
  52. selector: alignElements,
  53. attributes: { align: 'justify' },
  54. },
  55. bold: [
  56. {
  57. inline: 'b',
  58. remove: 'all',
  59. preserve_attributes: ['class', 'style'],
  60. },
  61. {
  62. inline: 'strong',
  63. remove: 'all',
  64. preserve_attributes: ['class', 'style'],
  65. },
  66. {
  67. inline: 'span',
  68. styles: { fontWeight: 'bold' },
  69. },
  70. ],
  71. italic: [
  72. {
  73. inline: 'i',
  74. remove: 'all',
  75. preserve_attributes: ['class', 'style'],
  76. },
  77. {
  78. inline: 'em',
  79. remove: 'all',
  80. preserve_attributes: ['class', 'style'],
  81. },
  82. {
  83. inline: 'span',
  84. styles: { fontStyle: 'italic' },
  85. },
  86. ],
  87. underline: [
  88. {
  89. inline: 'u',
  90. remove: 'all',
  91. preserve_attributes: ['class', 'style'],
  92. },
  93. {
  94. inline: 'span',
  95. styles: { textDecoration: 'underline' },
  96. exact: true,
  97. },
  98. ],
  99. strikethrough: [
  100. {
  101. inline: 'strike',
  102. remove: 'all',
  103. preserve_attributes: ['class', 'style'],
  104. },
  105. {
  106. inline: 'span',
  107. styles: { textDecoration: 'line-through' },
  108. exact: true,
  109. },
  110. ],
  111. fontname: {
  112. inline: 'font',
  113. toggle: false,
  114. attributes: { face: '%value' },
  115. },
  116. fontsize: {
  117. inline: 'font',
  118. toggle: false,
  119. attributes: {
  120. size: function (vars) {
  121. return String(global.inArray(fontSizes, vars.value) + 1)
  122. },
  123. },
  124. },
  125. forecolor: {
  126. inline: 'font',
  127. attributes: { color: '%value' },
  128. links: true,
  129. remove_similar: true,
  130. clear_child_styles: true,
  131. },
  132. hilitecolor: {
  133. inline: 'font',
  134. styles: { backgroundColor: '%value' },
  135. links: true,
  136. remove_similar: true,
  137. clear_child_styles: true,
  138. },
  139. })
  140. global.each('b,i,u,strike'.split(','), function (name) {
  141. schema.addValidElements(name + '[*]')
  142. })
  143. if (!schema.getElementRule('font')) {
  144. schema.addValidElements('font[face|size|color|style]')
  145. }
  146. global.each(alignElements.split(','), function (name) {
  147. var rule = schema.getElementRule(name)
  148. if (rule) {
  149. if (!rule.attributes.align) {
  150. rule.attributes.align = {}
  151. rule.attributesOrder.push('align')
  152. }
  153. }
  154. })
  155. }
  156. var overrideSettings = function (editor) {
  157. var defaultFontsizeFormats =
  158. '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7'
  159. var defaultFontsFormats =
  160. 'Andale Mono=andale mono,monospace;' +
  161. 'Arial=arial,helvetica,sans-serif;' +
  162. 'Arial Black=arial black,sans-serif;' +
  163. 'Book Antiqua=book antiqua,palatino,serif;' +
  164. 'Comic Sans MS=comic sans ms,sans-serif;' +
  165. 'Courier New=courier new,courier,monospace;' +
  166. 'Georgia=georgia,palatino,serif;' +
  167. 'Helvetica=helvetica,arial,sans-serif;' +
  168. 'Impact=impact,sans-serif;' +
  169. 'Symbol=symbol;' +
  170. 'Tahoma=tahoma,arial,helvetica,sans-serif;' +
  171. 'Terminal=terminal,monaco,monospace;' +
  172. 'Times New Roman=times new roman,times,serif;' +
  173. 'Trebuchet MS=trebuchet ms,geneva,sans-serif;' +
  174. 'Verdana=verdana,geneva,sans-serif;' +
  175. 'Webdings=webdings;' +
  176. 'Wingdings=wingdings,zapf dingbats'
  177. setInlineStyles(editor, false)
  178. if (!getFontSizeFormats(editor)) {
  179. setFontSizeFormats(editor, defaultFontsizeFormats)
  180. }
  181. if (!getFontFormats(editor)) {
  182. setFontFormats(editor, defaultFontsFormats)
  183. }
  184. }
  185. var setup = function (editor) {
  186. overrideSettings(editor)
  187. editor.on('PreInit', function () {
  188. return overrideFormats(editor)
  189. })
  190. }
  191. function Plugin() {
  192. global$1.add('legacyoutput', function (editor) {
  193. setup(editor)
  194. })
  195. }
  196. Plugin()
  197. })()