bootstrap.bundle.js 244 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
2001
        activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY$3) : null;
Mark Otto's avatar
dist    
Mark Otto committed
2002

XhmikosR's avatar
Dist    
XhmikosR committed
2003
        if (activesData && activesData._isTransitioning) {
Mark Otto's avatar
dist    
Mark Otto committed
2004
2005
          return;
        }
XhmikosR's avatar
Dist    
XhmikosR committed
2006
      }
Mark Otto's avatar
dist  
Mark Otto committed
2007

XhmikosR's avatar
XhmikosR committed
2008
      var startEvent = EventHandler.trigger(this._element, Event$4.SHOW);
Mark Otto's avatar
dist  
Mark Otto committed
2009

XhmikosR's avatar
XhmikosR committed
2010
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2011
2012
        return;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2013

XhmikosR's avatar
Dist    
XhmikosR committed
2014
      if (actives) {
XhmikosR's avatar
XhmikosR committed
2015
2016
2017
2018
        actives.forEach(function (elemActive) {
          if (container !== elemActive) {
            Collapse._collapseInterface(elemActive, 'hide');
          }
Mark Otto's avatar
dist  
Mark Otto committed
2019

XhmikosR's avatar
XhmikosR committed
2020
2021
2022
2023
          if (!activesData) {
            Data.setData(elemActive, DATA_KEY$3, null);
          }
        });
XhmikosR's avatar
Dist    
XhmikosR committed
2024
      }
Mark Otto's avatar
dist  
Mark Otto committed
2025

XhmikosR's avatar
Dist    
XhmikosR committed
2026
      var dimension = this._getDimension();
Mark Otto's avatar
dist  
Mark Otto committed
2027

XhmikosR's avatar
XhmikosR committed
2028
2029
2030
2031
      this._element.classList.remove(ClassName$3.COLLAPSE);

      this._element.classList.add(ClassName$3.COLLAPSING);

XhmikosR's avatar
Dist    
XhmikosR committed
2032
      this._element.style[dimension] = 0;
Mark Otto's avatar
dist  
Mark Otto committed
2033

XhmikosR's avatar
Dist    
XhmikosR committed
2034
      if (this._triggerArray.length) {
XhmikosR's avatar
XhmikosR committed
2035
2036
2037
2038
        this._triggerArray.forEach(function (element) {
          element.classList.remove(ClassName$3.COLLAPSED);
          element.setAttribute('aria-expanded', true);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
2039
      }
Mark Otto's avatar
dist  
Mark Otto committed
2040

XhmikosR's avatar
Dist    
XhmikosR committed
2041
      this.setTransitioning(true);
Mark Otto's avatar
dist  
Mark Otto committed
2042

XhmikosR's avatar
Dist    
XhmikosR committed
2043
      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
2044
2045
2046
2047
2048
2049
        _this._element.classList.remove(ClassName$3.COLLAPSING);

        _this._element.classList.add(ClassName$3.COLLAPSE);

        _this._element.classList.add(ClassName$3.SHOW);

XhmikosR's avatar
Dist    
XhmikosR committed
2050
2051
2052
2053
        _this._element.style[dimension] = '';

        _this.setTransitioning(false);

XhmikosR's avatar
XhmikosR committed
2054
        EventHandler.trigger(_this._element, Event$4.SHOWN);
Mark Otto's avatar
dist    
Mark Otto committed
2055
      };
Mark Otto's avatar
dist  
Mark Otto committed
2056

XhmikosR's avatar
Dist    
XhmikosR committed
2057
2058
      var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
      var scrollSize = "scroll" + capitalizedDimension;
XhmikosR's avatar
XhmikosR committed
2059
2060
2061
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2062
2063
      this._element.style[dimension] = this._element[scrollSize] + "px";
    };
Mark Otto's avatar
dist  
Mark Otto committed
2064

XhmikosR's avatar
Dist    
XhmikosR committed
2065
2066
2067
    _proto.hide = function hide() {
      var _this2 = this;

XhmikosR's avatar
XhmikosR committed
2068
      if (this._isTransitioning || !this._element.classList.contains(ClassName$3.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2069
2070
        return;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2071

XhmikosR's avatar
XhmikosR committed
2072
      var startEvent = EventHandler.trigger(this._element, Event$4.HIDE);
Mark Otto's avatar
dist    
Mark Otto committed
2073

XhmikosR's avatar
XhmikosR committed
2074
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2075
2076
        return;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2077

XhmikosR's avatar
Dist    
XhmikosR committed
2078
      var dimension = this._getDimension();
Mark Otto's avatar
dist  
Mark Otto committed
2079

XhmikosR's avatar
Dist    
XhmikosR committed
2080
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
2081
2082
2083
2084
2085
2086
2087
2088
      reflow(this._element);

      this._element.classList.add(ClassName$3.COLLAPSING);

      this._element.classList.remove(ClassName$3.COLLAPSE);

      this._element.classList.remove(ClassName$3.SHOW);

XhmikosR's avatar
Dist    
XhmikosR committed
2089
      var triggerArrayLength = this._triggerArray.length;
Mark Otto's avatar
dist  
Mark Otto committed
2090

XhmikosR's avatar
Dist    
XhmikosR committed
2091
2092
2093
      if (triggerArrayLength > 0) {
        for (var i = 0; i < triggerArrayLength; i++) {
          var trigger = this._triggerArray[i];
XhmikosR's avatar
XhmikosR committed
2094
          var selector = getSelectorFromElement(trigger);
Mark Otto's avatar
dist    
Mark Otto committed
2095

XhmikosR's avatar
Dist    
XhmikosR committed
2096
          if (selector !== null) {
XhmikosR's avatar
XhmikosR committed
2097
            var elem = SelectorEngine.findOne(selector);
Mark Otto's avatar
dist    
Mark Otto committed
2098

XhmikosR's avatar
XhmikosR committed
2099
2100
2101
            if (!elem.classList.contains(ClassName$3.SHOW)) {
              trigger.classList.add(ClassName$3.COLLAPSED);
              trigger.setAttribute('aria-expanded', false);
Mark Otto's avatar
dist  
Mark Otto committed
2102
2103
2104
            }
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
2105
      }
Mark Otto's avatar
dist  
Mark Otto committed
2106

XhmikosR's avatar
Dist    
XhmikosR committed
2107
      this.setTransitioning(true);
Mark Otto's avatar
dist  
Mark Otto committed
2108

XhmikosR's avatar
Dist    
XhmikosR committed
2109
2110
      var complete = function complete() {
        _this2.setTransitioning(false);
Mark Otto's avatar
dist  
Mark Otto committed
2111

XhmikosR's avatar
XhmikosR committed
2112
2113
2114
2115
2116
        _this2._element.classList.remove(ClassName$3.COLLAPSING);

        _this2._element.classList.add(ClassName$3.COLLAPSE);

        EventHandler.trigger(_this2._element, Event$4.HIDDEN);
Mark Otto's avatar
dist    
Mark Otto committed
2117
      };
Mark Otto's avatar
dist  
Mark Otto committed
2118

XhmikosR's avatar
Dist    
XhmikosR committed
2119
      this._element.style[dimension] = '';
XhmikosR's avatar
XhmikosR committed
2120
2121
2122
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2123
    };
Mark Otto's avatar
dist  
Mark Otto committed
2124

XhmikosR's avatar
Dist    
XhmikosR committed
2125
2126
2127
    _proto.setTransitioning = function setTransitioning(isTransitioning) {
      this._isTransitioning = isTransitioning;
    };
Mark Otto's avatar
dist  
Mark Otto committed
2128

XhmikosR's avatar
Dist    
XhmikosR committed
2129
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
2130
      Data.removeData(this._element, DATA_KEY$3);
XhmikosR's avatar
Dist    
XhmikosR committed
2131
2132
2133
2134
2135
      this._config = null;
      this._parent = null;
      this._element = null;
      this._triggerArray = null;
      this._isTransitioning = null;
Mark Otto's avatar
Mark Otto committed
2136
2137
    } // Private
    ;
Mark Otto's avatar
dist    
Mark Otto committed
2138

XhmikosR's avatar
Dist    
XhmikosR committed
2139
    _proto._getConfig = function _getConfig(config) {
2140
      config = _objectSpread2({}, Default$1, {}, config);
XhmikosR's avatar
Dist    
XhmikosR committed
2141
      config.toggle = Boolean(config.toggle); // Coerce string values
Mark Otto's avatar
dist  
Mark Otto committed
2142

XhmikosR's avatar
XhmikosR committed
2143
      typeCheckConfig(NAME$3, config, DefaultType$1);
XhmikosR's avatar
Dist    
XhmikosR committed
2144
2145
      return config;
    };
Mark Otto's avatar
dist  
Mark Otto committed
2146

XhmikosR's avatar
Dist    
XhmikosR committed
2147
    _proto._getDimension = function _getDimension() {
XhmikosR's avatar
XhmikosR committed
2148
2149
      var hasWidth = this._element.classList.contains(Dimension.WIDTH);

XhmikosR's avatar
Dist    
XhmikosR committed
2150
2151
      return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT;
    };
Mark Otto's avatar
dist  
Mark Otto committed
2152

XhmikosR's avatar
Dist    
XhmikosR committed
2153
2154
    _proto._getParent = function _getParent() {
      var _this3 = this;
Mark Otto's avatar
dist  
Mark Otto committed
2155

XhmikosR's avatar
Dist.    
XhmikosR committed
2156
      var parent = this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
2157

XhmikosR's avatar
Dist.    
XhmikosR committed
2158
2159
2160
2161
      if (isElement(parent)) {
        // it's a jQuery object
        if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') {
          parent = parent[0];
XhmikosR's avatar
Dist    
XhmikosR committed
2162
2163
        }
      } else {
XhmikosR's avatar
Dist.    
XhmikosR committed
2164
        parent = SelectorEngine.findOne(parent);
XhmikosR's avatar
Dist    
XhmikosR committed
2165
      }
Mark Otto's avatar
dist  
Mark Otto committed
2166

XhmikosR's avatar
Dist.    
XhmikosR committed
2167
      var selector = "[data-toggle=\"collapse\"][data-parent=\"" + parent + "\"]";
XhmikosR's avatar
XhmikosR committed
2168
      makeArray(SelectorEngine.find(selector, parent)).forEach(function (element) {
2169
2170
2171
2172
        var selector = getSelectorFromElement(element);
        var selected = selector ? SelectorEngine.findOne(selector) : null;

        _this3._addAriaAndCollapsedClass(selected, [element]);
XhmikosR's avatar
Dist    
XhmikosR committed
2173
2174
2175
      });
      return parent;
    };
Mark Otto's avatar
dist  
Mark Otto committed
2176

XhmikosR's avatar
XhmikosR committed
2177
2178
2179
2180
2181
2182
    _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) {
      if (element) {
        var isOpen = element.classList.contains(ClassName$3.SHOW);

        if (triggerArray.length) {
          triggerArray.forEach(function (elem) {
XhmikosR's avatar
Dist.    
XhmikosR committed
2183
            if (isOpen) {
XhmikosR's avatar
XhmikosR committed
2184
              elem.classList.remove(ClassName$3.COLLAPSED);
XhmikosR's avatar
Dist.    
XhmikosR committed
2185
2186
            } else {
              elem.classList.add(ClassName$3.COLLAPSED);
XhmikosR's avatar
XhmikosR committed
2187
            }
Mark Otto's avatar
dist  
Mark Otto committed
2188

XhmikosR's avatar
XhmikosR committed
2189
2190
2191
            elem.setAttribute('aria-expanded', isOpen);
          });
        }
XhmikosR's avatar
Dist    
XhmikosR committed
2192
      }
Mark Otto's avatar
Mark Otto committed
2193
2194
    } // Static
    ;
Mark Otto's avatar
dist  
Mark Otto committed
2195

XhmikosR's avatar
XhmikosR committed
2196
2197
    Collapse._collapseInterface = function _collapseInterface(element, config) {
      var data = Data.getData(element, DATA_KEY$3);
Mark Otto's avatar
dist  
Mark Otto committed
2198

2199
      var _config = _objectSpread2({}, Default$1, {}, Manipulator.getDataAttributes(element), {}, typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist  
Mark Otto committed
2200

XhmikosR's avatar
XhmikosR committed
2201
2202
2203
      if (!data && _config.toggle && /show|hide/.test(config)) {
        _config.toggle = false;
      }
Mark Otto's avatar
dist    
Mark Otto committed
2204

XhmikosR's avatar
XhmikosR committed
2205
2206
2207
2208
2209
2210
      if (!data) {
        data = new Collapse(element, _config);
      }

      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
2211
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
2212
        }
Mark Otto's avatar
dist  
Mark Otto committed
2213

XhmikosR's avatar
XhmikosR committed
2214
2215
2216
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
2217

XhmikosR's avatar
XhmikosR committed
2218
2219
2220
    Collapse._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        Collapse._collapseInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
2221
2222
      });
    };
Mark Otto's avatar
dist  
Mark Otto committed
2223

XhmikosR's avatar
XhmikosR committed
2224
2225
2226
2227
    Collapse._getInstance = function _getInstance(element) {
      return Data.getData(element, DATA_KEY$3);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
    _createClass(Collapse, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION$3;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default$1;
      }
    }]);
Mark Otto's avatar
dist  
Mark Otto committed
2239

XhmikosR's avatar
Dist    
XhmikosR committed
2240
2241
2242
2243
2244
2245
2246
    return Collapse;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
Mark Otto's avatar
dist    
Mark Otto committed
2247

Mark Otto's avatar
dist  
Mark Otto committed
2248

XhmikosR's avatar
XhmikosR committed
2249
  EventHandler.on(document, Event$4.CLICK_DATA_API, Selector$3.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2250
    // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
XhmikosR's avatar
XhmikosR committed
2251
    if (event.target.tagName === 'A') {
XhmikosR's avatar
Dist    
XhmikosR committed
2252
2253
      event.preventDefault();
    }
Mark Otto's avatar
dist    
Mark Otto committed
2254

XhmikosR's avatar
XhmikosR committed
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
    var triggerData = Manipulator.getDataAttributes(this);
    var selector = getSelectorFromElement(this);
    var selectorElements = makeArray(SelectorEngine.find(selector));
    selectorElements.forEach(function (element) {
      var data = Data.getData(element, DATA_KEY$3);
      var config;

      if (data) {
        // update parent attribute
        if (data._parent === null && typeof triggerData.parent === 'string') {
          data._config.parent = triggerData.parent;
          data._parent = data._getParent();
        }

        config = 'toggle';
      } else {
        config = triggerData;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2273

XhmikosR's avatar
XhmikosR committed
2274
      Collapse._collapseInterface(element, config);
XhmikosR's avatar
Dist    
XhmikosR committed
2275
2276
2277
2278
2279
2280
    });
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
2281
   * add .collapse to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
2282
   */
Mark Otto's avatar
dist    
Mark Otto committed
2283

2284
2285
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
2286
2287
2288
2289
  if (typeof jQuery !== 'undefined') {
    var JQUERY_NO_CONFLICT$3 = jQuery.fn[NAME$3];
    jQuery.fn[NAME$3] = Collapse._jQueryInterface;
    jQuery.fn[NAME$3].Constructor = Collapse;
Mark Otto's avatar
dist  
Mark Otto committed
2290

XhmikosR's avatar
XhmikosR committed
2291
2292
2293
2294
2295
    jQuery.fn[NAME$3].noConflict = function () {
      jQuery.fn[NAME$3] = JQUERY_NO_CONFLICT$3;
      return Collapse._jQueryInterface;
    };
  }
Mark Otto's avatar
dist  
Mark Otto committed
2296

Mark Otto's avatar
dist    
Mark Otto committed
2297
2298
  /**!
   * @fileOverview Kickass library to create and place poppers near their reference elements.
XhmikosR's avatar
XhmikosR committed
2299
   * @version 1.15.0
Mark Otto's avatar
dist    
Mark Otto committed
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
   * @license
   * Copyright (c) 2016 Federico Zivolo and contributors
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in all
   * copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   * SOFTWARE.
   */
  var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
Mark Otto's avatar
dist    
Mark Otto committed
2322

Mark Otto's avatar
dist    
Mark Otto committed
2323
2324
2325
2326
2327
2328
  var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
  var timeoutDuration = 0;
  for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
    if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
      timeoutDuration = 1;
      break;
Mark Otto's avatar
dist  
Mark Otto committed
2329
    }
Mark Otto's avatar
dist    
Mark Otto committed
2330
  }
Mark Otto's avatar
dist  
Mark Otto committed
2331

Mark Otto's avatar
dist    
Mark Otto committed
2332
2333
2334
2335
2336
2337
2338
2339
2340
  function microtaskDebounce(fn) {
    var called = false;
    return function () {
      if (called) {
        return;
      }
      called = true;
      window.Promise.resolve().then(function () {
        called = false;
Mark Otto's avatar
dist  
Mark Otto committed
2341
        fn();
Mark Otto's avatar
dist    
Mark Otto committed
2342
2343
      });
    };
Mark Otto's avatar
dist  
Mark Otto committed
2344
2345
  }

Mark Otto's avatar
dist    
Mark Otto committed
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
  function taskDebounce(fn) {
    var scheduled = false;
    return function () {
      if (!scheduled) {
        scheduled = true;
        setTimeout(function () {
          scheduled = false;
          fn();
        }, timeoutDuration);
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
2357
2358
  }

Mark Otto's avatar
dist    
Mark Otto committed
2359
  var supportsMicroTasks = isBrowser && window.Promise;
Mark Otto's avatar
dist  
Mark Otto committed
2360

Mark Otto's avatar
dist    
Mark Otto committed
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
  /**
  * Create a debounced version of a method, that's asynchronously deferred
  * but called in the minimum time possible.
  *
  * @method
  * @memberof Popper.Utils
  * @argument {Function} fn
  * @returns {Function}
  */
  var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
Mark Otto's avatar
dist  
Mark Otto committed
2371

Mark Otto's avatar
dist    
Mark Otto committed
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
  /**
   * Check if the given variable is a function
   * @method
   * @memberof Popper.Utils
   * @argument {Any} functionToCheck - variable to check
   * @returns {Boolean} answer to: is a function?
   */
  function isFunction(functionToCheck) {
    var getType = {};
    return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
Mark Otto's avatar
dist  
Mark Otto committed
2382
2383
  }

Mark Otto's avatar
dist    
Mark Otto committed
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
  /**
   * Get CSS computed property of the given element
   * @method
   * @memberof Popper.Utils
   * @argument {Eement} element
   * @argument {String} property
   */
  function getStyleComputedProperty(element, property) {
    if (element.nodeType !== 1) {
      return [];
Mark Otto's avatar
dist    
Mark Otto committed
2394
    }
Mark Otto's avatar
dist    
Mark Otto committed
2395
    // NOTE: 1 DOM access here
XhmikosR's avatar
Dist    
XhmikosR committed
2396
2397
    var window = element.ownerDocument.defaultView;
    var css = window.getComputedStyle(element, null);
Mark Otto's avatar
dist    
Mark Otto committed
2398
    return property ? css[property] : css;
Mark Otto's avatar
dist  
Mark Otto committed
2399
2400
  }

Mark Otto's avatar
dist    
Mark Otto committed
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
  /**
   * Returns the parentNode or the host of the element
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @returns {Element} parent
   */
  function getParentNode(element) {
    if (element.nodeName === 'HTML') {
      return element;
    }
    return element.parentNode || element.host;
Mark Otto's avatar
dist  
Mark Otto committed
2413
2414
  }

Mark Otto's avatar
dist    
Mark Otto committed
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
  /**
   * Returns the scrolling parent of the given element
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @returns {Element} scroll parent
   */
  function getScrollParent(element) {
    // Return body, `getScroll` will take care to get the correct `scrollTop` from it
    if (!element) {
      return document.body;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2427

Mark Otto's avatar
dist    
Mark Otto committed
2428
2429
2430
2431
2432
2433
2434
    switch (element.nodeName) {
      case 'HTML':
      case 'BODY':
        return element.ownerDocument.body;
      case '#document':
        return element.body;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2435

Mark Otto's avatar
dist    
Mark Otto committed
2436
    // Firefox want us to check `-x` and `-y` variations as well
Mark Otto's avatar
dist  
Mark Otto committed
2437

Mark Otto's avatar
dist    
Mark Otto committed
2438
2439
2440
2441
    var _getStyleComputedProp = getStyleComputedProperty(element),
        overflow = _getStyleComputedProp.overflow,
        overflowX = _getStyleComputedProp.overflowX,
        overflowY = _getStyleComputedProp.overflowY;
Mark Otto's avatar
dist  
Mark Otto committed
2442

Mark Otto's avatar
dist    
Mark Otto committed
2443
2444
    if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
      return element;
Mark Otto's avatar
dist  
Mark Otto committed
2445
2446
    }

Mark Otto's avatar
dist    
Mark Otto committed
2447
    return getScrollParent(getParentNode(element));
Mark Otto's avatar
dist  
Mark Otto committed
2448
2449
  }

Mark Otto's avatar
dist    
Mark Otto committed
2450
2451
2452
  var isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
  var isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);

Mark Otto's avatar
dist    
Mark Otto committed
2453
  /**
Mark Otto's avatar
dist    
Mark Otto committed
2454
   * Determines if the browser is Internet Explorer
Mark Otto's avatar
dist    
Mark Otto committed
2455
2456
   * @method
   * @memberof Popper.Utils
Mark Otto's avatar
dist    
Mark Otto committed
2457
   * @param {Number} version to check
Mark Otto's avatar
dist    
Mark Otto committed
2458
2459
   * @returns {Boolean} isIE
   */
Mark Otto's avatar
dist    
Mark Otto committed
2460
2461
2462
  function isIE(version) {
    if (version === 11) {
      return isIE11;
Mark Otto's avatar
dist    
Mark Otto committed
2463
    }
Mark Otto's avatar
dist    
Mark Otto committed
2464
2465
    if (version === 10) {
      return isIE10;
Mark Otto's avatar
dist    
Mark Otto committed
2466
    }
Mark Otto's avatar
dist    
Mark Otto committed
2467
2468
    return isIE11 || isIE10;
  }
Mark Otto's avatar
dist  
Mark Otto committed
2469

Mark Otto's avatar
dist    
Mark Otto committed
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
  /**
   * Returns the offset parent of the given element
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @returns {Element} offset parent
   */
  function getOffsetParent(element) {
    if (!element) {
      return document.documentElement;
Mark Otto's avatar
dist  
Mark Otto committed
2480
2481
    }

Mark Otto's avatar
dist    
Mark Otto committed
2482
    var noOffsetParent = isIE(10) ? document.body : null;
Mark Otto's avatar
dist  
Mark Otto committed
2483

Mark Otto's avatar
dist    
Mark Otto committed
2484
    // NOTE: 1 DOM access here
XhmikosR's avatar
Dist    
XhmikosR committed
2485
    var offsetParent = element.offsetParent || null;
Mark Otto's avatar
dist    
Mark Otto committed
2486
2487
2488
2489
    // Skip hidden elements which don't have an offsetParent
    while (offsetParent === noOffsetParent && element.nextElementSibling) {
      offsetParent = (element = element.nextElementSibling).offsetParent;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2490

Mark Otto's avatar
dist    
Mark Otto committed
2491
    var nodeName = offsetParent && offsetParent.nodeName;
Mark Otto's avatar
dist  
Mark Otto committed
2492

Mark Otto's avatar
dist    
Mark Otto committed
2493
2494
2495
    if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
      return element ? element.ownerDocument.documentElement : document.documentElement;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2496

XhmikosR's avatar
Dist    
XhmikosR committed
2497
    // .offsetParent will return the closest TH, TD or TABLE in case
Mark Otto's avatar
dist    
Mark Otto committed
2498
    // no offsetParent is present, I hate this job...
XhmikosR's avatar
Dist    
XhmikosR committed
2499
    if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
Mark Otto's avatar
dist    
Mark Otto committed
2500
2501
      return getOffsetParent(offsetParent);
    }
Mark Otto's avatar
dist  
Mark Otto committed
2502

Mark Otto's avatar
dist    
Mark Otto committed
2503
    return offsetParent;
Mark Otto's avatar
dist  
Mark Otto committed
2504
2505
  }

Mark Otto's avatar
dist    
Mark Otto committed
2506
2507
  function isOffsetContainer(element) {
    var nodeName = element.nodeName;
Mark Otto's avatar
dist  
Mark Otto committed
2508

Mark Otto's avatar
dist    
Mark Otto committed
2509
2510
    if (nodeName === 'BODY') {
      return false;
Mark Otto's avatar
dist  
Mark Otto committed
2511
    }
Mark Otto's avatar
dist    
Mark Otto committed
2512
    return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
Mark Otto's avatar
dist  
Mark Otto committed
2513
2514
  }

Mark Otto's avatar
dist    
Mark Otto committed
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
  /**
   * Finds the root node (document, shadowDOM root) of the given element
   * @method
   * @memberof Popper.Utils
   * @argument {Element} node
   * @returns {Element} root node
   */
  function getRoot(node) {
    if (node.parentNode !== null) {
      return getRoot(node.parentNode);
    }
Mark Otto's avatar
dist  
Mark Otto committed
2526

Mark Otto's avatar
dist    
Mark Otto committed
2527
    return node;
Mark Otto's avatar
dist  
Mark Otto committed
2528
2529
  }

Mark Otto's avatar
dist    
Mark Otto committed
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
  /**
   * Finds the offset parent common to the two provided nodes
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element1
   * @argument {Element} element2
   * @returns {Element} common offset parent
   */
  function findCommonOffsetParent(element1, element2) {
    // This check is needed to avoid errors in case one of the elements isn't defined for any reason
    if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
      return document.documentElement;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2543

Mark Otto's avatar
dist    
Mark Otto committed
2544
2545
2546
2547
    // Here we make sure to give as "start" the element that comes first in the DOM
    var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
    var start = order ? element1 : element2;
    var end = order ? element2 : element1;
Mark Otto's avatar
dist  
Mark Otto committed
2548

Mark Otto's avatar
dist    
Mark Otto committed
2549
2550
2551
2552
2553
    // Get common ancestor container
    var range = document.createRange();
    range.setStart(start, 0);
    range.setEnd(end, 0);
    var commonAncestorContainer = range.commonAncestorContainer;
Mark Otto's avatar
dist  
Mark Otto committed
2554

Mark Otto's avatar
dist    
Mark Otto committed
2555
    // Both nodes are inside #document
Mark Otto's avatar
dist  
Mark Otto committed
2556

Mark Otto's avatar
dist    
Mark Otto committed
2557
2558
2559
2560
    if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
      if (isOffsetContainer(commonAncestorContainer)) {
        return commonAncestorContainer;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2561

Mark Otto's avatar
dist    
Mark Otto committed
2562
2563
      return getOffsetParent(commonAncestorContainer);
    }
Mark Otto's avatar
dist  
Mark Otto committed
2564

Mark Otto's avatar
dist    
Mark Otto committed
2565
2566
2567
2568
    // one of the nodes is inside shadowDOM, find which one
    var element1root = getRoot(element1);
    if (element1root.host) {
      return findCommonOffsetParent(element1root.host, element2);
Mark Otto's avatar
dist  
Mark Otto committed
2569
    } else {
Mark Otto's avatar
dist    
Mark Otto committed
2570
      return findCommonOffsetParent(element1, getRoot(element2).host);
Mark Otto's avatar
dist  
Mark Otto committed
2571
    }
Mark Otto's avatar
dist    
Mark Otto committed
2572
  }
Mark Otto's avatar
dist  
Mark Otto committed
2573

Mark Otto's avatar
dist    
Mark Otto committed
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
  /**
   * Gets the scroll value of the given element in the given side (top and left)
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @argument {String} side `top` or `left`
   * @returns {number} amount of scrolled pixels
   */
  function getScroll(element) {
    var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
Mark Otto's avatar
dist  
Mark Otto committed
2584

Mark Otto's avatar
dist    
Mark Otto committed
2585
2586
    var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
    var nodeName = element.nodeName;
Mark Otto's avatar
dist  
Mark Otto committed
2587

Mark Otto's avatar
dist    
Mark Otto committed
2588
2589
2590
2591
    if (nodeName === 'BODY' || nodeName === 'HTML') {
      var html = element.ownerDocument.documentElement;
      var scrollingElement = element.ownerDocument.scrollingElement || html;
      return scrollingElement[upperSide];
Mark Otto's avatar
dist  
Mark Otto committed
2592
2593
    }

Mark Otto's avatar
dist    
Mark Otto committed
2594
    return element[upperSide];
Mark Otto's avatar
dist  
Mark Otto committed
2595
2596
  }

Mark Otto's avatar
dist    
Mark Otto committed
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
  /*
   * Sum or subtract the element scroll values (left and top) from a given rect object
   * @method
   * @memberof Popper.Utils
   * @param {Object} rect - Rect object you want to change
   * @param {HTMLElement} element - The element from the function reads the scroll values
   * @param {Boolean} subtract - set to true if you want to subtract the scroll values
   * @return {Object} rect - The modifier rect object
   */
  function includeScroll(rect, element) {
    var subtract = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

    var scrollTop = getScroll(element, 'top');
    var scrollLeft = getScroll(element, 'left');
    var modifier = subtract ? -1 : 1;
    rect.top += scrollTop * modifier;
    rect.bottom += scrollTop * modifier;
    rect.left += scrollLeft * modifier;
    rect.right += scrollLeft * modifier;
    return rect;
  }
Mark Otto's avatar
dist  
Mark Otto committed
2618

Mark Otto's avatar
dist    
Mark Otto committed
2619
2620
2621
2622
2623
2624
2625
2626
2627
  /*
   * Helper to detect borders of a given element
   * @method
   * @memberof Popper.Utils
   * @param {CSSStyleDeclaration} styles
   * Result of `getStyleComputedProperty` on the given element
   * @param {String} axis - `x` or `y`
   * @return {number} borders - The borders size of the given axis
   */
Mark Otto's avatar
dist  
Mark Otto committed
2628

Mark Otto's avatar
dist    
Mark Otto committed
2629
2630
2631
  function getBordersSize(styles, axis) {
    var sideA = axis === 'x' ? 'Left' : 'Top';
    var sideB = sideA === 'Left' ? 'Right' : 'Bottom';
Mark Otto's avatar
dist  
Mark Otto committed
2632

Mark Otto's avatar
dist    
Mark Otto committed
2633
    return parseFloat(styles['border' + sideA + 'Width'], 10) + parseFloat(styles['border' + sideB + 'Width'], 10);
Mark Otto's avatar
dist  
Mark Otto committed
2634
2635
  }

Mark Otto's avatar
dist    
Mark Otto committed
2636
  function getSize(axis, body, html, computedStyle) {
Mark Otto's avatar
dist    
Mark Otto committed
2637
    return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE(10) ? parseInt(html['offset' + axis]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')]) : 0);
Mark Otto's avatar
dist  
Mark Otto committed
2638
2639
  }

Mark Otto's avatar
dist    
Mark Otto committed
2640
  function getWindowSizes(document) {
Mark Otto's avatar
dist    
Mark Otto committed
2641
2642
2643
    var body = document.body;
    var html = document.documentElement;
    var computedStyle = isIE(10) && getComputedStyle(html);
Mark Otto's avatar
dist  
Mark Otto committed
2644

Mark Otto's avatar
dist    
Mark Otto committed
2645
2646
2647
2648
    return {
      height: getSize('Height', body, html, computedStyle),
      width: getSize('Width', body, html, computedStyle)
    };
Mark Otto's avatar
dist  
Mark Otto committed
2649
2650
  }

Mark Otto's avatar
dist    
Mark Otto committed
2651
2652
2653
2654
  var classCallCheck = function (instance, Constructor) {
    if (!(instance instanceof Constructor)) {
      throw new TypeError("Cannot call a class as a function");
    }
Mark Otto's avatar
dist  
Mark Otto committed
2655
2656
  };

Mark Otto's avatar
dist    
Mark Otto committed
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
  var createClass = function () {
    function defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
      }
    }
Mark Otto's avatar
dist  
Mark Otto committed
2667

Mark Otto's avatar
dist    
Mark Otto committed
2668
2669
2670
2671
2672
2673
    return function (Constructor, protoProps, staticProps) {
      if (protoProps) defineProperties(Constructor.prototype, protoProps);
      if (staticProps) defineProperties(Constructor, staticProps);
      return Constructor;
    };
  }();
Mark Otto's avatar
dist  
Mark Otto committed
2674
2675
2676
2677
2678





Mark Otto's avatar
dist    
Mark Otto committed
2679
2680
2681
2682
2683
2684
2685
2686
  var defineProperty = function (obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
Mark Otto's avatar
dist  
Mark Otto committed
2687
    } else {
Mark Otto's avatar
dist    
Mark Otto committed
2688
      obj[key] = value;
Mark Otto's avatar
dist  
Mark Otto committed
2689
2690
    }

Mark Otto's avatar
dist    
Mark Otto committed
2691
2692
    return obj;
  };
Mark Otto's avatar
dist  
Mark Otto committed
2693

Mark Otto's avatar
dist    
Mark Otto committed
2694
2695
2696
  var _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
Mark Otto's avatar
dist  
Mark Otto committed
2697

Mark Otto's avatar
dist    
Mark Otto committed
2698
2699
2700
2701
2702
2703
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
Mark Otto's avatar
dist  
Mark Otto committed
2704

Mark Otto's avatar
dist    
Mark Otto committed
2705
    return target;
Mark Otto's avatar
dist  
Mark Otto committed
2706
2707
  };

Mark Otto's avatar
dist    
Mark Otto committed
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
  /**
   * Given element offsets, generate an output similar to getBoundingClientRect
   * @method
   * @memberof Popper.Utils
   * @argument {Object} offsets
   * @returns {Object} ClientRect like output
   */
  function getClientRect(offsets) {
    return _extends({}, offsets, {
      right: offsets.left + offsets.width,
      bottom: offsets.top + offsets.height
    });
Mark Otto's avatar
dist  
Mark Otto committed
2720
2721
  }

Mark Otto's avatar
dist    
Mark Otto committed
2722
2723
2724
2725
2726
2727
2728
2729
2730
  /**
   * Get bounding client rect of given element
   * @method
   * @memberof Popper.Utils
   * @param {HTMLElement} element
   * @return {Object} client rect
   */
  function getBoundingClientRect(element) {
    var rect = {};
Mark Otto's avatar
dist  
Mark Otto committed
2731

Mark Otto's avatar
dist    
Mark Otto committed
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
    // IE10 10 FIX: Please, don't ask, the element isn't
    // considered in DOM in some circumstances...
    // This isn't reproducible in IE10 compatibility mode of IE11
    try {
      if (isIE(10)) {
        rect = element.getBoundingClientRect();
        var scrollTop = getScroll(element, 'top');
        var scrollLeft = getScroll(element, 'left');
        rect.top += scrollTop;
        rect.left += scrollLeft;
        rect.bottom += scrollTop;
        rect.right += scrollLeft;
      } else {
        rect = element.getBoundingClientRect();
      }
    } catch (e) {}

    var result = {
      left: rect.left,
      top: rect.top,
      width: rect.right - rect.left,
      height: rect.bottom - rect.top
    };
Mark Otto's avatar
dist  
Mark Otto committed
2755

Mark Otto's avatar
dist    
Mark Otto committed
2756
    // subtract scrollbar size from sizes
Mark Otto's avatar
dist    
Mark Otto committed
2757
    var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
Mark Otto's avatar
dist    
Mark Otto committed
2758
2759
    var width = sizes.width || element.clientWidth || result.right - result.left;
    var height = sizes.height || element.clientHeight || result.bottom - result.top;
Mark Otto's avatar
dist  
Mark Otto committed
2760

Mark Otto's avatar
dist    
Mark Otto committed
2761
2762
    var horizScrollbar = element.offsetWidth - width;
    var vertScrollbar = element.offsetHeight - height;
Mark Otto's avatar
dist  
Mark Otto committed
2763

Mark Otto's avatar
dist    
Mark Otto committed
2764
2765
2766
2767
2768
2769
2770
2771
2772
    // if an hypothetical scrollbar is detected, we must be sure it's not a `border`
    // we make this check conditional for performance reasons
    if (horizScrollbar || vertScrollbar) {
      var styles = getStyleComputedProperty(element);
      horizScrollbar -= getBordersSize(styles, 'x');
      vertScrollbar -= getBordersSize(styles, 'y');

      result.width -= horizScrollbar;
      result.height -= vertScrollbar;
Mark Otto's avatar
dist  
Mark Otto committed
2773
    }
Mark Otto's avatar
dist    
Mark Otto committed
2774
2775

    return getClientRect(result);
Mark Otto's avatar
dist  
Mark Otto committed
2776
2777
  }

Mark Otto's avatar
dist    
Mark Otto committed
2778
2779
  function getOffsetRectRelativeToArbitraryNode(children, parent) {
    var fixedPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
Mark Otto's avatar
dist  
Mark Otto committed
2780

Mark Otto's avatar
dist    
Mark Otto committed
2781
2782
2783
2784
2785
    var isIE10 = isIE(10);
    var isHTML = parent.nodeName === 'HTML';
    var childrenRect = getBoundingClientRect(children);
    var parentRect = getBoundingClientRect(parent);
    var scrollParent = getScrollParent(children);
Mark Otto's avatar
dist  
Mark Otto committed
2786

Mark Otto's avatar
dist    
Mark Otto committed
2787
2788
2789
    var styles = getStyleComputedProperty(parent);
    var borderTopWidth = parseFloat(styles.borderTopWidth, 10);
    var borderLeftWidth = parseFloat(styles.borderLeftWidth, 10);
Mark Otto's avatar
dist  
Mark Otto committed
2790

Mark Otto's avatar
dist    
Mark Otto committed
2791
    // In cases where the parent is fixed, we must ignore negative scroll in offset calc
Mark Otto's avatar
dist    
Mark Otto committed
2792
    if (fixedPosition && isHTML) {
Mark Otto's avatar
dist    
Mark Otto committed
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
      parentRect.top = Math.max(parentRect.top, 0);
      parentRect.left = Math.max(parentRect.left, 0);
    }
    var offsets = getClientRect({
      top: childrenRect.top - parentRect.top - borderTopWidth,
      left: childrenRect.left - parentRect.left - borderLeftWidth,
      width: childrenRect.width,
      height: childrenRect.height
    });
    offsets.marginTop = 0;
    offsets.marginLeft = 0;

    // Subtract margins of documentElement in case it's being used as parent
    // we do this only on HTML because it's the only element that behaves
    // differently when margins are applied to it. The margins are included in
    // the box of the documentElement, in the other cases not.
    if (!isIE10 && isHTML) {
      var marginTop = parseFloat(styles.marginTop, 10);
      var marginLeft = parseFloat(styles.marginLeft, 10);

      offsets.top -= borderTopWidth - marginTop;
      offsets.bottom -= borderTopWidth - marginTop;
      offsets.left -= borderLeftWidth - marginLeft;
      offsets.right -= borderLeftWidth - marginLeft;

      // Attach marginTop and marginLeft because in some circumstances we may need them
      offsets.marginTop = marginTop;
      offsets.marginLeft = marginLeft;
    }
Mark Otto's avatar
dist  
Mark Otto committed
2822

Mark Otto's avatar
dist    
Mark Otto committed
2823
2824
2825
    if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
      offsets = includeScroll(offsets, parent);
    }
Mark Otto's avatar
dist  
Mark Otto committed
2826

Mark Otto's avatar
dist    
Mark Otto committed
2827
    return offsets;
Mark Otto's avatar
dist  
Mark Otto committed
2828
2829
  }

Mark Otto's avatar
dist    
Mark Otto committed
2830
2831
  function getViewportOffsetRectRelativeToArtbitraryNode(element) {
    var excludeScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
Mark Otto's avatar
dist  
Mark Otto committed
2832

Mark Otto's avatar
dist    
Mark Otto committed
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
    var html = element.ownerDocument.documentElement;
    var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
    var width = Math.max(html.clientWidth, window.innerWidth || 0);
    var height = Math.max(html.clientHeight, window.innerHeight || 0);

    var scrollTop = !excludeScroll ? getScroll(html) : 0;
    var scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;

    var offset = {
      top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
      left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
      width: width,
      height: height
    };
Mark Otto's avatar
dist  
Mark Otto committed
2847

Mark Otto's avatar
dist    
Mark Otto committed
2848
    return getClientRect(offset);
Mark Otto's avatar
dist  
Mark Otto committed
2849
2850
  }

Mark Otto's avatar
dist    
Mark Otto committed
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
  /**
   * Check if the given element is fixed or is inside a fixed parent
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @argument {Element} customContainer
   * @returns {Boolean} answer to "isFixed?"
   */
  function isFixed(element) {
    var nodeName = element.nodeName;
    if (nodeName === 'BODY' || nodeName === 'HTML') {
      return false;
Mark Otto's avatar
dist  
Mark Otto committed
2863
    }
Mark Otto's avatar
dist    
Mark Otto committed
2864
2865
2866
    if (getStyleComputedProperty(element, 'position') === 'fixed') {
      return true;
    }
Mark Otto's avatar
Mark Otto committed
2867
2868
2869
2870
2871
    var parentNode = getParentNode(element);
    if (!parentNode) {
      return false;
    }
    return isFixed(parentNode);
Mark Otto's avatar
dist    
Mark Otto committed
2872
  }
Mark Otto's avatar
dist  
Mark Otto committed
2873

Mark Otto's avatar
dist    
Mark Otto committed
2874
2875
2876
2877
2878
2879
2880
  /**
   * Finds the first parent of an element that has a transformed property defined
   * @method
   * @memberof Popper.Utils
   * @argument {Element} element
   * @returns {Element} first transformed parent or documentElement
   */
Mark Otto's avatar
dist  
Mark Otto committed
2881

Mark Otto's avatar
dist    
Mark Otto committed
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
  function getFixedPositionOffsetParent(element) {
    // This check is needed to avoid errors in case one of the elements isn't defined for any reason
    if (!element || !element.parentElement || isIE()) {
      return document.documentElement;
    }
    var el = element.parentElement;
    while (el && getStyleComputedProperty(el, 'transform') === 'none') {
      el = el.parentElement;
    }
    return el || document.documentElement;
  }
Mark Otto's avatar
dist  
Mark Otto committed
2893

Mark Otto's avatar
dist    
Mark Otto committed
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
  /**
   * Computed the boundaries limits and return them
   * @method
   * @memberof Popper.Utils
   * @param {HTMLElement} popper
   * @param {HTMLElement} reference
   * @param {number} padding
   * @param {HTMLElement} boundariesElement - Element used to define the boundaries
   * @param {Boolean} fixedPosition - Is in fixed position mode
   * @returns {Object} Coordinates of the boundaries
   */
  function getBoundaries(popper, reference, padding, boundariesElement) {
    var fixedPosition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
Mark Otto's avatar
dist  
Mark Otto committed
2907

Mark Otto's avatar
dist    
Mark Otto committed
2908
    // NOTE: 1 DOM access here
Mark Otto's avatar
dist  
Mark Otto committed
2909

Mark Otto's avatar
dist    
Mark Otto committed
2910
2911
    var boundaries = { top: 0, left: 0 };
    var offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
Mark Otto's avatar
dist  
Mark Otto committed
2912

Mark Otto's avatar
dist    
Mark Otto committed
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
    // Handle viewport case
    if (boundariesElement === 'viewport') {
      boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
    } else {
      // Handle other cases based on DOM element used as boundaries
      var boundariesNode = void 0;
      if (boundariesElement === 'scrollParent') {
        boundariesNode = getScrollParent(getParentNode(reference));
        if (boundariesNode.nodeName === 'BODY') {
          boundariesNode = popper.ownerDocument.documentElement;
        }
      } else if (boundariesElement === 'window') {
        boundariesNode = popper.ownerDocument.documentElement;
      } else {
        boundariesNode = boundariesElement;
      }
Mark Otto's avatar
dist  
Mark Otto committed
2929

Mark Otto's avatar
dist    
Mark Otto committed
2930
      var offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
Mark Otto's avatar
dist  
Mark Otto committed
2931

Mark Otto's avatar
dist    
Mark Otto committed
2932
2933
      // In case of HTML, we need a different computation
      if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
Mark Otto's avatar
dist    
Mark Otto committed
2934
        var _getWindowSizes = getWindowSizes(popper.ownerDocument),
Mark Otto's avatar
dist    
Mark Otto committed
2935
2936
            height = _getWindowSizes.height,
            width = _getWindowSizes.width;
Mark Otto's avatar
dist  
Mark Otto committed
2937

Mark Otto's avatar
dist    
Mark Otto committed
2938
2939
2940
2941
2942
2943
2944
        boundaries.top += offsets.top - offsets.marginTop;
        boundaries.bottom = height + offsets.top;
        boundaries.left += offsets.left - offsets.marginLeft;
        boundaries.right = width + offsets.left;
      } else {
        // for all the other DOM elements, this one is good
        boundaries = offsets;
Mark Otto's avatar
dist  
Mark Otto committed
2945
      }
Mark Otto's avatar
dist    
Mark Otto committed
2946
    }
Mark Otto's avatar
dist  
Mark Otto committed
2947

Mark Otto's avatar
dist    
Mark Otto committed
2948
    // Add paddings
Mark Otto's avatar
dist    
Mark Otto committed
2949
2950
2951
2952
2953
2954
    padding = padding || 0;
    var isPaddingNumber = typeof padding === 'number';
    boundaries.left += isPaddingNumber ? padding : padding.left || 0;
    boundaries.top += isPaddingNumber ? padding : padding.top || 0;
    boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
    boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
Mark Otto's avatar
dist  
Mark Otto committed
2955

Mark Otto's avatar
dist    
Mark Otto committed
2956
    return boundaries;
Mark Otto's avatar
dist  
Mark Otto committed
2957
2958
  }

Mark Otto's avatar
dist    
Mark Otto committed
2959
2960
2961
2962
2963
  function getArea(_ref) {
    var width = _ref.width,
        height = _ref.height;

    return width * height;
Mark Otto's avatar
dist  
Mark Otto committed
2964
2965
  }

Mark Otto's avatar
dist    
Mark Otto committed
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
  /**
   * Utility used to transform the `auto` placement to the placement with more
   * available space.
   * @method
   * @memberof Popper.Utils
   * @argument {Object} data - The data object generated by update method
   * @argument {Object} options - Modifiers configuration and options
   * @returns {Object} The data object, properly modified
   */
  function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) {
    var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
Mark Otto's avatar
dist  
Mark Otto committed
2977

Mark Otto's avatar
dist    
Mark Otto committed
2978
2979
    if (placement.indexOf('auto') === -1) {
      return placement;
Mark Otto's avatar
dist  
Mark Otto committed
2980
2981
    }

Mark Otto's avatar
dist    
Mark Otto committed
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
    var boundaries = getBoundaries(popper, reference, padding, boundariesElement);

    var rects = {
      top: {
        width: boundaries.width,
        height: refRect.top - boundaries.top
      },
      right: {
        width: boundaries.right - refRect.right,
        height: boundaries.height
      },
      bottom: {
        width: boundaries.width,
        height: boundaries.bottom - refRect.bottom
      },
      left: {
        width: refRect.left - boundaries.left,
        height: boundaries.height
Mark Otto's avatar
dist  
Mark Otto committed
3000
      }
For faster browsing, not all history is shown. View entire blame