theme/boost/amd/src/pending.js

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