Issues (141)

resources/bootstrap/js/util.js (1 issue)

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 View Code Duplication
(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
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
16
  /**
17
   * --------------------------------------------------------------------------
18
   * Bootstrap (v4.6.2): util.js
19
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
20
   * --------------------------------------------------------------------------
21
   */
22
  /**
23
   * Private TransitionEnd Helpers
24
   */
25
26
  var TRANSITION_END = 'transitionend';
27
  var MAX_UID = 1000000;
28
  var MILLISECONDS_MULTIPLIER = 1000; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
29
30
  function toType(obj) {
31
    if (obj === null || typeof obj === 'undefined') {
32
      return "" + obj;
33
    }
34
35
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
36
  }
37
38
  function getSpecialTransitionEndEvent() {
39
    return {
40
      bindType: TRANSITION_END,
41
      delegateType: TRANSITION_END,
42
      handle: function handle(event) {
43
        if ($__default["default"](event.target).is(this)) {
44
          return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
45
        }
46
47
        return undefined;
48
      }
49
    };
50
  }
51
52
  function transitionEndEmulator(duration) {
53
    var _this = this;
54
55
    var called = false;
56
    $__default["default"](this).one(Util.TRANSITION_END, function () {
57
      called = true;
58
    });
59
    setTimeout(function () {
60
      if (!called) {
61
        Util.triggerTransitionEnd(_this);
62
      }
63
    }, duration);
64
    return this;
65
  }
66
67
  function setTransitionEndSupport() {
68
    $__default["default"].fn.emulateTransitionEnd = transitionEndEmulator;
69
    $__default["default"].event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
70
  }
71
  /**
72
   * Public Util API
73
   */
74
75
76
  var Util = {
77
    TRANSITION_END: 'bsTransitionEnd',
78
    getUID: function getUID(prefix) {
79
      do {
80
        // eslint-disable-next-line no-bitwise
81
        prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
82
      } while (document.getElementById(prefix));
83
84
      return prefix;
85
    },
86
    getSelectorFromElement: function getSelectorFromElement(element) {
87
      var selector = element.getAttribute('data-target');
88
89
      if (!selector || selector === '#') {
90
        var hrefAttr = element.getAttribute('href');
91
        selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
92
      }
93
94
      try {
95
        return document.querySelector(selector) ? selector : null;
96
      } catch (_) {
97
        return null;
98
      }
99
    },
100
    getTransitionDurationFromElement: function getTransitionDurationFromElement(element) {
101
      if (!element) {
102
        return 0;
103
      } // Get transition-duration of the element
104
105
106
      var transitionDuration = $__default["default"](element).css('transition-duration');
107
      var transitionDelay = $__default["default"](element).css('transition-delay');
108
      var floatTransitionDuration = parseFloat(transitionDuration);
109
      var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
110
111
      if (!floatTransitionDuration && !floatTransitionDelay) {
112
        return 0;
113
      } // If multiple durations are defined, take the first
114
115
116
      transitionDuration = transitionDuration.split(',')[0];
117
      transitionDelay = transitionDelay.split(',')[0];
118
      return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
119
    },
120
    reflow: function reflow(element) {
121
      return element.offsetHeight;
122
    },
123
    triggerTransitionEnd: function triggerTransitionEnd(element) {
124
      $__default["default"](element).trigger(TRANSITION_END);
125
    },
126
    supportsTransitionEnd: function supportsTransitionEnd() {
127
      return Boolean(TRANSITION_END);
128
    },
129
    isElement: function isElement(obj) {
130
      return (obj[0] || obj).nodeType;
131
    },
132
    typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
133
      for (var property in configTypes) {
0 ignored issues
show
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
134
        if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
135
          var expectedTypes = configTypes[property];
136
          var value = config[property];
137
          var valueType = value && Util.isElement(value) ? 'element' : toType(value);
138
139
          if (!new RegExp(expectedTypes).test(valueType)) {
140
            throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
141
          }
142
        }
143
      }
144
    },
145
    findShadowRoot: function findShadowRoot(element) {
146
      if (!document.documentElement.attachShadow) {
147
        return null;
148
      } // Can find the shadow root otherwise it'll return the document
149
150
151
      if (typeof element.getRootNode === 'function') {
152
        var root = element.getRootNode();
153
        return root instanceof ShadowRoot ? root : null;
154
      }
155
156
      if (element instanceof ShadowRoot) {
157
        return element;
158
      } // when we don't find a shadow root
159
160
161
      if (!element.parentNode) {
162
        return null;
163
      }
164
165
      return Util.findShadowRoot(element.parentNode);
166
    },
167
    jQueryDetection: function jQueryDetection() {
168
      if (typeof $__default["default"] === 'undefined') {
169
        throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.');
170
      }
171
172
      var version = $__default["default"].fn.jquery.split(' ')[0].split('.');
173
      var minMajor = 1;
174
      var ltMajor = 2;
175
      var minMinor = 9;
176
      var minPatch = 1;
177
      var maxMajor = 4;
178
179
      if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
180
        throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0');
181
      }
182
    }
183
  };
184
  Util.jQueryDetection();
185
  setTransitionEndSupport();
186
187
  return Util;
188
189
}));
190
//# sourceMappingURL=util.js.map
191