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 {get_string as getString} from 'core/str';
|
|
|
18 |
import {component, buttonName, buttonIcon} from 'tiny_noautolink/common';
|
|
|
19 |
import {handleAction, toggleActiveState} from 'tiny_noautolink/noautolink';
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Tiny noautolink commands.
|
|
|
23 |
*
|
|
|
24 |
* @module tiny_noautolink/commands
|
|
|
25 |
* @copyright 2023 Meirza <meirza.arson@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
export const getSetup = async() => {
|
|
|
30 |
const [
|
|
|
31 |
buttonText,
|
|
|
32 |
infoEmptySelection,
|
|
|
33 |
infoAddSuccess,
|
|
|
34 |
infoRemoveSuccess,
|
|
|
35 |
buttonImage,
|
|
|
36 |
] = await Promise.all([
|
|
|
37 |
getString('buttontitle', component),
|
|
|
38 |
getString('infoemptyselection', component),
|
|
|
39 |
getString('infoaddsuccess', component),
|
|
|
40 |
getString('inforemovesuccess', component),
|
|
|
41 |
getButtonImage('icon', component),
|
|
|
42 |
]);
|
|
|
43 |
|
|
|
44 |
return (editor) => {
|
|
|
45 |
|
|
|
46 |
const messages = {
|
|
|
47 |
infoEmptySelection: infoEmptySelection,
|
|
|
48 |
infoAddSuccess: infoAddSuccess,
|
|
|
49 |
infoRemoveSuccess: infoRemoveSuccess
|
|
|
50 |
};
|
|
|
51 |
|
|
|
52 |
// Register the noautolink Icon.
|
|
|
53 |
editor.ui.registry.addIcon(buttonIcon, buttonImage.html);
|
|
|
54 |
|
|
|
55 |
// Register the noautolink button.
|
|
|
56 |
editor.ui.registry.addToggleButton(buttonName, {
|
|
|
57 |
icon: buttonIcon,
|
|
|
58 |
tooltip: buttonText,
|
|
|
59 |
onAction: () => {
|
|
|
60 |
handleAction(editor, messages);
|
|
|
61 |
},
|
|
|
62 |
onSetup: toggleActiveState(editor),
|
|
|
63 |
});
|
|
|
64 |
|
|
|
65 |
// Register the noautolink item.
|
|
|
66 |
editor.ui.registry.addMenuItem(buttonName, {
|
|
|
67 |
icon: buttonIcon,
|
|
|
68 |
text: buttonText,
|
|
|
69 |
onAction: () => {
|
|
|
70 |
handleAction(editor, messages);
|
|
|
71 |
},
|
|
|
72 |
});
|
|
|
73 |
};
|
|
|
74 |
};
|