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 H5P Content configuration.
|
|
|
18 |
*
|
|
|
19 |
* @module tiny_h5p/commands
|
|
|
20 |
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import {getButtonImage} from 'editor_tiny/utils';
|
|
|
25 |
import {handleAction} from './ui';
|
|
|
26 |
import {getString} from 'core/str';
|
|
|
27 |
import {
|
|
|
28 |
component,
|
|
|
29 |
buttonName,
|
|
|
30 |
icon,
|
|
|
31 |
} from './common';
|
|
|
32 |
import {hasAnyH5PPermission} from './options';
|
|
|
33 |
|
|
|
34 |
export const getSetup = async() => {
|
|
|
35 |
const [
|
|
|
36 |
buttonText,
|
|
|
37 |
buttonImage,
|
|
|
38 |
] = await Promise.all([
|
|
|
39 |
getString('buttontitle', component),
|
|
|
40 |
getButtonImage('icon', component),
|
|
|
41 |
]);
|
|
|
42 |
|
|
|
43 |
return (editor) => {
|
|
|
44 |
if (!hasAnyH5PPermission(editor)) {
|
|
|
45 |
return;
|
|
|
46 |
}
|
|
|
47 |
// Register the H5P Icon.
|
|
|
48 |
editor.ui.registry.addIcon(icon, buttonImage.html);
|
|
|
49 |
|
|
|
50 |
// Register the Menu Button as a toggle.
|
|
|
51 |
// This means that when highlighted over an existing H5P element it will show as toggled on.
|
|
|
52 |
editor.ui.registry.addToggleButton(buttonName, {
|
|
|
53 |
icon,
|
|
|
54 |
tooltip: buttonText,
|
|
|
55 |
onAction: () => handleAction(editor),
|
|
|
56 |
onSetup: (api) => {
|
|
|
57 |
// Set the button to be active if the current selection matches the h5p formatter registered above during PreInit.
|
|
|
58 |
api.setActive(editor.formatter.match('h5p'));
|
|
|
59 |
const changed = editor.formatter.formatChanged('h5p', (state) => api.setActive(state));
|
|
|
60 |
return () => changed.unbind();
|
|
|
61 |
},
|
|
|
62 |
});
|
|
|
63 |
|
|
|
64 |
// Add the H5P Menu Item.
|
|
|
65 |
// This allows it to be added to a standard menu, or a context menu.
|
|
|
66 |
editor.ui.registry.addMenuItem(buttonName, {
|
|
|
67 |
icon,
|
|
|
68 |
text: buttonText,
|
|
|
69 |
onAction: () => handleAction(editor),
|
|
|
70 |
});
|
|
|
71 |
};
|
|
|
72 |
};
|