Proyectos de Subversion Moodle

Rev

| 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 Media Manager plugin class for Moodle.
18
 *
19
 * @module      tiny_media/manager
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 Templates from 'core/templates';
25
import {getString} from 'core/str';
26
import Modal from 'core/modal';
27
import * as ModalEvents from 'core/modal_events';
28
import {getData} from './options';
29
import Config from 'core/config';
30
 
31
export default class MediaManager {
32
 
33
    editor = null;
34
    area = null;
35
 
36
    constructor(editor) {
37
        this.editor = editor;
38
        const data = getData(editor);
39
        this.area = data.params.area;
40
        this.area.itemid = data.fpoptions.image.itemid;
41
    }
42
 
43
    async displayDialogue() {
44
        const modal = await Modal.create({
45
            large: true,
46
            title: getString('mediamanagerproperties', 'tiny_media'),
47
            body: Templates.render('tiny_media/mm_iframe', {
48
                src: this.getIframeURL()
49
            }),
50
            removeOnClose: true,
51
            show: true,
52
        });
53
        modal.getRoot().on(ModalEvents.bodyRendered, () => {
54
            this.selectFirstElement();
55
        });
56
 
57
        document.querySelector('.modal-lg').style.cssText = `max-width: 850px`;
58
        return modal;
59
    }
60
 
61
    // It will select the first element in the file manager.
62
    selectFirstElement() {
63
        const iframe = document.getElementById('mm-iframe');
64
        iframe.addEventListener('load', function() {
65
            let intervalId = setInterval(function() {
66
                const iDocument = iframe.contentWindow.document;
67
                if (iDocument.querySelector('.filemanager')) {
68
                    const firstFocusableElement = iDocument.querySelector('.fp-navbar a:not([disabled])');
69
                    if (firstFocusableElement) {
70
                        firstFocusableElement.focus();
71
                    }
72
                    clearInterval(intervalId);
73
                }
74
            }, 200);
75
        });
76
    }
77
 
78
    getIframeURL() {
79
        const url = new URL(`${Config.wwwroot}/lib/editor/tiny/plugins/media/manage.php`);
80
        url.searchParams.append('elementid', this.editor.getElement().id);
81
        for (const key in this.area) {
82
            url.searchParams.append(key, this.area[key]);
83
        }
84
        return url.toString();
85
    }
86
}