Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
/**
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,
1441 ariadna 26
    videoButtonName,
27
    screenButtonName,
28
    videoContextMenuName,
1 efrain 29
} from './common';
30
import {
31
    addMenubarItem,
32
} from 'editor_tiny/utils';
33
 
34
const configureMenu = (menu) => {
35
    const items = menu.insert.items.split(' ');
36
    const inserted = items.some((item, index) => {
37
        // Append after the media or video button.
38
        if (item.match(/(media|video)\b/)) {
1441 ariadna 39
            items.splice(index + 1, 0, audioButtonName, videoButtonName, screenButtonName);
1 efrain 40
            return true;
41
        }
42
 
43
        return false;
44
    });
45
 
46
    if (inserted) {
47
        menu.insert.items = items.join(' ');
48
    } else {
1441 ariadna 49
        addMenubarItem(menu, 'insert', `${audioButtonName} ${videoButtonName} ${screenButtonName}`);
1 efrain 50
    }
51
 
52
    return menu;
53
};
54
 
55
const configureToolbar = (toolbar) => {
56
    // The toolbar contains an array of named sections.
57
    // The Moodle integration ensures that there is a section called 'content'.
58
 
59
 
60
    return toolbar.map((section) => {
61
        if (section.name === 'content') {
62
            const inserted = section.items.some((item, index) => {
63
                // Append after the media or video button.
64
                if (item.match(/(media|video)\b/)) {
1441 ariadna 65
                    section.items.splice(index + 1, 0, audioButtonName, videoContextMenuName);
1 efrain 66
                    return true;
67
                }
68
                return false;
69
            });
70
 
71
            if (!inserted) {
1441 ariadna 72
                section.items.unshift(audioButtonName, videoContextMenuName);
1 efrain 73
            }
74
        }
75
 
76
        return section;
77
    });
78
};
79
 
80
export const configure = (instanceConfig) => {
81
    // Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
82
    return {
83
        toolbar: configureToolbar(instanceConfig.toolbar),
84
        menu: configureMenu(instanceConfig.menu),
85
    };
86
};