1441 |
ariadna |
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 |
* The collapsable section events.
|
|
|
18 |
*
|
|
|
19 |
* This module wraps the standard bootstrap collapsable events, but for collapsable sections.
|
|
|
20 |
*
|
|
|
21 |
* @module core/local/collapsable_section/events
|
|
|
22 |
* @copyright 2024 Ferran Recio <ferran@moodle.com>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*
|
|
|
25 |
* @example <caption>Example of listening to a collapsable section events.</caption>
|
|
|
26 |
* import {eventTypes as collapsableSectionEventTypes} from 'core/local/collapsable_section/events';
|
|
|
27 |
*
|
|
|
28 |
* document.addEventListener(collapsableSectionEventTypes.shown, event => {
|
|
|
29 |
* window.console.log(event.target); // The HTMLElement relating to the block whose content was updated.
|
|
|
30 |
* });
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
import {dispatchEvent} from 'core/event_dispatcher';
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Events for `core_block`.
|
|
|
37 |
*
|
|
|
38 |
* @constant
|
|
|
39 |
* @property {String} blockContentUpdated See {@link event:blockContentUpdated}
|
|
|
40 |
*/
|
|
|
41 |
export const eventTypes = {
|
|
|
42 |
/**
|
|
|
43 |
* An event triggered when the content of a block has changed.
|
|
|
44 |
*
|
|
|
45 |
* @event blockContentUpdated
|
|
|
46 |
* @type {CustomEvent}
|
|
|
47 |
* @property {HTMLElement} target The block element that was updated
|
|
|
48 |
* @property {object} detail
|
|
|
49 |
* @property {number} detail.instanceId The block instance id
|
|
|
50 |
*/
|
|
|
51 |
shown: 'core_collapsable_section_shown',
|
|
|
52 |
hidden: 'core_collapsable_section_hidden',
|
|
|
53 |
// All Bootstrap 4 jQuery events are wrapped while MDL-71979 is not integrated.
|
|
|
54 |
hideBsCollapse: 'hide.bs.collapse',
|
|
|
55 |
hiddenBsCollapse: 'hidden.bs.collapse',
|
|
|
56 |
showBsCollapse: 'show.bs.collapse',
|
|
|
57 |
shownBsCollapse: 'shown.bs.collapse',
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Trigger an event to indicate that the content of a block was updated.
|
|
|
62 |
*
|
|
|
63 |
* @method notifyBlockContentUpdated
|
|
|
64 |
* @param {HTMLElement} element The HTMLElement containing the updated block.
|
|
|
65 |
* @returns {CustomEvent}
|
|
|
66 |
* @fires blockContentUpdated
|
|
|
67 |
*/
|
|
|
68 |
export const notifyCollapsableSectionShown = element => dispatchEvent(
|
|
|
69 |
eventTypes.shown,
|
|
|
70 |
{},
|
|
|
71 |
element
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Trigger an event to indicate that the content of a block was updated.
|
|
|
76 |
*
|
|
|
77 |
* @method notifyBlockContentUpdated
|
|
|
78 |
* @param {HTMLElement} element The HTMLElement containing the updated block.
|
|
|
79 |
* @returns {CustomEvent}
|
|
|
80 |
* @fires blockContentUpdated
|
|
|
81 |
*/
|
|
|
82 |
export const notifyCollapsableSectionHidden = element => dispatchEvent(
|
|
|
83 |
eventTypes.hidden,
|
|
|
84 |
{},
|
|
|
85 |
element
|
|
|
86 |
);
|