bootstrap.js 149 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
2001
2002
2003
  onDOMContentLoaded(function () {
    var $ = getjQuery();
    /* istanbul ignore if */
2004

XhmikosR's avatar
XhmikosR committed
2005
2006
2007
2008
    if ($) {
      var JQUERY_NO_CONFLICT = $.fn[NAME$3];
      $.fn[NAME$3] = Collapse.jQueryInterface;
      $.fn[NAME$3].Constructor = Collapse;
Jacob Thornton's avatar
Jacob Thornton committed
2009

XhmikosR's avatar
XhmikosR committed
2010
2011
2012
2013
2014
2015
      $.fn[NAME$3].noConflict = function () {
        $.fn[NAME$3] = JQUERY_NO_CONFLICT;
        return Collapse.jQueryInterface;
      };
    }
  });
Jacob Thornton's avatar
Jacob Thornton committed
2016

XhmikosR's avatar
Dist    
XhmikosR committed
2017
2018
2019
2020
2021
2022
2023
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME$4 = 'dropdown';
XhmikosR's avatar
XhmikosR committed
2024
  var VERSION$4 = '5.0.0-alpha3';
XhmikosR's avatar
Dist    
XhmikosR committed
2025
2026
2027
  var DATA_KEY$4 = 'bs.dropdown';
  var EVENT_KEY$4 = "." + DATA_KEY$4;
  var DATA_API_KEY$4 = '.data-api';
XhmikosR's avatar
XhmikosR committed
2028
2029
2030
2031
2032
2033
2034
2035
  var ESCAPE_KEY = 'Escape';
  var SPACE_KEY = 'Space';
  var TAB_KEY = 'Tab';
  var ARROW_UP_KEY = 'ArrowUp';
  var ARROW_DOWN_KEY = 'ArrowDown';
  var RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button

  var REGEXP_KEYDOWN = new RegExp(ARROW_UP_KEY + "|" + ARROW_DOWN_KEY + "|" + ESCAPE_KEY);
XhmikosR's avatar
XhmikosR committed
2036
2037
2038
2039
2040
2041
2042
2043
  var EVENT_HIDE$1 = "hide" + EVENT_KEY$4;
  var EVENT_HIDDEN$1 = "hidden" + EVENT_KEY$4;
  var EVENT_SHOW$1 = "show" + EVENT_KEY$4;
  var EVENT_SHOWN$1 = "shown" + EVENT_KEY$4;
  var EVENT_CLICK = "click" + EVENT_KEY$4;
  var EVENT_CLICK_DATA_API$4 = "click" + EVENT_KEY$4 + DATA_API_KEY$4;
  var EVENT_KEYDOWN_DATA_API = "keydown" + EVENT_KEY$4 + DATA_API_KEY$4;
  var EVENT_KEYUP_DATA_API = "keyup" + EVENT_KEY$4 + DATA_API_KEY$4;
XhmikosR's avatar
XhmikosR committed
2044
  var CLASS_NAME_DISABLED = 'disabled';
XhmikosR's avatar
XhmikosR committed
2045
2046
2047
2048
2049
2050
2051
  var CLASS_NAME_SHOW$1 = 'show';
  var CLASS_NAME_DROPUP = 'dropup';
  var CLASS_NAME_DROPRIGHT = 'dropright';
  var CLASS_NAME_DROPLEFT = 'dropleft';
  var CLASS_NAME_MENURIGHT = 'dropdown-menu-right';
  var CLASS_NAME_NAVBAR = 'navbar';
  var CLASS_NAME_POSITION_STATIC = 'position-static';
XhmikosR's avatar
XhmikosR committed
2052
  var SELECTOR_DATA_TOGGLE$2 = '[data-bs-toggle="dropdown"]';
XhmikosR's avatar
XhmikosR committed
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
  var SELECTOR_FORM_CHILD = '.dropdown form';
  var SELECTOR_MENU = '.dropdown-menu';
  var SELECTOR_NAVBAR_NAV = '.navbar-nav';
  var SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)';
  var PLACEMENT_TOP = 'top-start';
  var PLACEMENT_TOPEND = 'top-end';
  var PLACEMENT_BOTTOM = 'bottom-start';
  var PLACEMENT_BOTTOMEND = 'bottom-end';
  var PLACEMENT_RIGHT = 'right-start';
  var PLACEMENT_LEFT = 'left-start';
XhmikosR's avatar
Dist    
XhmikosR committed
2063
2064
2065
2066
2067
  var Default$2 = {
    offset: 0,
    flip: true,
    boundary: 'scrollParent',
    reference: 'toggle',
XhmikosR's avatar
XhmikosR committed
2068
2069
    display: 'dynamic',
    popperConfig: null
XhmikosR's avatar
Dist    
XhmikosR committed
2070
2071
2072
2073
2074
2075
  };
  var DefaultType$2 = {
    offset: '(number|string|function)',
    flip: 'boolean',
    boundary: '(string|element)',
    reference: '(string|element)',
XhmikosR's avatar
XhmikosR committed
2076
2077
    display: 'string',
    popperConfig: '(null|object)'
XhmikosR's avatar
Dist    
XhmikosR committed
2078
  };
XhmikosR's avatar
XhmikosR committed
2079
2080
2081
2082
2083
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
Mark Otto's avatar
dist    
Mark Otto committed
2084

XhmikosR's avatar
XhmikosR committed
2085
  var Dropdown = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
2086
2087
2088
2089
2090
2091
    function Dropdown(element, config) {
      this._element = element;
      this._popper = null;
      this._config = this._getConfig(config);
      this._menu = this._getMenuElement();
      this._inNavbar = this._detectNavbar();
Mark Otto's avatar
dist    
Mark Otto committed
2092

XhmikosR's avatar
Dist    
XhmikosR committed
2093
      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
2094
2095

      Data.setData(element, DATA_KEY$4, this);
XhmikosR's avatar
Dist    
XhmikosR committed
2096
    } // Getters
Mark Otto's avatar
dist    
Mark Otto committed
2097

Jacob Thornton's avatar
Jacob Thornton committed
2098

XhmikosR's avatar
Dist    
XhmikosR committed
2099
    var _proto = Dropdown.prototype;
Jacob Thornton's avatar
Jacob Thornton committed
2100

XhmikosR's avatar
Dist    
XhmikosR committed
2101
2102
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
2103
      if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2104
2105
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2106

XhmikosR's avatar
XhmikosR committed
2107
      var isActive = this._element.classList.contains(CLASS_NAME_SHOW$1);
Jacob Thornton's avatar
Jacob Thornton committed
2108

XhmikosR's avatar
XhmikosR committed
2109
      Dropdown.clearMenus();
Jacob Thornton's avatar
Jacob Thornton committed
2110

XhmikosR's avatar
Dist    
XhmikosR committed
2111
2112
2113
      if (isActive) {
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2114

XhmikosR's avatar
XhmikosR committed
2115
2116
2117
2118
      this.show();
    };

    _proto.show = function show() {
XhmikosR's avatar
XhmikosR committed
2119
      if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED) || this._menu.classList.contains(CLASS_NAME_SHOW$1)) {
XhmikosR's avatar
XhmikosR committed
2120
2121
2122
2123
        return;
      }

      var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
2124
2125
2126
      var relatedTarget = {
        relatedTarget: this._element
      };
XhmikosR's avatar
XhmikosR committed
2127
      var showEvent = EventHandler.trigger(this._element, EVENT_SHOW$1, relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
2128

XhmikosR's avatar
XhmikosR committed
2129
      if (showEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2130
        return;
XhmikosR's avatar
XhmikosR committed
2131
      } // Totally disable Popper for Dropdowns in Navbar
Jacob Thornton's avatar
Jacob Thornton committed
2132
2133


XhmikosR's avatar
Dist    
XhmikosR committed
2134
      if (!this._inNavbar) {
XhmikosR's avatar
XhmikosR committed
2135
        if (typeof Popper__default['default'] === 'undefined') {
XhmikosR's avatar
XhmikosR committed
2136
          throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)');
Mark Otto's avatar
dist    
Mark Otto committed
2137
        }
Jacob Thornton's avatar
Jacob Thornton committed
2138

XhmikosR's avatar
Dist    
XhmikosR committed
2139
        var referenceElement = this._element;
Mark Otto's avatar
dist    
Mark Otto committed
2140

XhmikosR's avatar
Dist    
XhmikosR committed
2141
2142
        if (this._config.reference === 'parent') {
          referenceElement = parent;
XhmikosR's avatar
XhmikosR committed
2143
        } else if (isElement(this._config.reference)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2144
          referenceElement = this._config.reference; // Check if it's jQuery element
Mark Otto's avatar
dist    
Mark Otto committed
2145

XhmikosR's avatar
Dist    
XhmikosR committed
2146
2147
          if (typeof this._config.reference.jquery !== 'undefined') {
            referenceElement = this._config.reference[0];
Mark Otto's avatar
dist    
Mark Otto committed
2148
          }
XhmikosR's avatar
Dist    
XhmikosR committed
2149
2150
2151
        } // If boundary is not `scrollParent`, then set position to `static`
        // to allow the menu to "escape" the scroll parent's boundaries
        // https://github.com/twbs/bootstrap/issues/24251
Jacob Thornton's avatar
Jacob Thornton committed
2152

Mark Otto's avatar
dist    
Mark Otto committed
2153

XhmikosR's avatar
Dist    
XhmikosR committed
2154
        if (this._config.boundary !== 'scrollParent') {
XhmikosR's avatar
XhmikosR committed
2155
          parent.classList.add(CLASS_NAME_POSITION_STATIC);
XhmikosR's avatar
Dist    
XhmikosR committed
2156
        }
Mark Otto's avatar
dist    
Mark Otto committed
2157

XhmikosR's avatar
XhmikosR committed
2158
        this._popper = new Popper__default['default'](referenceElement, this._menu, this._getPopperConfig());
XhmikosR's avatar
Dist    
XhmikosR committed
2159
2160
2161
2162
      } // If this is a touch-enabled device we add extra
      // empty mouseover listeners to the body's immediate children;
      // only needed because of broken event delegation on iOS
      // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
Mark Otto's avatar
dist    
Mark Otto committed
2163

Johann-S's avatar
build    
Johann-S committed
2164

XhmikosR's avatar
XhmikosR committed
2165
      if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
XhmikosR's avatar
XhmikosR committed
2166
2167
2168
        var _ref;

        (_ref = []).concat.apply(_ref, document.body.children).forEach(function (elem) {
XhmikosR's avatar
XhmikosR committed
2169
2170
          return EventHandler.on(elem, 'mouseover', null, noop());
        });
XhmikosR's avatar
Dist    
XhmikosR committed
2171
      }
Mark Otto's avatar
dist    
Mark Otto committed
2172

XhmikosR's avatar
Dist    
XhmikosR committed
2173
      this._element.focus();
Mark Otto's avatar
dist    
Mark Otto committed
2174

XhmikosR's avatar
Dist    
XhmikosR committed
2175
      this._element.setAttribute('aria-expanded', true);
Mark Otto's avatar
grunt    
Mark Otto committed
2176

Mark Otto's avatar
Mark Otto committed
2177
2178
2179
2180
      this._menu.classList.toggle(CLASS_NAME_SHOW$1);

      this._element.classList.toggle(CLASS_NAME_SHOW$1);

XhmikosR's avatar
XhmikosR committed
2181
      EventHandler.trigger(parent, EVENT_SHOWN$1, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
2182
    };
Mark Otto's avatar
dist    
Mark Otto committed
2183

XhmikosR's avatar
Dist    
XhmikosR committed
2184
    _proto.hide = function hide() {
XhmikosR's avatar
XhmikosR committed
2185
      if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED) || !this._menu.classList.contains(CLASS_NAME_SHOW$1)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2186
2187
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2188

XhmikosR's avatar
XhmikosR committed
2189
      var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
2190
2191
2192
      var relatedTarget = {
        relatedTarget: this._element
      };
XhmikosR's avatar
XhmikosR committed
2193
      var hideEvent = EventHandler.trigger(parent, EVENT_HIDE$1, relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
2194

XhmikosR's avatar
XhmikosR committed
2195
      if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2196
2197
        return;
      }
Johann-S's avatar
build    
Johann-S committed
2198

XhmikosR's avatar
XhmikosR committed
2199
2200
2201
2202
      if (this._popper) {
        this._popper.destroy();
      }

Mark Otto's avatar
Mark Otto committed
2203
2204
2205
2206
      this._menu.classList.toggle(CLASS_NAME_SHOW$1);

      this._element.classList.toggle(CLASS_NAME_SHOW$1);

XhmikosR's avatar
XhmikosR committed
2207
      EventHandler.trigger(parent, EVENT_HIDDEN$1, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
2208
    };
Johann-S's avatar
build    
Johann-S committed
2209

XhmikosR's avatar
Dist    
XhmikosR committed
2210
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
2211
2212
      Data.removeData(this._element, DATA_KEY$4);
      EventHandler.off(this._element, EVENT_KEY$4);
XhmikosR's avatar
Dist    
XhmikosR committed
2213
2214
      this._element = null;
      this._menu = null;
Mark Otto's avatar
dist    
Mark Otto committed
2215

XhmikosR's avatar
XhmikosR committed
2216
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
2217
        this._popper.destroy();
Mark Otto's avatar
dist    
Mark Otto committed
2218

XhmikosR's avatar
Dist    
XhmikosR committed
2219
2220
2221
        this._popper = null;
      }
    };
Jacob Thornton's avatar
Jacob Thornton committed
2222

XhmikosR's avatar
Dist    
XhmikosR committed
2223
2224
    _proto.update = function update() {
      this._inNavbar = this._detectNavbar();
Mark Otto's avatar
build    
Mark Otto committed
2225

XhmikosR's avatar
XhmikosR committed
2226
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
2227
2228
        this._popper.scheduleUpdate();
      }
Mark Otto's avatar
Mark Otto committed
2229
2230
    } // Private
    ;
Mark Otto's avatar
dist    
Mark Otto committed
2231

XhmikosR's avatar
Dist    
XhmikosR committed
2232
2233
    _proto._addEventListeners = function _addEventListeners() {
      var _this = this;
Mark Otto's avatar
build    
Mark Otto committed
2234

XhmikosR's avatar
XhmikosR committed
2235
      EventHandler.on(this._element, EVENT_CLICK, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2236
2237
        event.preventDefault();
        event.stopPropagation();
Mark Otto's avatar
build    
Mark Otto committed
2238

XhmikosR's avatar
Dist    
XhmikosR committed
2239
2240
2241
        _this.toggle();
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
2242

XhmikosR's avatar
Dist    
XhmikosR committed
2243
    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
2244
      config = _extends({}, this.constructor.Default, Manipulator.getDataAttributes(this._element), config);
XhmikosR's avatar
XhmikosR committed
2245
      typeCheckConfig(NAME$4, config, this.constructor.DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
2246
2247
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
2248

XhmikosR's avatar
Dist    
XhmikosR committed
2249
    _proto._getMenuElement = function _getMenuElement() {
XhmikosR's avatar
XhmikosR committed
2250
      return SelectorEngine.next(this._element, SELECTOR_MENU)[0];
XhmikosR's avatar
Dist    
XhmikosR committed
2251
    };
Mark Otto's avatar
dist    
Mark Otto committed
2252

XhmikosR's avatar
Dist    
XhmikosR committed
2253
    _proto._getPlacement = function _getPlacement() {
XhmikosR's avatar
XhmikosR committed
2254
      var parentDropdown = this._element.parentNode;
XhmikosR's avatar
XhmikosR committed
2255
      var placement = PLACEMENT_BOTTOM; // Handle dropup
Mark Otto's avatar
dist    
Mark Otto committed
2256

XhmikosR's avatar
XhmikosR committed
2257
      if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
XhmikosR's avatar
XhmikosR committed
2258
        placement = this._menu.classList.contains(CLASS_NAME_MENURIGHT) ? PLACEMENT_TOPEND : PLACEMENT_TOP;
XhmikosR's avatar
XhmikosR committed
2259
2260
2261
2262
2263
2264
      } else if (parentDropdown.classList.contains(CLASS_NAME_DROPRIGHT)) {
        placement = PLACEMENT_RIGHT;
      } else if (parentDropdown.classList.contains(CLASS_NAME_DROPLEFT)) {
        placement = PLACEMENT_LEFT;
      } else if (this._menu.classList.contains(CLASS_NAME_MENURIGHT)) {
        placement = PLACEMENT_BOTTOMEND;
XhmikosR's avatar
Dist    
XhmikosR committed
2265
      }
Jacob Thornton's avatar
Jacob Thornton committed
2266

XhmikosR's avatar
Dist    
XhmikosR committed
2267
2268
      return placement;
    };
Mark Otto's avatar
dist    
Mark Otto committed
2269

XhmikosR's avatar
Dist    
XhmikosR committed
2270
    _proto._detectNavbar = function _detectNavbar() {
XhmikosR's avatar
XhmikosR committed
2271
      return Boolean(this._element.closest("." + CLASS_NAME_NAVBAR));
XhmikosR's avatar
Dist    
XhmikosR committed
2272
    };
Jacob Thornton's avatar
Jacob Thornton committed
2273

Mark Otto's avatar
Mark Otto committed
2274
    _proto._getOffset = function _getOffset() {
XhmikosR's avatar
Dist    
XhmikosR committed
2275
      var _this2 = this;
Mark Otto's avatar
dist    
Mark Otto committed
2276

Mark Otto's avatar
Mark Otto committed
2277
      var offset = {};
Jacob Thornton's avatar
Jacob Thornton committed
2278

XhmikosR's avatar
Dist    
XhmikosR committed
2279
      if (typeof this._config.offset === 'function') {
Mark Otto's avatar
Mark Otto committed
2280
        offset.fn = function (data) {
XhmikosR's avatar
XhmikosR committed
2281
          data.offsets = _extends({}, data.offsets, _this2._config.offset(data.offsets, _this2._element) || {});
XhmikosR's avatar
Dist    
XhmikosR committed
2282
2283
2284
          return data;
        };
      } else {
Mark Otto's avatar
Mark Otto committed
2285
        offset.offset = this._config.offset;
XhmikosR's avatar
Dist    
XhmikosR committed
2286
      }
Mark Otto's avatar
dist    
Mark Otto committed
2287

Mark Otto's avatar
Mark Otto committed
2288
2289
2290
2291
      return offset;
    };

    _proto._getPopperConfig = function _getPopperConfig() {
XhmikosR's avatar
Dist    
XhmikosR committed
2292
2293
2294
      var popperConfig = {
        placement: this._getPlacement(),
        modifiers: {
Mark Otto's avatar
Mark Otto committed
2295
          offset: this._getOffset(),
XhmikosR's avatar
Dist    
XhmikosR committed
2296
2297
2298
2299
2300
          flip: {
            enabled: this._config.flip
          },
          preventOverflow: {
            boundariesElement: this._config.boundary
Mark Otto's avatar
grunt    
Mark Otto committed
2301
          }
XhmikosR's avatar
XhmikosR committed
2302
        }
XhmikosR's avatar
XhmikosR committed
2303
      }; // Disable Popper if we have a static display
Jacob Thornton's avatar
Jacob Thornton committed
2304

XhmikosR's avatar
Dist    
XhmikosR committed
2305
2306
2307
2308
2309
      if (this._config.display === 'static') {
        popperConfig.modifiers.applyStyle = {
          enabled: false
        };
      }
Jacob Thornton's avatar
Jacob Thornton committed
2310

XhmikosR's avatar
XhmikosR committed
2311
      return _extends({}, popperConfig, this._config.popperConfig);
Mark Otto's avatar
Mark Otto committed
2312
2313
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
2314

XhmikosR's avatar
XhmikosR committed
2315
    Dropdown.dropdownInterface = function dropdownInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
2316
      var data = Data.getData(element, DATA_KEY$4);
Mark Otto's avatar
dist    
Mark Otto committed
2317

XhmikosR's avatar
XhmikosR committed
2318
      var _config = typeof config === 'object' ? config : null;
Jacob Thornton's avatar
Jacob Thornton committed
2319

XhmikosR's avatar
XhmikosR committed
2320
2321
2322
2323
2324
2325
      if (!data) {
        data = new Dropdown(element, _config);
      }

      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
2326
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
2327
        }
Johann-S's avatar
build    
Johann-S committed
2328

XhmikosR's avatar
XhmikosR committed
2329
2330
2331
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
2332

XhmikosR's avatar
XhmikosR committed
2333
    Dropdown.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
2334
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
2335
        Dropdown.dropdownInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
2336
2337
      });
    };
Jacob Thornton's avatar
Jacob Thornton committed
2338

XhmikosR's avatar
XhmikosR committed
2339
    Dropdown.clearMenus = function clearMenus(event) {
XhmikosR's avatar
XhmikosR committed
2340
      if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2341
2342
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2343

XhmikosR's avatar
XhmikosR committed
2344
      var toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE$2);
Mark Otto's avatar
dist    
Mark Otto committed
2345

XhmikosR's avatar
Dist    
XhmikosR committed
2346
      for (var i = 0, len = toggles.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
2347
        var parent = Dropdown.getParentFromElement(toggles[i]);
XhmikosR's avatar
XhmikosR committed
2348
        var context = Data.getData(toggles[i], DATA_KEY$4);
XhmikosR's avatar
Dist    
XhmikosR committed
2349
2350
2351
        var relatedTarget = {
          relatedTarget: toggles[i]
        };
Mark Otto's avatar
dist    
Mark Otto committed
2352

XhmikosR's avatar
Dist    
XhmikosR committed
2353
2354
        if (event && event.type === 'click') {
          relatedTarget.clickEvent = event;
Mark Otto's avatar
grunt    
Mark Otto committed
2355
2356
        }

XhmikosR's avatar
Dist    
XhmikosR committed
2357
2358
        if (!context) {
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
2359
        }
Jacob Thornton's avatar
Jacob Thornton committed
2360

XhmikosR's avatar
Dist    
XhmikosR committed
2361
        var dropdownMenu = context._menu;
Jacob Thornton's avatar
Jacob Thornton committed
2362

XhmikosR's avatar
XhmikosR committed
2363
        if (!toggles[i].classList.contains(CLASS_NAME_SHOW$1)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2364
2365
          continue;
        }
Mark Otto's avatar
dist    
Mark Otto committed
2366

XhmikosR's avatar
XhmikosR committed
2367
        if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.key === TAB_KEY) && dropdownMenu.contains(event.target)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2368
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
2369
        }
Jacob Thornton's avatar
Jacob Thornton committed
2370

XhmikosR's avatar
XhmikosR committed
2371
        var hideEvent = EventHandler.trigger(parent, EVENT_HIDE$1, relatedTarget);
Jacob Thornton's avatar
Jacob Thornton committed
2372

XhmikosR's avatar
XhmikosR committed
2373
        if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2374
2375
2376
2377
2378
2379
          continue;
        } // If this is a touch-enabled device we remove the extra
        // empty mouseover listeners we added for iOS support


        if ('ontouchstart' in document.documentElement) {
XhmikosR's avatar
XhmikosR committed
2380
2381
2382
          var _ref2;

          (_ref2 = []).concat.apply(_ref2, document.body.children).forEach(function (elem) {
XhmikosR's avatar
XhmikosR committed
2383
2384
            return EventHandler.off(elem, 'mouseover', null, noop());
          });
Mark Otto's avatar
dist    
Mark Otto committed
2385
        }
Jacob Thornton's avatar
Jacob Thornton committed
2386

XhmikosR's avatar
Dist    
XhmikosR committed
2387
        toggles[i].setAttribute('aria-expanded', 'false');
XhmikosR's avatar
XhmikosR committed
2388
2389
2390
2391
2392

        if (context._popper) {
          context._popper.destroy();
        }

XhmikosR's avatar
XhmikosR committed
2393
2394
2395
        dropdownMenu.classList.remove(CLASS_NAME_SHOW$1);
        toggles[i].classList.remove(CLASS_NAME_SHOW$1);
        EventHandler.trigger(parent, EVENT_HIDDEN$1, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
2396
2397
      }
    };
Jacob Thornton's avatar
Jacob Thornton committed
2398

XhmikosR's avatar
XhmikosR committed
2399
2400
    Dropdown.getParentFromElement = function getParentFromElement(element) {
      return getElementFromSelector(element) || element.parentNode;
XhmikosR's avatar
XhmikosR committed
2401
    };
Jacob Thornton's avatar
Jacob Thornton committed
2402

XhmikosR's avatar
XhmikosR committed
2403
    Dropdown.dataApiKeydownHandler = function dataApiKeydownHandler(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2404
2405
2406
2407
2408
2409
2410
      // If not input/textarea:
      //  - And not a key in REGEXP_KEYDOWN => not a dropdown command
      // If input/textarea:
      //  - If space key => not a dropdown command
      //  - If key is other than escape
      //    - If key is not up or down => not a dropdown command
      //    - If trigger inside the menu => not a dropdown command
XhmikosR's avatar
XhmikosR committed
2411
      if (/input|textarea/i.test(event.target.tagName) ? event.key === SPACE_KEY || event.key !== ESCAPE_KEY && (event.key !== ARROW_DOWN_KEY && event.key !== ARROW_UP_KEY || event.target.closest(SELECTOR_MENU)) : !REGEXP_KEYDOWN.test(event.key)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2412
2413
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2414

XhmikosR's avatar
Dist    
XhmikosR committed
2415
2416
      event.preventDefault();
      event.stopPropagation();
Jacob Thornton's avatar
Jacob Thornton committed
2417

XhmikosR's avatar
XhmikosR committed
2418
      if (this.disabled || this.classList.contains(CLASS_NAME_DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2419
2420
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2421

XhmikosR's avatar
XhmikosR committed
2422
      var parent = Dropdown.getParentFromElement(this);
XhmikosR's avatar
XhmikosR committed
2423
      var isActive = this.classList.contains(CLASS_NAME_SHOW$1);
Jacob Thornton's avatar
Jacob Thornton committed
2424

XhmikosR's avatar
XhmikosR committed
2425
      if (event.key === ESCAPE_KEY) {
XhmikosR's avatar
XhmikosR committed
2426
2427
2428
2429
2430
        var button = this.matches(SELECTOR_DATA_TOGGLE$2) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$2)[0];
        button.focus();
        Dropdown.clearMenus();
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
2431

XhmikosR's avatar
XhmikosR committed
2432
      if (!isActive || event.key === SPACE_KEY) {
XhmikosR's avatar
XhmikosR committed
2433
        Dropdown.clearMenus();
XhmikosR's avatar
Dist    
XhmikosR committed
2434
2435
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
2436

XhmikosR's avatar
XhmikosR committed
2437
      var items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent).filter(isVisible);
Jacob Thornton's avatar
Jacob Thornton committed
2438

XhmikosR's avatar
XhmikosR committed
2439
      if (!items.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
2440
2441
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
2442

XhmikosR's avatar
XhmikosR committed
2443
      var index = items.indexOf(event.target);
Mark Otto's avatar
dist    
Mark Otto committed
2444

XhmikosR's avatar
XhmikosR committed
2445
      if (event.key === ARROW_UP_KEY && index > 0) {
XhmikosR's avatar
Dist    
XhmikosR committed
2446
2447
2448
        // Up
        index--;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2449

XhmikosR's avatar
XhmikosR committed
2450
      if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
XhmikosR's avatar
Dist    
XhmikosR committed
2451
2452
        // Down
        index++;
XhmikosR's avatar
XhmikosR committed
2453
2454
      } // index is -1 if the first keydown is an ArrowUp

Mark Otto's avatar
dist    
Mark Otto committed
2455

XhmikosR's avatar
XhmikosR committed
2456
      index = index === -1 ? 0 : index;
XhmikosR's avatar
Dist    
XhmikosR committed
2457
      items[index].focus();
Mark Otto's avatar
dist    
Mark Otto committed
2458
    };
Jacob Thornton's avatar
Jacob Thornton committed
2459

XhmikosR's avatar
XhmikosR committed
2460
    Dropdown.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
2461
2462
2463
      return Data.getData(element, DATA_KEY$4);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
    _createClass(Dropdown, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION$4;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default$2;
      }
    }, {
      key: "DefaultType",
      get: function get() {
        return DefaultType$2;
      }
    }]);

Mark Otto's avatar
dist    
Mark Otto committed
2481
    return Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
2482
2483
2484
2485
2486
2487
2488
2489
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
2490
2491
2492
2493
2494
  EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE$2, Dropdown.dataApiKeydownHandler);
  EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, Dropdown.clearMenus);
  EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_DATA_TOGGLE$2, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2495
2496
    event.preventDefault();
    event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
2497
    Dropdown.dropdownInterface(this, 'toggle');
XhmikosR's avatar
XhmikosR committed
2498
  });
XhmikosR's avatar
XhmikosR committed
2499
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_FORM_CHILD, function (e) {
XhmikosR's avatar
XhmikosR committed
2500
    return e.stopPropagation();
XhmikosR's avatar
Dist    
XhmikosR committed
2501
2502
2503
2504
2505
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
2506
   * add .Dropdown to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
2507
2508
   */

XhmikosR's avatar
XhmikosR committed
2509
2510
2511
  onDOMContentLoaded(function () {
    var $ = getjQuery();
    /* istanbul ignore if */
2512

XhmikosR's avatar
XhmikosR committed
2513
2514
2515
2516
    if ($) {
      var JQUERY_NO_CONFLICT = $.fn[NAME$4];
      $.fn[NAME$4] = Dropdown.jQueryInterface;
      $.fn[NAME$4].Constructor = Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
2517

XhmikosR's avatar
XhmikosR committed
2518
2519
2520
2521
2522
2523
      $.fn[NAME$4].noConflict = function () {
        $.fn[NAME$4] = JQUERY_NO_CONFLICT;
        return Dropdown.jQueryInterface;
      };
    }
  });
Jacob Thornton's avatar
Jacob Thornton committed
2524

XhmikosR's avatar
Dist    
XhmikosR committed
2525
2526
2527
2528
2529
2530
2531
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME$5 = 'modal';
XhmikosR's avatar
XhmikosR committed
2532
  var VERSION$5 = '5.0.0-alpha3';
XhmikosR's avatar
Dist    
XhmikosR committed
2533
2534
2535
  var DATA_KEY$5 = 'bs.modal';
  var EVENT_KEY$5 = "." + DATA_KEY$5;
  var DATA_API_KEY$5 = '.data-api';
XhmikosR's avatar
XhmikosR committed
2536
  var ESCAPE_KEY$1 = 'Escape';
XhmikosR's avatar
Dist    
XhmikosR committed
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
  var Default$3 = {
    backdrop: true,
    keyboard: true,
    focus: true,
    show: true
  };
  var DefaultType$3 = {
    backdrop: '(boolean|string)',
    keyboard: 'boolean',
    focus: 'boolean',
    show: 'boolean'
  };
XhmikosR's avatar
XhmikosR committed
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
  var EVENT_HIDE$2 = "hide" + EVENT_KEY$5;
  var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY$5;
  var EVENT_HIDDEN$2 = "hidden" + EVENT_KEY$5;
  var EVENT_SHOW$2 = "show" + EVENT_KEY$5;
  var EVENT_SHOWN$2 = "shown" + EVENT_KEY$5;
  var EVENT_FOCUSIN = "focusin" + EVENT_KEY$5;
  var EVENT_RESIZE = "resize" + EVENT_KEY$5;
  var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY$5;
  var EVENT_KEYDOWN_DISMISS = "keydown.dismiss" + EVENT_KEY$5;
  var EVENT_MOUSEUP_DISMISS = "mouseup.dismiss" + EVENT_KEY$5;
  var EVENT_MOUSEDOWN_DISMISS = "mousedown.dismiss" + EVENT_KEY$5;
  var EVENT_CLICK_DATA_API$5 = "click" + EVENT_KEY$5 + DATA_API_KEY$5;
  var CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure';
  var CLASS_NAME_BACKDROP = 'modal-backdrop';
  var CLASS_NAME_OPEN = 'modal-open';
  var CLASS_NAME_FADE = 'fade';
  var CLASS_NAME_SHOW$2 = 'show';
  var CLASS_NAME_STATIC = 'modal-static';
  var SELECTOR_DIALOG = '.modal-dialog';
  var SELECTOR_MODAL_BODY = '.modal-body';
XhmikosR's avatar
XhmikosR committed
2569
2570
  var SELECTOR_DATA_TOGGLE$3 = '[data-bs-toggle="modal"]';
  var SELECTOR_DATA_DISMISS = '[data-bs-dismiss="modal"]';
XhmikosR's avatar
XhmikosR committed
2571
2572
  var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
  var SELECTOR_STICKY_CONTENT = '.sticky-top';
XhmikosR's avatar
XhmikosR committed
2573
2574
2575
2576
2577
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
2578

XhmikosR's avatar
XhmikosR committed
2579
  var Modal = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
2580
2581
2582
    function Modal(element, config) {
      this._config = this._getConfig(config);
      this._element = element;
XhmikosR's avatar
XhmikosR committed
2583
      this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, element);
XhmikosR's avatar
Dist    
XhmikosR committed
2584
2585
2586
2587
2588
2589
      this._backdrop = null;
      this._isShown = false;
      this._isBodyOverflowing = false;
      this._ignoreBackdropClick = false;
      this._isTransitioning = false;
      this._scrollbarWidth = 0;
XhmikosR's avatar
XhmikosR committed
2590
      Data.setData(element, DATA_KEY$5, this);
XhmikosR's avatar
Dist    
XhmikosR committed
2591
2592
2593
2594
2595
2596
2597
2598
    } // Getters


    var _proto = Modal.prototype;

    // Public
    _proto.toggle = function toggle(relatedTarget) {
      return this._isShown ? this.hide() : this.show(relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
2599
    };
Jacob Thornton's avatar
Jacob Thornton committed
2600

XhmikosR's avatar
Dist    
XhmikosR committed
2601
2602
    _proto.show = function show(relatedTarget) {
      var _this = this;
Mark Otto's avatar
grunt    
Mark Otto committed
2603

XhmikosR's avatar
Dist    
XhmikosR committed
2604
2605
2606
      if (this._isShown || this._isTransitioning) {
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
2607

XhmikosR's avatar
XhmikosR committed
2608
      if (this._element.classList.contains(CLASS_NAME_FADE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2609
2610
        this._isTransitioning = true;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2611

XhmikosR's avatar
XhmikosR committed
2612
      var showEvent = EventHandler.trigger(this._element, EVENT_SHOW$2, {
XhmikosR's avatar
Dist    
XhmikosR committed
2613
2614
        relatedTarget: relatedTarget
      });
Jacob Thornton's avatar
Jacob Thornton committed
2615

XhmikosR's avatar
XhmikosR committed
2616
      if (this._isShown || showEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2617
2618
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2619

XhmikosR's avatar
Dist    
XhmikosR committed
2620
      this._isShown = true;
Mark Otto's avatar
dist    
Mark Otto committed
2621

XhmikosR's avatar
Dist    
XhmikosR committed
2622
      this._checkScrollbar();
Jacob Thornton's avatar
Jacob Thornton committed
2623

XhmikosR's avatar
Dist    
XhmikosR committed
2624
      this._setScrollbar();
Mark Otto's avatar
dist    
Mark Otto committed
2625

XhmikosR's avatar
Dist    
XhmikosR committed
2626
      this._adjustDialog();
Jacob Thornton's avatar
Jacob Thornton committed
2627

XhmikosR's avatar
Dist    
XhmikosR committed
2628
      this._setEscapeEvent();
Jacob Thornton's avatar
Jacob Thornton committed
2629

XhmikosR's avatar
Dist    
XhmikosR committed
2630
      this._setResizeEvent();
Mark Otto's avatar
grunt    
Mark Otto committed
2631

XhmikosR's avatar
XhmikosR committed
2632
      EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2633
2634
        return _this.hide(event);
      });
XhmikosR's avatar
XhmikosR committed
2635
2636
      EventHandler.on(this._dialog, EVENT_MOUSEDOWN_DISMISS, function () {
        EventHandler.one(_this._element, EVENT_MOUSEUP_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2637
          if (event.target === _this._element) {
XhmikosR's avatar
Dist    
XhmikosR committed
2638
2639
            _this._ignoreBackdropClick = true;
          }
Mark Otto's avatar
dist    
Mark Otto committed
2640
        });
XhmikosR's avatar
Dist    
XhmikosR committed
2641
      });
Jacob Thornton's avatar
Jacob Thornton committed
2642

XhmikosR's avatar
Dist    
XhmikosR committed
2643
2644
2645
2646
      this._showBackdrop(function () {
        return _this._showElement(relatedTarget);
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
2647

XhmikosR's avatar
Dist    
XhmikosR committed
2648
2649
    _proto.hide = function hide(event) {
      var _this2 = this;
Jacob Thornton's avatar
Jacob Thornton committed
2650

XhmikosR's avatar
Dist    
XhmikosR committed
2651
2652
2653
      if (event) {
        event.preventDefault();
      }
Jacob Thornton's avatar
Jacob Thornton committed
2654

XhmikosR's avatar
Dist    
XhmikosR committed
2655
2656
2657
      if (!this._isShown || this._isTransitioning) {
        return;
      }
Jacob Thornton's avatar
Jacob Thornton committed
2658

XhmikosR's avatar
XhmikosR committed
2659
      var hideEvent = EventHandler.trigger(this._element, EVENT_HIDE$2);
Jacob Thornton's avatar
Jacob Thornton committed
2660

2661
      if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
2662
2663
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
2664

XhmikosR's avatar
Dist    
XhmikosR committed
2665
      this._isShown = false;
XhmikosR's avatar
XhmikosR committed
2666

XhmikosR's avatar
XhmikosR committed
2667
      var transition = this._element.classList.contains(CLASS_NAME_FADE);
Jacob Thornton's avatar
Jacob Thornton committed
2668

XhmikosR's avatar
Dist    
XhmikosR committed
2669
2670
2671
      if (transition) {
        this._isTransitioning = true;
      }
Mark Otto's avatar
dist    
Mark Otto committed
2672

XhmikosR's avatar
Dist    
XhmikosR committed
2673
      this._setEscapeEvent();
Jacob Thornton's avatar
Jacob Thornton committed
2674

XhmikosR's avatar
Dist    
XhmikosR committed
2675
      this._setResizeEvent();
Jacob Thornton's avatar
Jacob Thornton committed
2676

XhmikosR's avatar
XhmikosR committed
2677
      EventHandler.off(document, EVENT_FOCUSIN);
XhmikosR's avatar
XhmikosR committed
2678

XhmikosR's avatar
XhmikosR committed
2679
      this._element.classList.remove(CLASS_NAME_SHOW$2);
XhmikosR's avatar
XhmikosR committed
2680

XhmikosR's avatar
XhmikosR committed
2681
2682
      EventHandler.off(this._element, EVENT_CLICK_DISMISS);
      EventHandler.off(this._dialog, EVENT_MOUSEDOWN_DISMISS);
Jacob Thornton's avatar
Jacob Thornton committed
2683

XhmikosR's avatar
Dist    
XhmikosR committed
2684
      if (transition) {
XhmikosR's avatar
XhmikosR committed
2685
2686
        var transitionDuration = getTransitionDurationFromElement(this._element);
        EventHandler.one(this._element, TRANSITION_END, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2687
          return _this2._hideModal(event);
XhmikosR's avatar
XhmikosR committed
2688
2689
        });
        emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2690
2691
2692
2693
      } else {
        this._hideModal();
      }
    };
Jacob Thornton's avatar
Jacob Thornton committed
2694

XhmikosR's avatar
Dist    
XhmikosR committed
2695
2696
    _proto.dispose = function dispose() {
      [window, this._element, this._dialog].forEach(function (htmlElement) {
XhmikosR's avatar
XhmikosR committed
2697
        return EventHandler.off(htmlElement, EVENT_KEY$5);
XhmikosR's avatar
Dist    
XhmikosR committed
2698
2699
      });
      /**
XhmikosR's avatar
XhmikosR committed
2700
       * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
XhmikosR's avatar
Dist    
XhmikosR committed
2701
       * Do not move `document` in `htmlElements` array
XhmikosR's avatar
XhmikosR committed
2702
       * It will remove `EVENT_CLICK_DATA_API` event that should remain
XhmikosR's avatar
Dist    
XhmikosR committed
2703
       */
Mark Otto's avatar
grunt    
Mark Otto committed
2704

XhmikosR's avatar
XhmikosR committed
2705
      EventHandler.off(document, EVENT_FOCUSIN);
XhmikosR's avatar
XhmikosR committed
2706
      Data.removeData(this._element, DATA_KEY$5);
XhmikosR's avatar
Dist    
XhmikosR committed
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
      this._config = null;
      this._element = null;
      this._dialog = null;
      this._backdrop = null;
      this._isShown = null;
      this._isBodyOverflowing = null;
      this._ignoreBackdropClick = null;
      this._isTransitioning = null;
      this._scrollbarWidth = null;
    };
Jacob Thornton's avatar
Jacob Thornton committed
2717

XhmikosR's avatar
Dist    
XhmikosR committed
2718
2719
    _proto.handleUpdate = function handleUpdate() {
      this._adjustDialog();
Mark Otto's avatar
Mark Otto committed
2720
2721
    } // Private
    ;
Jacob Thornton's avatar
Jacob Thornton committed
2722

XhmikosR's avatar
Dist    
XhmikosR committed
2723
    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
2724
      config = _extends({}, Default$3, config);
XhmikosR's avatar
XhmikosR committed
2725
      typeCheckConfig(NAME$5, config, DefaultType$3);
XhmikosR's avatar
Dist    
XhmikosR committed
2726
2727
      return config;
    };
Jacob Thornton's avatar
Jacob Thornton committed
2728

XhmikosR's avatar
Dist    
XhmikosR committed
2729
2730
    _proto._showElement = function _showElement(relatedTarget) {
      var _this3 = this;
Jacob Thornton's avatar
Jacob Thornton committed
2731

XhmikosR's avatar
XhmikosR committed
2732
      var transition = this._element.classList.contains(CLASS_NAME_FADE);
Mark Otto's avatar
dist    
Mark Otto committed
2733

XhmikosR's avatar
XhmikosR committed
2734
      var modalBody = SelectorEngine.findOne(SELECTOR_MODAL_BODY, this._dialog);
XhmikosR's avatar
XhmikosR committed
2735

XhmikosR's avatar
Dist    
XhmikosR committed
2736
2737
2738
2739
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
        // Don't move modal's DOM position
        document.body.appendChild(this._element);
      }
Mark Otto's avatar
dist    
Mark Otto committed
2740

XhmikosR's avatar
Dist    
XhmikosR committed
2741
      this._element.style.display = 'block';
Jacob Thornton's avatar
Jacob Thornton committed
2742

XhmikosR's avatar
Dist    
XhmikosR committed
2743
      this._element.removeAttribute('aria-hidden');
Mark Otto's avatar
grunt    
Mark Otto committed
2744

Mark Otto's avatar
dist    
Mark Otto committed
2745
2746
      this._element.setAttribute('aria-modal', true);

Mark Otto's avatar
Mark Otto committed
2747
2748
      this._element.setAttribute('role', 'dialog');

XhmikosR's avatar
XhmikosR committed
2749
2750
2751
      this._element.scrollTop = 0;

      if (modalBody) {
XhmikosR's avatar
XhmikosR committed
2752
        modalBody.scrollTop = 0;
Mark Otto's avatar
Mark Otto committed
2753
      }
Mark Otto's avatar
grunt    
Mark Otto committed
2754

XhmikosR's avatar
Dist    
XhmikosR committed
2755
      if (transition) {
XhmikosR's avatar
XhmikosR committed
2756
        reflow(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
2757
      }
Mark Otto's avatar
grunt    
Mark Otto committed
2758

XhmikosR's avatar
XhmikosR committed
2759
      this._element.classList.add(CLASS_NAME_SHOW$2);
Mark Otto's avatar
dist    
Mark Otto committed
2760

XhmikosR's avatar
Dist    
XhmikosR committed
2761
2762
2763
      if (this._config.focus) {
        this._enforceFocus();
      }
Mark Otto's avatar
dist    
Mark Otto committed
2764

XhmikosR's avatar
Dist    
XhmikosR committed
2765
2766
2767
      var transitionComplete = function transitionComplete() {
        if (_this3._config.focus) {
          _this3._element.focus();
Jacob Thornton's avatar
Jacob Thornton committed
2768
        }
Mark Otto's avatar
dist    
Mark Otto committed
2769

XhmikosR's avatar
Dist    
XhmikosR committed
2770
        _this3._isTransitioning = false;
XhmikosR's avatar
XhmikosR committed
2771
        EventHandler.trigger(_this3._element, EVENT_SHOWN$2, {
XhmikosR's avatar
XhmikosR committed
2772
2773
          relatedTarget: relatedTarget
        });
Mark Otto's avatar
grunt    
Mark Otto committed
2774
2775
      };

XhmikosR's avatar
Dist    
XhmikosR committed
2776
      if (transition) {
XhmikosR's avatar
XhmikosR committed
2777
2778
2779
        var transitionDuration = getTransitionDurationFromElement(this._dialog);
        EventHandler.one(this._dialog, TRANSITION_END, transitionComplete);
        emulateTransitionEnd(this._dialog, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2780
2781
2782
2783
      } else {
        transitionComplete();
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
2784

XhmikosR's avatar
Dist    
XhmikosR committed
2785
2786
    _proto._enforceFocus = function _enforceFocus() {
      var _this4 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
2787

XhmikosR's avatar
XhmikosR committed
2788
      EventHandler.off(document, EVENT_FOCUSIN); // guard against infinite focus loop
XhmikosR's avatar
XhmikosR committed
2789

XhmikosR's avatar
XhmikosR committed
2790
      EventHandler.on(document, EVENT_FOCUSIN, function (event) {
XhmikosR's avatar
XhmikosR committed
2791
        if (document !== event.target && _this4._element !== event.target && !_this4._element.contains(event.target)) {
XhmikosR's avatar
Dist    
XhmikosR committed
2792
          _this4._element.focus();
Mark Otto's avatar
dist    
Mark Otto committed
2793
        }
XhmikosR's avatar
Dist    
XhmikosR committed
2794
2795
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
2796

XhmikosR's avatar
Dist    
XhmikosR committed
2797
2798
    _proto._setEscapeEvent = function _setEscapeEvent() {
      var _this5 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
2799

XhmikosR's avatar
XhmikosR committed
2800
2801
      if (this._isShown) {
        EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2802
          if (_this5._config.keyboard && event.key === ESCAPE_KEY$1) {
XhmikosR's avatar
XhmikosR committed
2803
2804
2805
            event.preventDefault();

            _this5.hide();
XhmikosR's avatar
XhmikosR committed
2806
          } else if (!_this5._config.keyboard && event.key === ESCAPE_KEY$1) {
XhmikosR's avatar
XhmikosR committed
2807
            _this5._triggerBackdropTransition();
XhmikosR's avatar
Dist    
XhmikosR committed
2808
2809
          }
        });
2810
      } else {
XhmikosR's avatar
XhmikosR committed
2811
        EventHandler.off(this._element, EVENT_KEYDOWN_DISMISS);
XhmikosR's avatar
Dist    
XhmikosR committed
2812
2813
      }
    };
Jacob Thornton's avatar
Jacob Thornton committed
2814

XhmikosR's avatar
Dist    
XhmikosR committed
2815
2816
    _proto._setResizeEvent = function _setResizeEvent() {
      var _this6 = this;
Jacob Thornton's avatar
Jacob Thornton committed
2817

XhmikosR's avatar
Dist    
XhmikosR committed
2818
      if (this._isShown) {
XhmikosR's avatar
XhmikosR committed
2819
        EventHandler.on(window, EVENT_RESIZE, function () {
2820
          return _this6._adjustDialog();
XhmikosR's avatar
Dist    
XhmikosR committed
2821
2822
        });
      } else {
XhmikosR's avatar
XhmikosR committed
2823
        EventHandler.off(window, EVENT_RESIZE);
XhmikosR's avatar
Dist    
XhmikosR committed
2824
2825
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
2826

XhmikosR's avatar
Dist    
XhmikosR committed
2827
2828
    _proto._hideModal = function _hideModal() {
      var _this7 = this;
Mark Otto's avatar
dist    
Mark Otto committed
2829

XhmikosR's avatar
Dist    
XhmikosR committed
2830
      this._element.style.display = 'none';
Mark Otto's avatar
dist    
Mark Otto committed
2831

XhmikosR's avatar
Dist    
XhmikosR committed
2832
      this._element.setAttribute('aria-hidden', true);
Mark Otto's avatar
dist    
Mark Otto committed
2833

Mark Otto's avatar
dist    
Mark Otto committed
2834
2835
      this._element.removeAttribute('aria-modal');

Mark Otto's avatar
Mark Otto committed
2836
2837
      this._element.removeAttribute('role');

XhmikosR's avatar
Dist    
XhmikosR committed
2838
      this._isTransitioning = false;
Mark Otto's avatar
dist    
Mark Otto committed
2839

XhmikosR's avatar
Dist    
XhmikosR committed
2840
      this._showBackdrop(function () {
XhmikosR's avatar
XhmikosR committed
2841
        document.body.classList.remove(CLASS_NAME_OPEN);
Mark Otto's avatar
dist    
Mark Otto committed
2842

XhmikosR's avatar
Dist    
XhmikosR committed
2843
        _this7._resetAdjustments();
Mark Otto's avatar
dist    
Mark Otto committed
2844

XhmikosR's avatar
Dist    
XhmikosR committed
2845
        _this7._resetScrollbar();
Jacob Thornton's avatar
Jacob Thornton committed
2846

XhmikosR's avatar
XhmikosR committed
2847
        EventHandler.trigger(_this7._element, EVENT_HIDDEN$2);
XhmikosR's avatar
Dist    
XhmikosR committed
2848
2849
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
2850

XhmikosR's avatar
Dist    
XhmikosR committed
2851
    _proto._removeBackdrop = function _removeBackdrop() {
2852
      this._backdrop.parentNode.removeChild(this._backdrop);
XhmikosR's avatar
XhmikosR committed
2853

2854
      this._backdrop = null;
XhmikosR's avatar
Dist    
XhmikosR committed
2855
    };
Jacob Thornton's avatar
Jacob Thornton committed
2856

XhmikosR's avatar
Dist    
XhmikosR committed
2857
2858
    _proto._showBackdrop = function _showBackdrop(callback) {
      var _this8 = this;
Jacob Thornton's avatar
Jacob Thornton committed
2859

XhmikosR's avatar
XhmikosR committed
2860
      var animate = this._element.classList.contains(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
Jacob Thornton's avatar
Jacob Thornton committed
2861

XhmikosR's avatar
Dist    
XhmikosR committed
2862
2863
      if (this._isShown && this._config.backdrop) {
        this._backdrop = document.createElement('div');
XhmikosR's avatar
XhmikosR committed
2864
        this._backdrop.className = CLASS_NAME_BACKDROP;
Mark Otto's avatar
grunt    
Mark Otto committed
2865

XhmikosR's avatar
Dist    
XhmikosR committed
2866
2867
2868
        if (animate) {
          this._backdrop.classList.add(animate);
        }
Jacob Thornton's avatar
Jacob Thornton committed
2869

XhmikosR's avatar
XhmikosR committed
2870
        document.body.appendChild(this._backdrop);
XhmikosR's avatar
XhmikosR committed
2871
        EventHandler.on(this._element, EVENT_CLICK_DISMISS, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
2872
2873
          if (_this8._ignoreBackdropClick) {
            _this8._ignoreBackdropClick = false;
Jacob Thornton's avatar
Jacob Thornton committed
2874
2875
            return;
          }
Mark Otto's avatar
dist    
Mark Otto committed
2876

XhmikosR's avatar
Dist    
XhmikosR committed
2877
          if (event.target !== event.currentTarget) {
Jacob Thornton's avatar
Jacob Thornton committed
2878
2879
            return;
          }
Mark Otto's avatar
dist    
Mark Otto committed
2880

XhmikosR's avatar
XhmikosR committed
2881
2882
2883
2884
2885
          if (_this8._config.backdrop === 'static') {
            _this8._triggerBackdropTransition();
          } else {
            _this8.hide();
          }
XhmikosR's avatar
Dist    
XhmikosR committed
2886
        });
Jacob Thornton's avatar
Jacob Thornton committed
2887

XhmikosR's avatar
Dist    
XhmikosR committed
2888
        if (animate) {
XhmikosR's avatar
XhmikosR committed
2889
          reflow(this._backdrop);
XhmikosR's avatar
Dist    
XhmikosR committed
2890
        }
Jacob Thornton's avatar
Jacob Thornton committed
2891

XhmikosR's avatar
XhmikosR committed
2892
        this._backdrop.classList.add(CLASS_NAME_SHOW$2);
Jacob Thornton's avatar
Jacob Thornton committed
2893

XhmikosR's avatar
Dist    
XhmikosR committed
2894
        if (!animate) {
Jacob Thornton's avatar
Jacob Thornton committed
2895
          callback();
XhmikosR's avatar
Dist    
XhmikosR committed
2896
          return;
Jacob Thornton's avatar
Jacob Thornton committed
2897
2898
        }

XhmikosR's avatar
XhmikosR committed
2899
2900
2901
        var backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
        EventHandler.one(this._backdrop, TRANSITION_END, callback);
        emulateTransitionEnd(this._backdrop, backdropTransitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2902
      } else if (!this._isShown && this._backdrop) {
XhmikosR's avatar
XhmikosR committed
2903
        this._backdrop.classList.remove(CLASS_NAME_SHOW$2);
Jacob Thornton's avatar
Jacob Thornton committed
2904

XhmikosR's avatar
Dist    
XhmikosR committed
2905
2906
        var callbackRemove = function callbackRemove() {
          _this8._removeBackdrop();
Jacob Thornton's avatar
Jacob Thornton committed
2907

2908
          callback();
XhmikosR's avatar
Dist    
XhmikosR committed
2909
2910
        };

XhmikosR's avatar
XhmikosR committed
2911
        if (this._element.classList.contains(CLASS_NAME_FADE)) {
XhmikosR's avatar
XhmikosR committed
2912
          var _backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
Mark Otto's avatar
grunt    
Mark Otto committed
2913

XhmikosR's avatar
XhmikosR committed
2914
2915
          EventHandler.one(this._backdrop, TRANSITION_END, callbackRemove);
          emulateTransitionEnd(this._backdrop, _backdropTransitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
2916
2917
        } else {
          callbackRemove();
Mark Otto's avatar
dist    
Mark Otto committed
2918
        }
2919
      } else {
XhmikosR's avatar
Dist    
XhmikosR committed
2920
2921
        callback();
      }
XhmikosR's avatar
XhmikosR committed
2922
2923
2924
2925
2926
    };

    _proto._triggerBackdropTransition = function _triggerBackdropTransition() {
      var _this9 = this;

XhmikosR's avatar
XhmikosR committed
2927
      var hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED);
XhmikosR's avatar
XhmikosR committed
2928

XhmikosR's avatar
XhmikosR committed
2929
2930
2931
      if (hideEvent.defaultPrevented) {
        return;
      }
XhmikosR's avatar
XhmikosR committed
2932

XhmikosR's avatar
XhmikosR committed
2933
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
XhmikosR's avatar
XhmikosR committed
2934

XhmikosR's avatar
XhmikosR committed
2935
2936
2937
      if (!isModalOverflowing) {
        this._element.style.overflowY = 'hidden';
      }
XhmikosR's avatar
XhmikosR committed
2938

XhmikosR's avatar
XhmikosR committed
2939
      this._element.classList.add(CLASS_NAME_STATIC);
XhmikosR's avatar
XhmikosR committed
2940

XhmikosR's avatar
XhmikosR committed
2941
2942
2943
2944
      var modalTransitionDuration = getTransitionDurationFromElement(this._dialog);
      EventHandler.off(this._element, TRANSITION_END);
      EventHandler.one(this._element, TRANSITION_END, function () {
        _this9._element.classList.remove(CLASS_NAME_STATIC);
XhmikosR's avatar
XhmikosR committed
2945

XhmikosR's avatar
XhmikosR committed
2946
2947
2948
2949
2950
2951
2952
2953
        if (!isModalOverflowing) {
          EventHandler.one(_this9._element, TRANSITION_END, function () {
            _this9._element.style.overflowY = '';
          });
          emulateTransitionEnd(_this9._element, modalTransitionDuration);
        }
      });
      emulateTransitionEnd(this._element, modalTransitionDuration);
XhmikosR's avatar
XhmikosR committed
2954

XhmikosR's avatar
XhmikosR committed
2955
      this._element.focus();
Mark Otto's avatar
Mark Otto committed
2956
    } // ----------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
2957
2958
    // the following methods are used to handle overflowing modals
    // ----------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
2959
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
2960

XhmikosR's avatar
Dist    
XhmikosR committed
2961
2962
    _proto._adjustDialog = function _adjustDialog() {
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
Mark Otto's avatar
grunt    
Mark Otto committed
2963

XhmikosR's avatar
Dist    
XhmikosR committed
2964
2965
2966
      if (!this._isBodyOverflowing && isModalOverflowing) {
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
      }
Mark Otto's avatar
dist    
Mark Otto committed
2967

XhmikosR's avatar
Dist    
XhmikosR committed
2968
2969
2970
2971
      if (this._isBodyOverflowing && !isModalOverflowing) {
        this._element.style.paddingRight = this._scrollbarWidth + "px";
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
2972

XhmikosR's avatar
Dist    
XhmikosR committed
2973
2974
2975
2976
    _proto._resetAdjustments = function _resetAdjustments() {
      this._element.style.paddingLeft = '';
      this._element.style.paddingRight = '';
    };
Mark Otto's avatar
dist    
Mark Otto committed
2977

XhmikosR's avatar
Dist    
XhmikosR committed
2978
2979
    _proto._checkScrollbar = function _checkScrollbar() {
      var rect = document.body.getBoundingClientRect();
XhmikosR's avatar
XhmikosR committed
2980
      this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
XhmikosR's avatar
Dist    
XhmikosR committed
2981
2982
      this._scrollbarWidth = this._getScrollbarWidth();
    };
Mark Otto's avatar
dist    
Mark Otto committed
2983

XhmikosR's avatar
Dist    
XhmikosR committed
2984
    _proto._setScrollbar = function _setScrollbar() {
XhmikosR's avatar
XhmikosR committed
2985
      var _this10 = this;
XhmikosR's avatar
Dist    
XhmikosR committed
2986
2987
2988
2989

      if (this._isBodyOverflowing) {
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
XhmikosR's avatar
XhmikosR committed
2990
        // Adjust fixed content padding
XhmikosR's avatar
XhmikosR committed
2991
        SelectorEngine.find(SELECTOR_FIXED_CONTENT).forEach(function (element) {
XhmikosR's avatar
Dist    
XhmikosR committed
2992
          var actualPadding = element.style.paddingRight;
XhmikosR's avatar
XhmikosR committed
2993
2994
          var calculatedPadding = window.getComputedStyle(element)['padding-right'];
          Manipulator.setDataAttribute(element, 'padding-right', actualPadding);
XhmikosR's avatar
XhmikosR committed
2995
          element.style.paddingRight = Number.parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px";
XhmikosR's avatar
Dist    
XhmikosR committed
2996
2997
        }); // Adjust sticky content margin

XhmikosR's avatar
XhmikosR committed
2998
        SelectorEngine.find(SELECTOR_STICKY_CONTENT).forEach(function (element) {
XhmikosR's avatar
Dist    
XhmikosR committed
2999
          var actualMargin = element.style.marginRight;
XhmikosR's avatar
XhmikosR committed
3000
          var calculatedMargin = window.getComputedStyle(element)['margin-right'];
For faster browsing, not all history is shown. View entire blame