Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Tiny Premium configuration.
18
 *
19
 * @module      tiny_premium/configuration
20
 * @copyright   2023 David Woloszyn <david.woloszyn@moodle.com>
21
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import {
25
    addToolbarButton,
26
    addMenubarItem,
27
    addToolbarSection,
1441 ariadna 28
    addContextmenuItem,
29
    removeMenubarItem,
1 efrain 30
} from 'editor_tiny/utils';
31
import {
32
    getInitialPluginConfiguration,
33
    getPluginOptionName
34
} from 'editor_tiny/options';
35
 
36
const configureToolbar = (toolbar) => {
37
    // Add premium toolbar sections to house all the plugins with no natural home.
38
    toolbar = addToolbarSection(toolbar, 'premium_a', 'advanced', true);
39
    toolbar = addToolbarSection(toolbar, 'premium_b', 'formatting', true);
40
    return toolbar;
41
};
42
 
43
export const configure = (instanceConfig, options) => {
44
    // Get the namespaced options for Tiny Premium before they are officially initialised.
45
    // Due to the timing the plugin options are available, we need to get at the options in this slightly unconventional way.
46
    const pluginOptions = getInitialPluginConfiguration(options);
47
    const enabledPremiumPlugins = pluginOptions[getPluginOptionName('tiny_premium/plugin', 'premiumplugins')].split(',');
48
 
49
    let plugins = instanceConfig.plugins;
50
    let menu = instanceConfig.menu;
51
    let toolbar = configureToolbar(instanceConfig.toolbar);
52
    let contextmenu = instanceConfig.contextmenu;
53
    let pluginsettings = {};
54
 
55
    // Advanced Table.
56
    if (enabledPremiumPlugins.indexOf('advtable') !== -1) {
57
        plugins += ` advtable`;
58
        menu = addMenubarItem(menu, 'table', '| advtablerownumbering', 'advtablesort');
59
    }
60
    // Enhanced Image Editing.
61
    if (enabledPremiumPlugins.indexOf('editimage') !== -1) {
62
        plugins += ` editimage`;
63
        toolbar = addToolbarButton(toolbar, 'content', 'editimage', 'tiny_media_image');
64
        // Remove the duplicate image button from the quickbar toolbar by redefining the values without 'imageoptions'.
65
        // eslint-disable-next-line camelcase
66
        instanceConfig.editimage_toolbar = 'rotateleft rotateright flipv fliph editimage';
67
    }
68
    // Export.
69
    if (enabledPremiumPlugins.indexOf('export') !== -1) {
70
        plugins += ` export`;
71
        menu = addMenubarItem(menu, 'tools', '| export');
72
    }
73
    // Page Embed.
74
    if (enabledPremiumPlugins.indexOf('pageembed') !== -1) {
75
        plugins += ` pageembed`;
76
        toolbar = addToolbarButton(toolbar, 'content', 'pageembed', 'tiny_media_video');
77
    }
78
    // Advanced Typography.
79
    if (enabledPremiumPlugins.indexOf('typography') !== -1) {
80
        plugins += ` typography`;
81
        toolbar = addToolbarButton(toolbar, 'premium_b', 'typography');
82
    }
83
    // Case Change.
84
    if (enabledPremiumPlugins.indexOf('casechange') !== -1) {
85
        plugins += ` casechange`;
86
        toolbar = addToolbarButton(toolbar, 'premium_a', 'casechange');
87
    }
88
    // Checklist.
89
    if (enabledPremiumPlugins.indexOf('checklist') !== -1) {
90
        plugins += ` checklist`;
91
        toolbar = addToolbarButton(toolbar, 'lists', 'checklist');
92
    }
93
    // Spell Checker Pro.
94
    if (enabledPremiumPlugins.indexOf('tinymcespellchecker') !== -1) {
95
        plugins += ` tinymcespellchecker`;
96
        menu = addMenubarItem(menu, 'tools', 'spellcheckdialog', 'spellcheckerlanguage');
97
        contextmenu = addContextmenuItem(contextmenu, 'spellchecker');
98
        toolbar = addToolbarButton(toolbar, 'premium_a', 'spellcheckdialog');
99
    }
100
    // Spelling Autocorrect.
101
    if (enabledPremiumPlugins.indexOf('autocorrect') !== -1) {
102
        plugins += ` autocorrect`;
103
        menu = addMenubarItem(menu, 'tools', '| autocorrect capitalization', 'spellcheckdialog');
104
    }
105
    // Permanent Pen.
106
    if (enabledPremiumPlugins.indexOf('permanentpen') !== -1) {
107
        plugins += ` permanentpen`;
108
        menu = addMenubarItem(menu, 'format', '| permanentpen configurepermanentpen');
109
        toolbar = addToolbarButton(toolbar, 'premium_a', 'permanentpen');
110
        contextmenu = addContextmenuItem(contextmenu, 'configurepermanentpen');
111
    }
112
    // Format Painter.
113
    if (enabledPremiumPlugins.indexOf('formatpainter') !== -1) {
114
        plugins += ` formatpainter`;
115
        toolbar = addToolbarButton(toolbar, 'premium_a', 'formatpainter');
116
    }
117
    // Link Checker.
118
    if (enabledPremiumPlugins.indexOf('linkchecker') !== -1) {
119
        plugins += ` linkchecker`;
120
        contextmenu = addContextmenuItem(contextmenu, 'linkchecker');
121
    }
122
    // Table of Contents.
123
    if (enabledPremiumPlugins.indexOf('tableofcontents') !== -1) {
124
        plugins += ` tableofcontents`;
125
        toolbar = addToolbarButton(toolbar, 'premium_a', 'tableofcontents');
126
    }
1441 ariadna 127
    // MathML
128
    if (enabledPremiumPlugins.indexOf('math') !== -1) {
129
        plugins += ` math`;
130
        toolbar = addToolbarButton(toolbar, 'premium_a', 'math');
131
        menu = addMenubarItem(menu, 'insert', 'math', 'tableofcontents');
132
    }
1 efrain 133
    // Footnotes.
134
    if (enabledPremiumPlugins.indexOf('footnotes') !== -1) {
135
        plugins += ` footnotes`;
136
        toolbar = addToolbarButton(toolbar, 'premium_a', 'footnotes');
137
        menu = addMenubarItem(menu, 'insert', 'footnotes', 'tableofcontents');
138
    }
139
    // Powerpaste.
140
    if (enabledPremiumPlugins.indexOf('powerpaste') !== -1) {
141
        plugins += ` powerpaste`;
142
    }
1441 ariadna 143
    // Accessibility Checker.
144
    if (enabledPremiumPlugins.indexOf('a11ychecker') !== -1) {
145
        plugins += ` a11ychecker`;
146
        toolbar = addToolbarButton(toolbar, 'premium_a', 'a11ycheck');
147
        // Tiny's allychecker plugin is listed in the menu by default. Let's remove it and add it where we want it.
148
        menu = removeMenubarItem(menu, 'tools', 'a11ycheck');
149
        // Positioning the a11ychecker in the same position as tiny_accessibilitychecker (for familiarity).
150
        menu = addMenubarItem(menu, 'tools', 'a11ycheck', 'count');
151
        // Finally, hide tiny_accessibilitychecker so there is no confusion.
152
        menu = removeMenubarItem(menu, 'tools', 'tiny_accessibilitychecker');
153
    }
1 efrain 154
 
155
    return {
156
        plugins,
157
        toolbar,
158
        menu,
159
        contextmenu,
160
        ...pluginsettings
161
    };
162
};