plugin.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. (function () {
  2. var legacyoutput = (function () {
  3. 'use strict';
  4. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  5. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  6. var overrideFormats = function (editor) {
  7. var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', fontSizes = global$1.explode(editor.settings.font_size_style_values), schema = editor.schema;
  8. editor.formatter.register({
  9. alignleft: {
  10. selector: alignElements,
  11. attributes: { align: 'left' }
  12. },
  13. aligncenter: {
  14. selector: alignElements,
  15. attributes: { align: 'center' }
  16. },
  17. alignright: {
  18. selector: alignElements,
  19. attributes: { align: 'right' }
  20. },
  21. alignjustify: {
  22. selector: alignElements,
  23. attributes: { align: 'justify' }
  24. },
  25. bold: [
  26. {
  27. inline: 'b',
  28. remove: 'all'
  29. },
  30. {
  31. inline: 'strong',
  32. remove: 'all'
  33. },
  34. {
  35. inline: 'span',
  36. styles: { fontWeight: 'bold' }
  37. }
  38. ],
  39. italic: [
  40. {
  41. inline: 'i',
  42. remove: 'all'
  43. },
  44. {
  45. inline: 'em',
  46. remove: 'all'
  47. },
  48. {
  49. inline: 'span',
  50. styles: { fontStyle: 'italic' }
  51. }
  52. ],
  53. underline: [
  54. {
  55. inline: 'u',
  56. remove: 'all'
  57. },
  58. {
  59. inline: 'span',
  60. styles: { textDecoration: 'underline' },
  61. exact: true
  62. }
  63. ],
  64. strikethrough: [
  65. {
  66. inline: 'strike',
  67. remove: 'all'
  68. },
  69. {
  70. inline: 'span',
  71. styles: { textDecoration: 'line-through' },
  72. exact: true
  73. }
  74. ],
  75. fontname: {
  76. inline: 'font',
  77. attributes: { face: '%value' }
  78. },
  79. fontsize: {
  80. inline: 'font',
  81. attributes: {
  82. size: function (vars) {
  83. return global$1.inArray(fontSizes, vars.value) + 1;
  84. }
  85. }
  86. },
  87. forecolor: {
  88. inline: 'font',
  89. attributes: { color: '%value' }
  90. },
  91. hilitecolor: {
  92. inline: 'font',
  93. styles: { backgroundColor: '%value' }
  94. }
  95. });
  96. global$1.each('b,i,u,strike'.split(','), function (name) {
  97. schema.addValidElements(name + '[*]');
  98. });
  99. if (!schema.getElementRule('font')) {
  100. schema.addValidElements('font[face|size|color|style]');
  101. }
  102. global$1.each(alignElements.split(','), function (name) {
  103. var rule = schema.getElementRule(name);
  104. if (rule) {
  105. if (!rule.attributes.align) {
  106. rule.attributes.align = {};
  107. rule.attributesOrder.push('align');
  108. }
  109. }
  110. });
  111. };
  112. var setup = function (editor) {
  113. editor.settings.inline_styles = false;
  114. editor.on('init', function () {
  115. overrideFormats(editor);
  116. });
  117. };
  118. var $_34p1gyfnjkmcwp7q = { setup: setup };
  119. var register = function (editor) {
  120. editor.addButton('fontsizeselect', function () {
  121. var items = [], defaultFontsizeFormats = '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7';
  122. var fontsizeFormats = editor.settings.fontsizeFormats || defaultFontsizeFormats;
  123. editor.$.each(fontsizeFormats.split(' '), function (i, item) {
  124. var text = item, value = item;
  125. var values = item.split('=');
  126. if (values.length > 1) {
  127. text = values[0];
  128. value = values[1];
  129. }
  130. items.push({
  131. text: text,
  132. value: value
  133. });
  134. });
  135. return {
  136. type: 'listbox',
  137. text: 'Font Sizes',
  138. tooltip: 'Font Sizes',
  139. values: items,
  140. fixedWidth: true,
  141. onPostRender: function () {
  142. var self = this;
  143. editor.on('NodeChange', function () {
  144. var fontElm;
  145. fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
  146. if (fontElm) {
  147. self.value(fontElm.size);
  148. } else {
  149. self.value('');
  150. }
  151. });
  152. },
  153. onclick: function (e) {
  154. if (e.control.settings.value) {
  155. editor.execCommand('FontSize', false, e.control.settings.value);
  156. }
  157. }
  158. };
  159. });
  160. editor.addButton('fontselect', function () {
  161. function createFormats(formats) {
  162. formats = formats.replace(/;$/, '').split(';');
  163. var i = formats.length;
  164. while (i--) {
  165. formats[i] = formats[i].split('=');
  166. }
  167. return formats;
  168. }
  169. 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';
  170. var items = [], fonts = createFormats(editor.settings.font_formats || defaultFontsFormats);
  171. editor.$.each(fonts, function (i, font) {
  172. items.push({
  173. text: { raw: font[0] },
  174. value: font[1],
  175. textStyle: font[1].indexOf('dings') === -1 ? 'font-family:' + font[1] : ''
  176. });
  177. });
  178. return {
  179. type: 'listbox',
  180. text: 'Font Family',
  181. tooltip: 'Font Family',
  182. values: items,
  183. fixedWidth: true,
  184. onPostRender: function () {
  185. var self = this;
  186. editor.on('NodeChange', function () {
  187. var fontElm;
  188. fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
  189. if (fontElm) {
  190. self.value(fontElm.face);
  191. } else {
  192. self.value('');
  193. }
  194. });
  195. },
  196. onselect: function (e) {
  197. if (e.control.settings.value) {
  198. editor.execCommand('FontName', false, e.control.settings.value);
  199. }
  200. }
  201. };
  202. });
  203. };
  204. var $_3yhahqfpjkmcwp7u = { register: register };
  205. global.add('legacyoutput', function (editor) {
  206. $_34p1gyfnjkmcwp7q.setup(editor);
  207. $_3yhahqfpjkmcwp7u.register(editor);
  208. });
  209. function Plugin () {
  210. }
  211. return Plugin;
  212. }());
  213. })();