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