Proyectos de Subversion Moodle

Rev

| 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,
28
    addContextmenuItem
29
} from 'editor_tiny/utils';
30
import {
31
    getInitialPluginConfiguration,
32
    getPluginOptionName
33
} from 'editor_tiny/options';
34
 
35
const configureToolbar = (toolbar) => {
36
    // Add premium toolbar sections to house all the plugins with no natural home.
37
    toolbar = addToolbarSection(toolbar, 'premium_a', 'advanced', true);
38
    toolbar = addToolbarSection(toolbar, 'premium_b', 'formatting', true);
39
    return toolbar;
40
};
41
 
42
export const configure = (instanceConfig, options) => {
43
    // Get the namespaced options for Tiny Premium before they are officially initialised.
44
    // Due to the timing the plugin options are available, we need to get at the options in this slightly unconventional way.
45
    const pluginOptions = getInitialPluginConfiguration(options);
46
    const enabledPremiumPlugins = pluginOptions[getPluginOptionName('tiny_premium/plugin', 'premiumplugins')].split(',');
47
 
48
    let plugins = instanceConfig.plugins;
49
    let menu = instanceConfig.menu;
50
    let toolbar = configureToolbar(instanceConfig.toolbar);
51
    let contextmenu = instanceConfig.contextmenu;
52
    let pluginsettings = {};
53
 
54
    // Advanced Table.
55
    if (enabledPremiumPlugins.indexOf('advtable') !== -1) {
56
        plugins += ` advtable`;
57
        menu = addMenubarItem(menu, 'table', '| advtablerownumbering', 'advtablesort');
58
    }
59
    // Enhanced Image Editing.
60
    if (enabledPremiumPlugins.indexOf('editimage') !== -1) {
61
        plugins += ` editimage`;
62
        toolbar = addToolbarButton(toolbar, 'content', 'editimage', 'tiny_media_image');
63
        // Remove the duplicate image button from the quickbar toolbar by redefining the values without 'imageoptions'.
64
        // eslint-disable-next-line camelcase
65
        instanceConfig.editimage_toolbar = 'rotateleft rotateright flipv fliph editimage';
66
    }
67
    // Export.
68
    if (enabledPremiumPlugins.indexOf('export') !== -1) {
69
        plugins += ` export`;
70
        menu = addMenubarItem(menu, 'tools', '| export');
71
    }
72
    // Page Embed.
73
    if (enabledPremiumPlugins.indexOf('pageembed') !== -1) {
74
        plugins += ` pageembed`;
75
        toolbar = addToolbarButton(toolbar, 'content', 'pageembed', 'tiny_media_video');
76
    }
77
    // Advanced Typography.
78
    if (enabledPremiumPlugins.indexOf('typography') !== -1) {
79
        plugins += ` typography`;
80
        toolbar = addToolbarButton(toolbar, 'premium_b', 'typography');
81
    }
82
    // Case Change.
83
    if (enabledPremiumPlugins.indexOf('casechange') !== -1) {
84
        plugins += ` casechange`;
85
        toolbar = addToolbarButton(toolbar, 'premium_a', 'casechange');
86
    }
87
    // Checklist.
88
    if (enabledPremiumPlugins.indexOf('checklist') !== -1) {
89
        plugins += ` checklist`;
90
        toolbar = addToolbarButton(toolbar, 'lists', 'checklist');
91
    }
92
    // Spell Checker Pro.
93
    if (enabledPremiumPlugins.indexOf('tinymcespellchecker') !== -1) {
94
        plugins += ` tinymcespellchecker`;
95
        menu = addMenubarItem(menu, 'tools', 'spellcheckdialog', 'spellcheckerlanguage');
96
        contextmenu = addContextmenuItem(contextmenu, 'spellchecker');
97
        toolbar = addToolbarButton(toolbar, 'premium_a', 'spellcheckdialog');
98
    }
99
    // Spelling Autocorrect.
100
    if (enabledPremiumPlugins.indexOf('autocorrect') !== -1) {
101
        plugins += ` autocorrect`;
102
        menu = addMenubarItem(menu, 'tools', '| autocorrect capitalization', 'spellcheckdialog');
103
    }
104
    // Permanent Pen.
105
    if (enabledPremiumPlugins.indexOf('permanentpen') !== -1) {
106
        plugins += ` permanentpen`;
107
        menu = addMenubarItem(menu, 'format', '| permanentpen configurepermanentpen');
108
        toolbar = addToolbarButton(toolbar, 'premium_a', 'permanentpen');
109
        contextmenu = addContextmenuItem(contextmenu, 'configurepermanentpen');
110
    }
111
    // Format Painter.
112
    if (enabledPremiumPlugins.indexOf('formatpainter') !== -1) {
113
        plugins += ` formatpainter`;
114
        toolbar = addToolbarButton(toolbar, 'premium_a', 'formatpainter');
115
    }
116
    // Link Checker.
117
    if (enabledPremiumPlugins.indexOf('linkchecker') !== -1) {
118
        plugins += ` linkchecker`;
119
        contextmenu = addContextmenuItem(contextmenu, 'linkchecker');
120
    }
121
    // Table of Contents.
122
    if (enabledPremiumPlugins.indexOf('tableofcontents') !== -1) {
123
        plugins += ` tableofcontents`;
124
        toolbar = addToolbarButton(toolbar, 'premium_a', 'tableofcontents');
125
    }
126
    // Footnotes.
127
    if (enabledPremiumPlugins.indexOf('footnotes') !== -1) {
128
        plugins += ` footnotes`;
129
        toolbar = addToolbarButton(toolbar, 'premium_a', 'footnotes');
130
        menu = addMenubarItem(menu, 'insert', 'footnotes', 'tableofcontents');
131
    }
132
    // Powerpaste.
133
    if (enabledPremiumPlugins.indexOf('powerpaste') !== -1) {
134
        plugins += ` powerpaste`;
135
    }
136
 
137
    return {
138
        plugins,
139
        toolbar,
140
        menu,
141
        contextmenu,
142
        ...pluginsettings
143
    };
144
};