plugin.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. const setContent = (editor, html) => {
  8. // We get a lovely "Wrong document" error in IE 11 if we
  9. // don't move the focus to the editor before creating an undo
  10. // transaction since it tries to make a bookmark for the current selection
  11. editor.focus();
  12. editor.undoManager.transact(() => {
  13. editor.setContent(html);
  14. });
  15. editor.selection.setCursorLocation();
  16. editor.nodeChanged();
  17. };
  18. const getContent = (editor) => {
  19. return editor.getContent({ source_view: true });
  20. };
  21. const open = (editor) => {
  22. const editorContent = getContent(editor);
  23. editor.windowManager.open({
  24. title: 'Source Code',
  25. size: 'large',
  26. body: {
  27. type: 'panel',
  28. items: [
  29. {
  30. type: 'textarea',
  31. name: 'code',
  32. spellcheck: false,
  33. }
  34. ]
  35. },
  36. buttons: [
  37. {
  38. type: 'cancel',
  39. name: 'cancel',
  40. text: 'Cancel'
  41. },
  42. {
  43. type: 'submit',
  44. name: 'save',
  45. text: 'Save',
  46. primary: true
  47. }
  48. ],
  49. initialData: {
  50. code: editorContent
  51. },
  52. onSubmit: (api) => {
  53. setContent(editor, api.getData().code);
  54. api.close();
  55. }
  56. });
  57. };
  58. const register$1 = (editor) => {
  59. editor.addCommand('mceCodeEditor', () => {
  60. open(editor);
  61. });
  62. };
  63. const register = (editor) => {
  64. const onAction = () => editor.execCommand('mceCodeEditor');
  65. editor.ui.registry.addButton('code', {
  66. icon: 'sourcecode',
  67. tooltip: 'Source code',
  68. onAction
  69. });
  70. editor.ui.registry.addMenuItem('code', {
  71. icon: 'sourcecode',
  72. text: 'Source code',
  73. onAction
  74. });
  75. };
  76. var Plugin = () => {
  77. global.add('code', (editor) => {
  78. register$1(editor);
  79. register(editor);
  80. return {};
  81. });
  82. };
  83. Plugin();
  84. /** *****
  85. * DO NOT EXPORT ANYTHING
  86. *
  87. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  88. *******/
  89. })();