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
 * Course index drawer wrap.
18
 *
19
 * This component is mostly used to ensure all subcomponents find a parent
20
 * compoment with a reactive instance defined.
21
 *
22
 * @module     core_courseformat/local/courseindex/drawer
23
 * @class     core_courseformat/local/courseindex/drawer
24
 * @copyright  2021 Ferran Recio <ferran@moodle.com>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
import {BaseComponent} from 'core/reactive';
29
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
1441 ariadna 30
import log from "core/log";
1 efrain 31
 
32
export default class Component extends BaseComponent {
33
 
34
    /**
35
     * Constructor hook.
36
     */
37
    create() {
38
        // Optional component name for debugging.
39
        this.name = 'courseindex-drawer';
40
    }
41
 
42
    /**
43
     * Static method to create a component instance form the mustache template.
44
     *
45
     * @param {element|string} target the DOM main element or its ID
46
     * @param {object} selectors optional css selector overrides
47
     * @return {Component}
48
     */
49
    static init(target, selectors) {
1441 ariadna 50
        let element = document.querySelector(target);
51
        // TODO Remove this if condition as part of MDL-83851.
52
        if (!element) {
53
            log.debug('Init component with id is deprecated, use a query selector instead.');
54
            element = document.getElementById(target);
55
        }
1 efrain 56
        return new this({
1441 ariadna 57
            element,
1 efrain 58
            reactive: getCurrentCourseEditor(),
59
            selectors,
60
        });
61
    }
62
}