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 Record RTC configuration.
|
|
|
18 |
*
|
|
|
19 |
* @module tiny_recordrtc/configuration
|
|
|
20 |
* @copyright 2022, Stevani Andolo <stevani@hotmail.com.au>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import {
|
|
|
25 |
audioButtonName,
|
|
|
26 |
videoButtonName
|
|
|
27 |
} from './common';
|
|
|
28 |
import {
|
|
|
29 |
addMenubarItem,
|
|
|
30 |
} from 'editor_tiny/utils';
|
|
|
31 |
|
|
|
32 |
const configureMenu = (menu) => {
|
|
|
33 |
const items = menu.insert.items.split(' ');
|
|
|
34 |
const inserted = items.some((item, index) => {
|
|
|
35 |
// Append after the media or video button.
|
|
|
36 |
if (item.match(/(media|video)\b/)) {
|
|
|
37 |
items.splice(index + 1, 0, audioButtonName, videoButtonName);
|
|
|
38 |
return true;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return false;
|
|
|
42 |
});
|
|
|
43 |
|
|
|
44 |
if (inserted) {
|
|
|
45 |
menu.insert.items = items.join(' ');
|
|
|
46 |
} else {
|
|
|
47 |
addMenubarItem(menu, 'insert', `${audioButtonName} ${videoButtonName}`);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
return menu;
|
|
|
51 |
};
|
|
|
52 |
|
|
|
53 |
const configureToolbar = (toolbar) => {
|
|
|
54 |
// The toolbar contains an array of named sections.
|
|
|
55 |
// The Moodle integration ensures that there is a section called 'content'.
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
return toolbar.map((section) => {
|
|
|
59 |
if (section.name === 'content') {
|
|
|
60 |
const inserted = section.items.some((item, index) => {
|
|
|
61 |
// Append after the media or video button.
|
|
|
62 |
if (item.match(/(media|video)\b/)) {
|
|
|
63 |
section.items.splice(index + 1, 0, audioButtonName, videoButtonName);
|
|
|
64 |
return true;
|
|
|
65 |
}
|
|
|
66 |
return false;
|
|
|
67 |
});
|
|
|
68 |
|
|
|
69 |
if (!inserted) {
|
|
|
70 |
section.items.unshift(audioButtonName, videoButtonName);
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
return section;
|
|
|
75 |
});
|
|
|
76 |
};
|
|
|
77 |
|
|
|
78 |
export const configure = (instanceConfig) => {
|
|
|
79 |
// Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
|
|
|
80 |
return {
|
|
|
81 |
toolbar: configureToolbar(instanceConfig.toolbar),
|
|
|
82 |
menu: configureMenu(instanceConfig.menu),
|
|
|
83 |
};
|
|
|
84 |
};
|