util.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*!
  2. * Bootstrap util.js v4.4.1 (https://getbootstrap.com/)
  3. * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/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 = global || self, global.Util = factory(global.jQuery));
  10. }(this, (function ($) { 'use strict';
  11. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  12. /**
  13. * --------------------------------------------------------------------------
  14. * Bootstrap (v4.4.1): util.js
  15. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  16. * --------------------------------------------------------------------------
  17. */
  18. /**
  19. * ------------------------------------------------------------------------
  20. * Private TransitionEnd Helpers
  21. * ------------------------------------------------------------------------
  22. */
  23. var TRANSITION_END = 'transitionend';
  24. var MAX_UID = 1000000;
  25. var MILLISECONDS_MULTIPLIER = 1000; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
  26. function toType(obj) {
  27. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  28. }
  29. function getSpecialTransitionEndEvent() {
  30. return {
  31. bindType: TRANSITION_END,
  32. delegateType: TRANSITION_END,
  33. handle: function handle(event) {
  34. if ($(event.target).is(this)) {
  35. return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
  36. }
  37. return undefined; // eslint-disable-line no-undefined
  38. }
  39. };
  40. }
  41. function transitionEndEmulator(duration) {
  42. var _this = this;
  43. var called = false;
  44. $(this).one(Util.TRANSITION_END, function () {
  45. called = true;
  46. });
  47. setTimeout(function () {
  48. if (!called) {
  49. Util.triggerTransitionEnd(_this);
  50. }
  51. }, duration);
  52. return this;
  53. }
  54. function setTransitionEndSupport() {
  55. $.fn.emulateTransitionEnd = transitionEndEmulator;
  56. $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  57. }
  58. /**
  59. * --------------------------------------------------------------------------
  60. * Public Util Api
  61. * --------------------------------------------------------------------------
  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 (err) {
  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 = $(element).css('transition-duration');
  89. var transitionDelay = $(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. $(element).trigger(TRANSITION_END);
  104. },
  105. // TODO: Remove in v5
  106. supportsTransitionEnd: function supportsTransitionEnd() {
  107. return Boolean(TRANSITION_END);
  108. },
  109. isElement: function isElement(obj) {
  110. return (obj[0] || obj).nodeType;
  111. },
  112. typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
  113. for (var property in configTypes) {
  114. if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
  115. var expectedTypes = configTypes[property];
  116. var value = config[property];
  117. var valueType = value && Util.isElement(value) ? 'element' : toType(value);
  118. if (!new RegExp(expectedTypes).test(valueType)) {
  119. throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
  120. }
  121. }
  122. }
  123. },
  124. findShadowRoot: function findShadowRoot(element) {
  125. if (!document.documentElement.attachShadow) {
  126. return null;
  127. } // Can find the shadow root otherwise it'll return the document
  128. if (typeof element.getRootNode === 'function') {
  129. var root = element.getRootNode();
  130. return root instanceof ShadowRoot ? root : null;
  131. }
  132. if (element instanceof ShadowRoot) {
  133. return element;
  134. } // when we don't find a shadow root
  135. if (!element.parentNode) {
  136. return null;
  137. }
  138. return Util.findShadowRoot(element.parentNode);
  139. },
  140. jQueryDetection: function jQueryDetection() {
  141. if (typeof $ === 'undefined') {
  142. throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.');
  143. }
  144. var version = $.fn.jquery.split(' ')[0].split('.');
  145. var minMajor = 1;
  146. var ltMajor = 2;
  147. var minMinor = 9;
  148. var minPatch = 1;
  149. var maxMajor = 4;
  150. if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
  151. throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0');
  152. }
  153. }
  154. };
  155. Util.jQueryDetection();
  156. setTransitionEndSupport();
  157. return Util;
  158. })));
  159. //# sourceMappingURL=util.js.map