Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Tiny tiny_aiplacement for Moodle.
18
 *
19
 * @module      tiny_aiplacement/configuration
20
 * @copyright   2024 Matt Porritt <matt.porritt@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import {
25
    contextMenuName,
26
    generateImageName,
27
    generateTextName
28
} from './common';
29
import {
30
    addMenubarItem,
31
} from 'editor_tiny/utils';
32
 
33
const configureMenu = (menu) => {
34
    const items = menu.insert.items.split(' ');
35
    const inserted = items.some((item, index) => {
36
        // Append after the media or video button.
37
        if (item.match(/(media)\b/)) {
38
            items.splice(index + 1, 0, generateImageName, generateTextName);
39
            return true;
40
        }
41
 
42
        return false;
43
    });
44
 
45
    if (inserted) {
46
        menu.insert.items = items.join(' ');
47
    } else {
48
        addMenubarItem(menu, 'insert', `${generateImageName} ${generateTextName}`);
49
    }
50
 
51
    return menu;
52
};
53
 
54
const configureToolbar = (toolbar) => {
55
    // The toolbar contains an array of named sections.
56
    // The Moodle integration ensures that there is a section called 'content'.
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)\b/)) {
63
                    section.items.splice(index + 1, 0, contextMenuName, generateImageName, generateTextName);
64
                    return true;
65
                }
66
                return false;
67
            });
68
 
69
            if (!inserted) {
70
                section.items.unshift(contextMenuName, generateImageName, generateTextName);
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
};