util.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*!
  2. * Bootstrap util.js v4.6.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
  8. typeof define === 'function' && define.amd ? define(['jquery'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Util = factory(global.jQuery));
  10. })(this, (function ($) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var $__default = /*#__PURE__*/_interopDefaultLegacy($);
  13. /**
  14. * --------------------------------------------------------------------------
  15. * Bootstrap (v4.6.2): util.js
  16. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  17. * --------------------------------------------------------------------------
  18. */
  19. /**
  20. * Private TransitionEnd Helpers
  21. */
  22. var TRANSITION_END = 'transitionend';
  23. var MAX_UID = 1000000;
  24. var MILLISECONDS_MULTIPLIER = 1000; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
  25. function toType(obj) {
  26. if (obj === null || typeof obj === 'undefined') {
  27. return "" + obj;
  28. }
  29. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  30. }
  31. function getSpecialTransitionEndEvent() {
  32. return {
  33. bindType: TRANSITION_END,
  34. delegateType: TRANSITION_END,
  35. handle: function handle(event) {
  36. if ($__default["default"](event.target).is(this)) {
  37. return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
  38. }
  39. return undefined;
  40. }
  41. };
  42. }
  43. function transitionEndEmulator(duration) {
  44. var _this = this;
  45. var called = false;
  46. $__default["default"](this).one(Util.TRANSITION_END, function () {
  47. called = true;
  48. });
  49. setTimeout(function () {
  50. if (!called) {
  51. Util.triggerTransitionEnd(_this);
  52. }
  53. }, duration);
  54. return this;
  55. }
  56. function setTransitionEndSupport() {
  57. $__default["default"].fn.emulateTransitionEnd = transitionEndEmulator;
  58. $__default["default"].event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  59. }
  60. /**
  61. * Public Util API
  62. */
  63. var Util = {
  64. TRANSITION_END: 'bsTransitionEnd',
  65. getUID: function getUID(prefix) {
  66. do {
  67. // eslint-disable-next-line no-bitwise
  68. prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
  69. } while (document.getElementById(prefix));
  70. return prefix;
  71. },
  72. getSelectorFromElement: function getSelectorFromElement(element) {
  73. var selector = element.getAttribute('data-target');
  74. if (!selector || selector === '#') {
  75. var hrefAttr = element.getAttribute('href');
  76. selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
  77. }
  78. try {
  79. return document.querySelector(selector) ? selector : null;
  80. } catch (_) {
  81. return null;
  82. }
  83. },
  84. getTransitionDurationFromElement: function getTransitionDurationFromElement(element) {
  85. if (!element) {
  86. return 0;
  87. } // Get transition-duration of the element
  88. var transitionDuration = $__default["default"](element).css('transition-duration');
  89. var transitionDelay = $__default["default"](element).css('transition-delay');
  90. var floatTransitionDuration = parseFloat(transitionDuration);
  91. var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
  92. if (!floatTransitionDuration && !floatTransitionDelay) {
  93. return 0;
  94. } // If multiple durations are defined, take the first
  95. transitionDuration = transitionDuration.split(',')[0];
  96. transitionDelay = transitionDelay.split(',')[0];
  97. return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  98. },
  99. reflow: function reflow(element) {
  100. return element.offsetHeight;
  101. },
  102. triggerTransitionEnd: function triggerTransitionEnd(element) {
  103. $__default["default"](element).trigger(TRANSITION_END);
  104. },
  105. supportsTransitionEnd: function supportsTransitionEnd() {
  106. return Boolean(TRANSITION_END);
  107. },
  108. isElement: function isElement(obj) {
  109. return (obj[0] || obj).nodeType;
  110. },
  111. typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
  112. for (var property in configTypes) {
  113. if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
  114. var expectedTypes = configTypes[property];
  115. var value = config[property];
  116. var valueType = value && Util.isElement(value) ? 'element' : toType(value);
  117. if (!new RegExp(expectedTypes).test(valueType)) {
  118. throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
  119. }
  120. }
  121. }
  122. },
  123. findShadowRoot: function findShadowRoot(element) {
  124. if (!document.documentElement.attachShadow) {
  125. return null;
  126. } // Can find the shadow root otherwise it'll return the document
  127. if (typeof element.getRootNode === 'function') {
  128. var root = element.getRootNode();
  129. return root instanceof ShadowRoot ? root : null;
  130. }
  131. if (element instanceof ShadowRoot) {
  132. return element;
  133. } // when we don't find a shadow root
  134. if (!element.parentNode) {
  135. return null;
  136. }
  137. return Util.findShadowRoot(element.parentNode);
  138. },
  139. jQueryDetection: function jQueryDetection() {
  140. if (typeof $__default["default"] === 'undefined') {
  141. throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.');
  142. }
  143. var version = $__default["default"].fn.jquery.split(' ')[0].split('.');
  144. var minMajor = 1;
  145. var ltMajor = 2;
  146. var minMinor = 9;
  147. var minPatch = 1;
  148. var maxMajor = 4;
  149. if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
  150. throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0');
  151. }
  152. }
  153. };
  154. Util.jQueryDetection();
  155. setTransitionEndSupport();
  156. return Util;
  157. }));
  158. //# sourceMappingURL=util.js.map