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
// Moodle is free software: you can redistribute it and/or modify
3
// it under the terms of the GNU General Public License as published by
4
// the Free Software Foundation, either version 3 of the License, or
5
// (at your option) any later version.
6
//
7
// Moodle is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
// GNU General Public License for more details.
11
//
12
// You should have received a copy of the GNU General Public License
13
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
14
 
15
/**
16
 * Course format selection handler.
17
 *
18
 * @module     core_course/formatchooser
19
 * @copyright  2022 Andrew Nicols <andrew@nicols.co.uk>
20
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 * @since      4.0
22
 */
23
 
24
const Selectors = {
25
    fields: {
26
        selector: '[data-formatchooser-field="selector"]',
27
        updateButton: '[data-formatchooser-field="updateButton"]',
28
    },
29
};
30
 
31
/**
32
 * Initialise the format chooser.
33
 */
34
export const init = () => {
35
    document.querySelector(Selectors.fields.selector).addEventListener('change', e => {
36
        const form = e.target.closest('form');
37
        const updateButton = form.querySelector(Selectors.fields.updateButton);
38
        const fieldset = updateButton.closest('fieldset');
39
 
40
        const url = new URL(form.action);
41
        url.hash = fieldset.id;
42
 
43
        form.action = url.toString();
44
        updateButton.click();
45
    });
46
};