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
import {getButtonImage} from 'editor_tiny/utils';
17
import {getString} from 'core/str';
18
import {component, buttonName, icon} from 'tiny_equation/common';
19
import {handleAction} from 'tiny_equation/ui';
20
import {getSelectedEquation} from 'tiny_equation/equation';
21
import {isTexFilterActive} from 'tiny_equation/options';
22
 
23
/**
24
 * Tiny Equation commands.
25
 *
26
 * @module      tiny_equation/commands
27
 * @copyright   2022 Huong Nguyen <huongnv13@gmail.com>
28
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
 
31
export const getSetup = async() => {
32
    const [
33
        buttonText,
34
        buttonImage,
35
    ] = await Promise.all([
36
        getString('buttontitle', component),
37
        getButtonImage('icon', component),
38
    ]);
39
 
40
    return (editor) => {
41
        if (isTexFilterActive(editor)) {
42
            // Register the Equation Icon.
43
            editor.ui.registry.addIcon(icon, buttonImage.html);
44
 
45
            // Register the Menu Button as a toggle.
46
            // This means that when highlighted over an existing Equation element it will show as toggled on.
47
            editor.ui.registry.addToggleButton(buttonName, {
48
                icon,
49
                tooltip: buttonText,
50
                onAction: () => {
51
                    handleAction(editor);
52
                },
53
                onSetup: (api) => {
54
                    editor.on('NodeChange', () => {
55
                        const result = getSelectedEquation(editor);
56
                        api.setActive(result);
57
                    });
58
                },
59
            });
60
 
61
            // Add the Equation Menu Item.
62
            // This allows it to be added to a standard menu, or a context menu.
63
            editor.ui.registry.addMenuItem(buttonName, {
64
                icon,
65
                text: buttonText,
66
                onAction: () => handleAction(editor),
67
            });
68
        }
69
    };
70
};