MDL-65447 theme: Apply pendingJS checks to BS transitions
[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 */
23define(['jquery'], function($) {
24 var moduleTransitions = {
25 alert: [
26 // Alert.
27 {
28 start: 'close',
29 end: 'closed',
30 },
31 ],
32
33 carousel: [
34 {
35 start: 'slide',
36 end: 'slid',
37 },
38 ],
39
40 collapse: [
41 {
42 start: 'hide',
43 end: 'hidden',
44 },
45 {
46 start: 'show',
47 end: 'shown',
48 },
49 ],
50
51 dropdown: [
52 {
53 start: 'hide',
54 end: 'hidden',
55 },
56 {
57 start: 'show',
58 end: 'shown',
59 },
60 ],
61
62 modal: [
63 {
64 start: 'hide',
65 end: 'hidden',
66 },
67 {
68 start: 'show',
69 end: 'shown',
70 },
71 ],
72
73 popover: [
74 {
75 start: 'hide',
76 end: 'hidden',
77 },
78 {
79 start: 'show',
80 end: 'shown',
81 },
82 ],
83
84 tab: [
85 {
86 start: 'hide',
87 end: 'hidden',
88 },
89 {
90 start: 'show',
91 end: 'shown',
92 },
93 ],
94
95 tooltip: [
96 {
97 start: 'hide',
98 end: 'hidden',
99 },
100 {
101 start: 'show',
102 end: 'shown',
103 },
104 ],
105 };
106
107 Object.keys(moduleTransitions).forEach(function(key) {
108 moduleTransitions[key].forEach(function(pair) {
109 var eventStart = pair.start + '.bs.' + key;
110 var eventEnd = pair.end + '.bs.' + key;
111 $(document.body).on(eventStart, function() {
112 M.util.js_pending(eventEnd);
113 });
114
115 $(document.body).on(eventEnd, function() {
116 M.util.js_complete(eventEnd);
117 });
118 });
119 });
120});