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 Cell = function (initial) { |
||
13 | var value = initial; |
||
14 | var get = function () { |
||
15 | return value; |
||
16 | }; |
||
17 | var set = function (v) { |
||
18 | value = v; |
||
19 | }; |
||
20 | return { |
||
21 | get: get, |
||
22 | set: set |
||
23 | }; |
||
24 | }; |
||
25 | |||
26 | var global = tinymce.util.Tools.resolve('tinymce.PluginManager'); |
||
27 | |||
28 | var fireVisualBlocks = function (editor, state) { |
||
29 | editor.fire('VisualBlocks', { state: state }); |
||
30 | }; |
||
31 | |||
32 | var toggleVisualBlocks = function (editor, pluginUrl, enabledState) { |
||
33 | var dom = editor.dom; |
||
34 | dom.toggleClass(editor.getBody(), 'mce-visualblocks'); |
||
35 | enabledState.set(!enabledState.get()); |
||
36 | fireVisualBlocks(editor, enabledState.get()); |
||
37 | }; |
||
38 | |||
637 | daniel-mar | 39 | var register$1 = function (editor, pluginUrl, enabledState) { |
597 | daniel-mar | 40 | editor.addCommand('mceVisualBlocks', function () { |
41 | toggleVisualBlocks(editor, pluginUrl, enabledState); |
||
42 | }); |
||
43 | }; |
||
44 | |||
45 | var isEnabledByDefault = function (editor) { |
||
46 | return editor.getParam('visualblocks_default_state', false, 'boolean'); |
||
47 | }; |
||
48 | |||
49 | var setup = function (editor, pluginUrl, enabledState) { |
||
50 | editor.on('PreviewFormats AfterPreviewFormats', function (e) { |
||
51 | if (enabledState.get()) { |
||
52 | editor.dom.toggleClass(editor.getBody(), 'mce-visualblocks', e.type === 'afterpreviewformats'); |
||
53 | } |
||
54 | }); |
||
55 | editor.on('init', function () { |
||
56 | if (isEnabledByDefault(editor)) { |
||
57 | toggleVisualBlocks(editor, pluginUrl, enabledState); |
||
58 | } |
||
59 | }); |
||
60 | }; |
||
61 | |||
62 | var toggleActiveState = function (editor, enabledState) { |
||
63 | return function (api) { |
||
64 | api.setActive(enabledState.get()); |
||
65 | var editorEventCallback = function (e) { |
||
66 | return api.setActive(e.state); |
||
67 | }; |
||
68 | editor.on('VisualBlocks', editorEventCallback); |
||
69 | return function () { |
||
70 | return editor.off('VisualBlocks', editorEventCallback); |
||
71 | }; |
||
72 | }; |
||
73 | }; |
||
637 | daniel-mar | 74 | var register = function (editor, enabledState) { |
75 | var onAction = function () { |
||
76 | return editor.execCommand('mceVisualBlocks'); |
||
77 | }; |
||
597 | daniel-mar | 78 | editor.ui.registry.addToggleButton('visualblocks', { |
79 | icon: 'visualblocks', |
||
80 | tooltip: 'Show blocks', |
||
637 | daniel-mar | 81 | onAction: onAction, |
597 | daniel-mar | 82 | onSetup: toggleActiveState(editor, enabledState) |
83 | }); |
||
84 | editor.ui.registry.addToggleMenuItem('visualblocks', { |
||
85 | text: 'Show blocks', |
||
86 | icon: 'visualblocks', |
||
637 | daniel-mar | 87 | onAction: onAction, |
597 | daniel-mar | 88 | onSetup: toggleActiveState(editor, enabledState) |
89 | }); |
||
90 | }; |
||
91 | |||
92 | function Plugin () { |
||
93 | global.add('visualblocks', function (editor, pluginUrl) { |
||
94 | var enabledState = Cell(false); |
||
637 | daniel-mar | 95 | register$1(editor, pluginUrl, enabledState); |
96 | register(editor, enabledState); |
||
597 | daniel-mar | 97 | setup(editor, pluginUrl, enabledState); |
98 | }); |
||
99 | } |
||
100 | |||
101 | Plugin(); |
||
102 | |||
103 | }()); |