plugin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.2.0 (2020-02-13)
  8. */
  9. (function () {
  10. 'use strict';
  11. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var setContent = function (editor, html) {
  13. editor.focus();
  14. editor.undoManager.transact(function () {
  15. editor.setContent(html);
  16. });
  17. editor.selection.setCursorLocation();
  18. editor.nodeChanged();
  19. };
  20. var getContent = function (editor) {
  21. return editor.getContent({ source_view: true });
  22. };
  23. var Content = {
  24. setContent: setContent,
  25. getContent: getContent
  26. };
  27. var open = function (editor) {
  28. var editorContent = Content.getContent(editor);
  29. editor.windowManager.open({
  30. title: 'Source Code',
  31. size: 'large',
  32. body: {
  33. type: 'panel',
  34. items: [{
  35. type: 'textarea',
  36. name: 'code'
  37. }]
  38. },
  39. buttons: [
  40. {
  41. type: 'cancel',
  42. name: 'cancel',
  43. text: 'Cancel'
  44. },
  45. {
  46. type: 'submit',
  47. name: 'save',
  48. text: 'Save',
  49. primary: true
  50. }
  51. ],
  52. initialData: { code: editorContent },
  53. onSubmit: function (api) {
  54. Content.setContent(editor, api.getData().code);
  55. api.close();
  56. }
  57. });
  58. };
  59. var Dialog = { open: open };
  60. var register = function (editor) {
  61. editor.addCommand('mceCodeEditor', function () {
  62. Dialog.open(editor);
  63. });
  64. };
  65. var Commands = { register: register };
  66. var register$1 = function (editor) {
  67. editor.ui.registry.addButton('code', {
  68. icon: 'sourcecode',
  69. tooltip: 'Source code',
  70. onAction: function () {
  71. return Dialog.open(editor);
  72. }
  73. });
  74. editor.ui.registry.addMenuItem('code', {
  75. icon: 'sourcecode',
  76. text: 'Source code',
  77. onAction: function () {
  78. return Dialog.open(editor);
  79. }
  80. });
  81. };
  82. var Buttons = { register: register$1 };
  83. function Plugin () {
  84. global.add('code', function (editor) {
  85. Commands.register(editor);
  86. Buttons.register(editor);
  87. return {};
  88. });
  89. }
  90. Plugin();
  91. }());