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 {getString} from 'core/str';
|
|
|
17 |
import {component, linkButtonShortName, unlinkButtonShortName} from 'tiny_link/common';
|
|
|
18 |
import {handleAction} from 'tiny_link/ui';
|
|
|
19 |
import {toggleActiveState} from 'tiny_link/link';
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Tiny Link commands.
|
|
|
23 |
*
|
|
|
24 |
* @module tiny_link/commands
|
|
|
25 |
* @copyright 2023 Huong Nguyen <huongnv13@gmail.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 |
linkButtonText,
|
|
|
32 |
unlinkButtonText,
|
|
|
33 |
] = await Promise.all([
|
|
|
34 |
getString('link', component),
|
|
|
35 |
getString('unlink', component),
|
|
|
36 |
]);
|
|
|
37 |
|
|
|
38 |
return (editor) => {
|
|
|
39 |
// Register Link button.
|
|
|
40 |
editor.ui.registry.addToggleButton(linkButtonShortName, {
|
|
|
41 |
icon: 'link',
|
|
|
42 |
tooltip: linkButtonText,
|
|
|
43 |
onAction: () => {
|
|
|
44 |
handleAction(editor);
|
|
|
45 |
},
|
|
|
46 |
onSetup: toggleActiveState(editor),
|
|
|
47 |
});
|
|
|
48 |
|
|
|
49 |
// Register the Link menu item.
|
|
|
50 |
editor.ui.registry.addMenuItem(linkButtonShortName, {
|
|
|
51 |
icon: 'link',
|
|
|
52 |
shortcut: 'Meta+K',
|
|
|
53 |
text: linkButtonText,
|
|
|
54 |
onAction: () => {
|
|
|
55 |
handleAction(editor);
|
|
|
56 |
},
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
// Register Unlink button.
|
|
|
60 |
editor.ui.registry.addToggleButton(unlinkButtonShortName, {
|
|
|
61 |
icon: 'unlink',
|
|
|
62 |
tooltip: unlinkButtonText,
|
|
|
63 |
onAction: () => {
|
|
|
64 |
handleAction(editor, true);
|
|
|
65 |
},
|
|
|
66 |
onSetup: toggleActiveState(editor),
|
|
|
67 |
});
|
|
|
68 |
|
|
|
69 |
// Register shortcut.
|
|
|
70 |
editor.shortcuts.add('Meta+K', 'Shortcut for create link', () => {
|
|
|
71 |
handleAction(editor);
|
|
|
72 |
});
|
|
|
73 |
};
|
|
|
74 |
};
|