MDL-69086 theme_boost: Improve pendingJs checks for bootstrap
[moodle.git] / theme / boost / amd / src / pending.js
CommitLineData
d27ac462
AN
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 * Add Pending JS checks to stock Bootstrap transitions.
18 *
19 * @module theme_boost/pending
20 * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
d27ac462 23
721c29ff
AN
24import jQuery from 'jquery';
25const moduleTransitions = {
26 alert: [
27 // Alert.
28 {
29 start: 'close',
30 end: 'closed',
31 },
32 ],
d27ac462 33
721c29ff
AN
34 carousel: [
35 {
36 start: 'slide',
37 end: 'slid',
38 },
39 ],
d27ac462 40
721c29ff
AN
41 collapse: [
42 {
43 start: 'hide',
44 end: 'hidden',
45 },
46 {
47 start: 'show',
48 end: 'shown',
49 },
50 ],
d27ac462 51
721c29ff
AN
52 dropdown: [
53 {
54 start: 'hide',
55 end: 'hidden',
56 },
57 {
58 start: 'show',
59 end: 'shown',
60 },
61 ],
d27ac462 62
721c29ff
AN
63 modal: [
64 {
65 start: 'hide',
66 end: 'hidden',
67 },
68 {
69 start: 'show',
70 end: 'shown',
71 },
72 ],
d27ac462 73
721c29ff
AN
74 popover: [
75 {
76 start: 'hide',
77 end: 'hidden',
78 },
79 {
80 start: 'show',
81 end: 'shown',
82 },
83 ],
d27ac462 84
721c29ff
AN
85 tab: [
86 {
87 start: 'hide',
88 end: 'hidden',
89 },
90 {
91 start: 'show',
92 end: 'shown',
93 },
94 ],
10425e73 95
721c29ff
AN
96 toast: [
97 {
98 start: 'hide',
99 end: 'hidden',
100 },
101 {
102 start: 'show',
103 end: 'shown',
104 },
105 ],
d27ac462 106
721c29ff
AN
107 tooltip: [
108 {
109 start: 'hide',
110 end: 'hidden',
111 },
112 {
113 start: 'show',
114 end: 'shown',
115 },
116 ],
117};
118
119export default () => {
120 Object.entries(moduleTransitions).forEach(([key, pairs]) => {
121 pairs.forEach(pair => {
122 const eventStart = `${pair.start}.bs.${key}`;
123 const eventEnd = `${pair.end}.bs.${key}`;
94376c69 124 jQuery(document.body).on(eventStart, e => {
d27ac462 125 M.util.js_pending(eventEnd);
94376c69
AN
126 jQuery(e.target).one(eventEnd, () => {
127 M.util.js_complete(eventEnd);
128 });
d27ac462
AN
129 });
130
d27ac462
AN
131 });
132 });
721c29ff 133};