util.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
  3. typeof define === 'function' && define.amd ? define(['jquery'], factory) :
  4. (global.Util = factory(global.jQuery));
  5. }(this, (function ($) { 'use strict';
  6. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  7. /**
  8. * --------------------------------------------------------------------------
  9. * Bootstrap (v4.1.3): util.js
  10. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  11. * --------------------------------------------------------------------------
  12. */
  13. var Util = function ($$$1) {
  14. /**
  15. * ------------------------------------------------------------------------
  16. * Private TransitionEnd Helpers
  17. * ------------------------------------------------------------------------
  18. */
  19. var TRANSITION_END = 'transitionend';
  20. var MAX_UID = 1000000;
  21. var MILLISECONDS_MULTIPLIER = 1000; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
  22. function toType(obj) {
  23. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  24. }
  25. function getSpecialTransitionEndEvent() {
  26. return {
  27. bindType: TRANSITION_END,
  28. delegateType: TRANSITION_END,
  29. handle: function handle(event) {
  30. if ($$$1(event.target).is(this)) {
  31. return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
  32. }
  33. return undefined; // eslint-disable-line no-undefined
  34. }
  35. };
  36. }
  37. function transitionEndEmulator(duration) {
  38. var _this = this;
  39. var called = false;
  40. $$$1(this).one(Util.TRANSITION_END, function () {
  41. called = true;
  42. });
  43. setTimeout(function () {
  44. if (!called) {
  45. Util.triggerTransitionEnd(_this);
  46. }
  47. }, duration);
  48. return this;
  49. }
  50. function setTransitionEndSupport() {
  51. $$$1.fn.emulateTransitionEnd = transitionEndEmulator;
  52. $$$1.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  53. }
  54. /**
  55. * --------------------------------------------------------------------------
  56. * Public Util Api
  57. * --------------------------------------------------------------------------
  58. */
  59. var Util = {
  60. TRANSITION_END: 'bsTransitionEnd',
  61. getUID: function getUID(prefix) {
  62. do {
  63. // eslint-disable-next-line no-bitwise
  64. prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
  65. } while (document.getElementById(prefix));
  66. return prefix;
  67. },
  68. getSelectorFromElement: function getSelectorFromElement(element) {
  69. var selector = element.getAttribute('data-target');
  70. if (!selector || selector === '#') {
  71. selector = element.getAttribute('href') || '';
  72. }
  73. try {
  74. return document.querySelector(selector) ? selector : null;
  75. } catch (err) {
  76. return null;
  77. }
  78. },
  79. getTransitionDurationFromElement: function getTransitionDurationFromElement(element) {
  80. if (!element) {
  81. return 0;
  82. } // Get transition-duration of the element
  83. var transitionDuration = $$$1(element).css('transition-duration');
  84. var floatTransitionDuration = parseFloat(transitionDuration); // Return 0 if element or transition duration is not found
  85. if (!floatTransitionDuration) {
  86. return 0;
  87. } // If multiple durations are defined, take the first
  88. transitionDuration = transitionDuration.split(',')[0];
  89. return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER;
  90. },
  91. reflow: function reflow(element) {
  92. return element.offsetHeight;
  93. },
  94. triggerTransitionEnd: function triggerTransitionEnd(element) {
  95. $$$1(element).trigger(TRANSITION_END);
  96. },
  97. // TODO: Remove in v5
  98. supportsTransitionEnd: function supportsTransitionEnd() {
  99. return Boolean(TRANSITION_END);
  100. },
  101. isElement: function isElement(obj) {
  102. return (obj[0] || obj).nodeType;
  103. },
  104. typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
  105. for (var property in configTypes) {
  106. if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
  107. var expectedTypes = configTypes[property];
  108. var value = config[property];
  109. var valueType = value && Util.isElement(value) ? 'element' : toType(value);
  110. if (!new RegExp(expectedTypes).test(valueType)) {
  111. throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
  112. }
  113. }
  114. }
  115. }
  116. };
  117. setTransitionEndSupport();
  118. return Util;
  119. }($);
  120. return Util;
  121. })));
  122. //# sourceMappingURL=util.js.map