plugin.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.0.1 (2019-02-21)
  8. */
  9. (function () {
  10. var legacyoutput = (function () {
  11. 'use strict';
  12. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  13. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  14. var getFontSizeFormats = function (editor) {
  15. return editor.getParam('fontsize_formats');
  16. };
  17. var setFontSizeFormats = function (editor, fontsize_formats) {
  18. editor.settings.fontsize_formats = fontsize_formats;
  19. };
  20. var getFontFormats = function (editor) {
  21. return editor.getParam('font_formats');
  22. };
  23. var setFontFormats = function (editor, font_formats) {
  24. editor.settings.font_formats = font_formats;
  25. };
  26. var getFontSizeStyleValues = function (editor) {
  27. return editor.getParam('font_size_style_values');
  28. };
  29. var setInlineStyles = function (editor, inline_styles) {
  30. editor.settings.inline_styles = inline_styles;
  31. };
  32. var Settings = {
  33. getFontFormats: getFontFormats,
  34. getFontSizeFormats: getFontSizeFormats,
  35. setFontSizeFormats: setFontSizeFormats,
  36. setFontFormats: setFontFormats,
  37. getFontSizeStyleValues: getFontSizeStyleValues,
  38. setInlineStyles: setInlineStyles
  39. };
  40. var overrideFormats = function (editor) {
  41. var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', fontSizes = global$1.explode(Settings.getFontSizeStyleValues(editor)), schema = editor.schema;
  42. editor.formatter.register({
  43. alignleft: {
  44. selector: alignElements,
  45. attributes: { align: 'left' }
  46. },
  47. aligncenter: {
  48. selector: alignElements,
  49. attributes: { align: 'center' }
  50. },
  51. alignright: {
  52. selector: alignElements,
  53. attributes: { align: 'right' }
  54. },
  55. alignjustify: {
  56. selector: alignElements,
  57. attributes: { align: 'justify' }
  58. },
  59. bold: [
  60. {
  61. inline: 'b',
  62. remove: 'all'
  63. },
  64. {
  65. inline: 'strong',
  66. remove: 'all'
  67. },
  68. {
  69. inline: 'span',
  70. styles: { fontWeight: 'bold' }
  71. }
  72. ],
  73. italic: [
  74. {
  75. inline: 'i',
  76. remove: 'all'
  77. },
  78. {
  79. inline: 'em',
  80. remove: 'all'
  81. },
  82. {
  83. inline: 'span',
  84. styles: { fontStyle: 'italic' }
  85. }
  86. ],
  87. underline: [
  88. {
  89. inline: 'u',
  90. remove: 'all'
  91. },
  92. {
  93. inline: 'span',
  94. styles: { textDecoration: 'underline' },
  95. exact: true
  96. }
  97. ],
  98. strikethrough: [
  99. {
  100. inline: 'strike',
  101. remove: 'all'
  102. },
  103. {
  104. inline: 'span',
  105. styles: { textDecoration: 'line-through' },
  106. exact: true
  107. }
  108. ],
  109. fontname: {
  110. inline: 'font',
  111. attributes: { face: '%value' }
  112. },
  113. fontsize: {
  114. inline: 'font',
  115. attributes: {
  116. size: function (vars) {
  117. return global$1.inArray(fontSizes, vars.value) + 1;
  118. }
  119. }
  120. },
  121. forecolor: {
  122. inline: 'font',
  123. attributes: { color: '%value' }
  124. },
  125. hilitecolor: {
  126. inline: 'font',
  127. styles: { backgroundColor: '%value' }
  128. }
  129. });
  130. global$1.each('b,i,u,strike'.split(','), function (name) {
  131. schema.addValidElements(name + '[*]');
  132. });
  133. if (!schema.getElementRule('font')) {
  134. schema.addValidElements('font[face|size|color|style]');
  135. }
  136. global$1.each(alignElements.split(','), function (name) {
  137. var rule = schema.getElementRule(name);
  138. if (rule) {
  139. if (!rule.attributes.align) {
  140. rule.attributes.align = {};
  141. rule.attributesOrder.push('align');
  142. }
  143. }
  144. });
  145. };
  146. var overrideSettings = function (editor) {
  147. var defaultFontsizeFormats = '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7';
  148. 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';
  149. Settings.setInlineStyles(editor, false);
  150. if (!Settings.getFontSizeFormats(editor)) {
  151. Settings.setFontSizeFormats(editor, defaultFontsizeFormats);
  152. }
  153. if (!Settings.getFontFormats(editor)) {
  154. Settings.setFontFormats(editor, defaultFontsFormats);
  155. }
  156. };
  157. var setup = function (editor) {
  158. overrideSettings(editor);
  159. editor.on('init', function () {
  160. return overrideFormats(editor);
  161. });
  162. };
  163. var Formats = { setup: setup };
  164. global.add('legacyoutput', function (editor) {
  165. Formats.setup(editor);
  166. });
  167. function Plugin () {
  168. }
  169. return Plugin;
  170. }());
  171. })();