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
 * Show more action for availablity information.
18
 *
19
 * @deprecated since 4.3 MDL-78204.
20
 * @module     core_availability/availability_more
21
 * @copyright  2021 Bas Brands <bas@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Availability info selectors.
27
 */
28
const Selectors = {
29
    regions: {
30
        availability: '[data-region="availability-multiple"]',
31
    },
32
    actions: {
33
        showmorelink: '[data-action="showmore"]'
34
    },
35
    classes: {
36
        hidden: 'd-none',
37
        visible: 'd-block',
38
 
39
    }
40
};
41
 
42
/**
43
 * Displays all the availability information in case part of it is hidden.
44
 *
45
 * @param {Event} event the triggered event
46
 */
47
const showMoreHandler = (event) => {
48
    const triggerElement = event.target.closest(Selectors.actions.showmorelink);
49
    if (triggerElement === null) {
50
        return;
51
    }
52
    const container = triggerElement.closest(Selectors.regions.availability);
53
    container.querySelectorAll('.' + Selectors.classes.hidden).forEach(function(node) {
54
        node.classList.remove(Selectors.classes.hidden);
55
    });
56
    container.querySelectorAll('.' + Selectors.classes.visible).forEach(function(node) {
57
        node.classList.remove(Selectors.classes.visible);
58
        node.classList.add(Selectors.classes.hidden);
59
    });
60
    event.preventDefault();
61
};
62
 
63
/**
64
 * Initialise the eventlister for the showmore action on availability information.
65
 *
66
 * @method  init
67
 */
68
export const init = () => {
69
    const body = document.querySelector('body');
70
    if (!body.dataset.showmoreactive) {
71
        document.addEventListener('click', showMoreHandler);
72
        body.dataset.showmoreactive = 1;
73
    }
74
};