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