bootstrap.esm.js 140 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
2001
2002
2003
2004
      return Collapse.jQueryInterface;
    };
  }
});
XhmikosR's avatar
Dist.  
XhmikosR committed
2005
2006
2007
2008
2009
2010
2011

/**
 * ------------------------------------------------------------------------
 * Constants
 * ------------------------------------------------------------------------
 */

XhmikosR's avatar
XhmikosR committed
2012
var NAME$4 = 'dropdown';
XhmikosR's avatar
XhmikosR committed
2013
var VERSION$4 = '5.0.0-alpha3';
XhmikosR's avatar
XhmikosR committed
2014
2015
2016
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
2017
2018
2019
2020
2021
2022
2023
2024
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
2025
2026
2027
2028
2029
2030
2031
2032
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
2033
var CLASS_NAME_DISABLED = 'disabled';
XhmikosR's avatar
XhmikosR committed
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
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';
var SELECTOR_DATA_TOGGLE$2 = '[data-toggle="dropdown"]';
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
XhmikosR committed
2052
var Default$2 = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2053
2054
2055
2056
  offset: 0,
  flip: true,
  boundary: 'scrollParent',
  reference: 'toggle',
XhmikosR's avatar
XhmikosR committed
2057
2058
  display: 'dynamic',
  popperConfig: null
XhmikosR's avatar
Dist.  
XhmikosR committed
2059
};
XhmikosR's avatar
XhmikosR committed
2060
var DefaultType$2 = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2061
2062
2063
2064
  offset: '(number|string|function)',
  flip: 'boolean',
  boundary: '(string|element)',
  reference: '(string|element)',
XhmikosR's avatar
XhmikosR committed
2065
2066
  display: 'string',
  popperConfig: '(null|object)'
XhmikosR's avatar
Dist.  
XhmikosR committed
2067
};
XhmikosR's avatar
XhmikosR committed
2068
2069
2070
2071
2072
/**
 * ------------------------------------------------------------------------
 * Class Definition
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
Dist.  
XhmikosR committed
2073

XhmikosR's avatar
XhmikosR committed
2074
var Dropdown = /*#__PURE__*/function () {
XhmikosR's avatar
XhmikosR committed
2075
  function Dropdown(element, config) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
    this._element = element;
    this._popper = null;
    this._config = this._getConfig(config);
    this._menu = this._getMenuElement();
    this._inNavbar = this._detectNavbar();

    this._addEventListeners();

    Data.setData(element, DATA_KEY$4, this);
  } // Getters


XhmikosR's avatar
XhmikosR committed
2088
  var _proto = Dropdown.prototype;
XhmikosR's avatar
Dist.  
XhmikosR committed
2089

XhmikosR's avatar
XhmikosR committed
2090
2091
  // Public
  _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
2092
    if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED)) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2093
2094
2095
      return;
    }

XhmikosR's avatar
XhmikosR committed
2096
    var isActive = this._element.classList.contains(CLASS_NAME_SHOW$1);
XhmikosR's avatar
Dist.  
XhmikosR committed
2097

XhmikosR's avatar
XhmikosR committed
2098
    Dropdown.clearMenus();
XhmikosR's avatar
Dist.  
XhmikosR committed
2099
2100
2101
2102
2103

    if (isActive) {
      return;
    }

XhmikosR's avatar
XhmikosR committed
2104
2105
2106
2107
    this.show();
  };

  _proto.show = function show() {
XhmikosR's avatar
XhmikosR committed
2108
    if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED) || this._menu.classList.contains(CLASS_NAME_SHOW$1)) {
XhmikosR's avatar
XhmikosR committed
2109
2110
2111
2112
      return;
    }

    var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
XhmikosR committed
2113
    var relatedTarget = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2114
2115
      relatedTarget: this._element
    };
XhmikosR's avatar
XhmikosR committed
2116
    var showEvent = EventHandler.trigger(this._element, EVENT_SHOW$1, relatedTarget);
XhmikosR's avatar
Dist.  
XhmikosR committed
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127

    if (showEvent.defaultPrevented) {
      return;
    } // Disable totally Popper.js for Dropdown in Navbar


    if (!this._inNavbar) {
      if (typeof Popper === 'undefined') {
        throw new TypeError('Bootstrap\'s dropdowns require Popper.js (https://popper.js.org)');
      }

XhmikosR's avatar
XhmikosR committed
2128
      var referenceElement = this._element;
XhmikosR's avatar
Dist.  
XhmikosR committed
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143

      if (this._config.reference === 'parent') {
        referenceElement = parent;
      } else if (isElement(this._config.reference)) {
        referenceElement = this._config.reference; // Check if it's jQuery element

        if (typeof this._config.reference.jquery !== 'undefined') {
          referenceElement = this._config.reference[0];
        }
      } // 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


      if (this._config.boundary !== 'scrollParent') {
XhmikosR's avatar
XhmikosR committed
2144
        parent.classList.add(CLASS_NAME_POSITION_STATIC);
XhmikosR's avatar
Dist.  
XhmikosR committed
2145
2146
2147
2148
2149
2150
2151
2152
2153
      }

      this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig());
    } // 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


XhmikosR's avatar
XhmikosR committed
2154
    if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
XhmikosR's avatar
XhmikosR committed
2155
2156
2157
      var _ref;

      (_ref = []).concat.apply(_ref, document.body.children).forEach(function (elem) {
XhmikosR's avatar
XhmikosR committed
2158
2159
        return EventHandler.on(elem, 'mouseover', null, noop());
      });
XhmikosR's avatar
Dist.  
XhmikosR committed
2160
2161
2162
2163
2164
2165
    }

    this._element.focus();

    this._element.setAttribute('aria-expanded', true);

Mark Otto's avatar
Mark Otto committed
2166
2167
2168
2169
    this._menu.classList.toggle(CLASS_NAME_SHOW$1);

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

XhmikosR's avatar
XhmikosR committed
2170
    EventHandler.trigger(parent, EVENT_SHOWN$1, relatedTarget);
XhmikosR's avatar
XhmikosR committed
2171
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2172

XhmikosR's avatar
XhmikosR committed
2173
  _proto.hide = function hide() {
XhmikosR's avatar
XhmikosR committed
2174
    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
2175
2176
2177
      return;
    }

XhmikosR's avatar
XhmikosR committed
2178
    var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
XhmikosR committed
2179
    var relatedTarget = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2180
2181
      relatedTarget: this._element
    };
XhmikosR's avatar
XhmikosR committed
2182
    var hideEvent = EventHandler.trigger(parent, EVENT_HIDE$1, relatedTarget);
XhmikosR's avatar
Dist.  
XhmikosR committed
2183
2184
2185
2186
2187

    if (hideEvent.defaultPrevented) {
      return;
    }

XhmikosR's avatar
XhmikosR committed
2188
2189
2190
2191
    if (this._popper) {
      this._popper.destroy();
    }

Mark Otto's avatar
Mark Otto committed
2192
2193
2194
2195
    this._menu.classList.toggle(CLASS_NAME_SHOW$1);

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

XhmikosR's avatar
XhmikosR committed
2196
    EventHandler.trigger(parent, EVENT_HIDDEN$1, relatedTarget);
XhmikosR's avatar
XhmikosR committed
2197
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2198

XhmikosR's avatar
XhmikosR committed
2199
  _proto.dispose = function dispose() {
XhmikosR's avatar
Dist.  
XhmikosR committed
2200
2201
2202
2203
2204
    Data.removeData(this._element, DATA_KEY$4);
    EventHandler.off(this._element, EVENT_KEY$4);
    this._element = null;
    this._menu = null;

XhmikosR's avatar
XhmikosR committed
2205
    if (this._popper) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2206
2207
2208
2209
      this._popper.destroy();

      this._popper = null;
    }
XhmikosR's avatar
XhmikosR committed
2210
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2211

XhmikosR's avatar
XhmikosR committed
2212
  _proto.update = function update() {
XhmikosR's avatar
Dist.  
XhmikosR committed
2213
2214
    this._inNavbar = this._detectNavbar();

XhmikosR's avatar
XhmikosR committed
2215
    if (this._popper) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2216
2217
2218
      this._popper.scheduleUpdate();
    }
  } // Private
XhmikosR's avatar
XhmikosR committed
2219
  ;
XhmikosR's avatar
Dist.  
XhmikosR committed
2220

XhmikosR's avatar
XhmikosR committed
2221
2222
  _proto._addEventListeners = function _addEventListeners() {
    var _this = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2223

XhmikosR's avatar
XhmikosR committed
2224
    EventHandler.on(this._element, EVENT_CLICK, function (event) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2225
2226
      event.preventDefault();
      event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
2227
2228

      _this.toggle();
XhmikosR's avatar
Dist.  
XhmikosR committed
2229
    });
XhmikosR's avatar
XhmikosR committed
2230
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2231

XhmikosR's avatar
XhmikosR committed
2232
  _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
2233
    config = _extends({}, this.constructor.Default, Manipulator.getDataAttributes(this._element), config);
XhmikosR's avatar
Dist.  
XhmikosR committed
2234
2235
    typeCheckConfig(NAME$4, config, this.constructor.DefaultType);
    return config;
XhmikosR's avatar
XhmikosR committed
2236
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2237

XhmikosR's avatar
XhmikosR committed
2238
  _proto._getMenuElement = function _getMenuElement() {
XhmikosR's avatar
XhmikosR committed
2239
    return SelectorEngine.next(this._element, SELECTOR_MENU)[0];
XhmikosR's avatar
XhmikosR committed
2240
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2241

XhmikosR's avatar
XhmikosR committed
2242
2243
  _proto._getPlacement = function _getPlacement() {
    var parentDropdown = this._element.parentNode;
XhmikosR's avatar
XhmikosR committed
2244
    var placement = PLACEMENT_BOTTOM; // Handle dropup
XhmikosR's avatar
Dist.  
XhmikosR committed
2245

XhmikosR's avatar
XhmikosR committed
2246
    if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
XhmikosR's avatar
XhmikosR committed
2247
      placement = this._menu.classList.contains(CLASS_NAME_MENURIGHT) ? PLACEMENT_TOPEND : PLACEMENT_TOP;
XhmikosR's avatar
XhmikosR committed
2248
2249
2250
2251
2252
2253
    } 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
2254
2255
2256
    }

    return placement;
XhmikosR's avatar
XhmikosR committed
2257
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2258

XhmikosR's avatar
XhmikosR committed
2259
  _proto._detectNavbar = function _detectNavbar() {
XhmikosR's avatar
XhmikosR committed
2260
    return Boolean(this._element.closest("." + CLASS_NAME_NAVBAR));
XhmikosR's avatar
XhmikosR committed
2261
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2262

XhmikosR's avatar
XhmikosR committed
2263
2264
2265
2266
  _proto._getOffset = function _getOffset() {
    var _this2 = this;

    var offset = {};
XhmikosR's avatar
Dist.  
XhmikosR committed
2267
2268

    if (typeof this._config.offset === 'function') {
XhmikosR's avatar
XhmikosR committed
2269
      offset.fn = function (data) {
XhmikosR's avatar
XhmikosR committed
2270
        data.offsets = _extends({}, data.offsets, _this2._config.offset(data.offsets, _this2._element) || {});
XhmikosR's avatar
Dist.  
XhmikosR committed
2271
2272
2273
2274
2275
2276
2277
        return data;
      };
    } else {
      offset.offset = this._config.offset;
    }

    return offset;
XhmikosR's avatar
XhmikosR committed
2278
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2279

XhmikosR's avatar
XhmikosR committed
2280
2281
  _proto._getPopperConfig = function _getPopperConfig() {
    var popperConfig = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2282
2283
2284
2285
2286
2287
2288
2289
2290
      placement: this._getPlacement(),
      modifiers: {
        offset: this._getOffset(),
        flip: {
          enabled: this._config.flip
        },
        preventOverflow: {
          boundariesElement: this._config.boundary
        }
XhmikosR's avatar
XhmikosR committed
2291
2292
      }
    }; // Disable Popper.js if we have a static display
XhmikosR's avatar
Dist.  
XhmikosR committed
2293
2294
2295
2296
2297
2298
2299

    if (this._config.display === 'static') {
      popperConfig.modifiers.applyStyle = {
        enabled: false
      };
    }

XhmikosR's avatar
XhmikosR committed
2300
    return _extends({}, popperConfig, this._config.popperConfig);
XhmikosR's avatar
Dist.  
XhmikosR committed
2301
  } // Static
XhmikosR's avatar
XhmikosR committed
2302
  ;
XhmikosR's avatar
Dist.  
XhmikosR committed
2303

XhmikosR's avatar
XhmikosR committed
2304
  Dropdown.dropdownInterface = function dropdownInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
2305
    var data = Data.getData(element, DATA_KEY$4);
XhmikosR's avatar
Dist.  
XhmikosR committed
2306

XhmikosR's avatar
XhmikosR committed
2307
    var _config = typeof config === 'object' ? config : null;
XhmikosR's avatar
Dist.  
XhmikosR committed
2308
2309
2310
2311
2312
2313
2314

    if (!data) {
      data = new Dropdown(element, _config);
    }

    if (typeof config === 'string') {
      if (typeof data[config] === 'undefined') {
XhmikosR's avatar
XhmikosR committed
2315
        throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist.  
XhmikosR committed
2316
2317
2318
2319
      }

      data[config]();
    }
XhmikosR's avatar
XhmikosR committed
2320
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2321

XhmikosR's avatar
XhmikosR committed
2322
  Dropdown.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2323
    return this.each(function () {
XhmikosR's avatar
XhmikosR committed
2324
      Dropdown.dropdownInterface(this, config);
XhmikosR's avatar
Dist.  
XhmikosR committed
2325
    });
XhmikosR's avatar
XhmikosR committed
2326
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2327

XhmikosR's avatar
XhmikosR committed
2328
  Dropdown.clearMenus = function clearMenus(event) {
XhmikosR's avatar
XhmikosR committed
2329
    if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2330
2331
2332
      return;
    }

XhmikosR's avatar
XhmikosR committed
2333
    var toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2334

XhmikosR's avatar
XhmikosR committed
2335
    for (var i = 0, len = toggles.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
2336
      var parent = Dropdown.getParentFromElement(toggles[i]);
XhmikosR's avatar
XhmikosR committed
2337
2338
      var context = Data.getData(toggles[i], DATA_KEY$4);
      var relatedTarget = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
        relatedTarget: toggles[i]
      };

      if (event && event.type === 'click') {
        relatedTarget.clickEvent = event;
      }

      if (!context) {
        continue;
      }

XhmikosR's avatar
XhmikosR committed
2350
      var dropdownMenu = context._menu;
XhmikosR's avatar
Dist.  
XhmikosR committed
2351

XhmikosR's avatar
XhmikosR committed
2352
      if (!toggles[i].classList.contains(CLASS_NAME_SHOW$1)) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2353
2354
2355
        continue;
      }

XhmikosR's avatar
XhmikosR committed
2356
      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
2357
2358
2359
        continue;
      }

XhmikosR's avatar
XhmikosR committed
2360
      var hideEvent = EventHandler.trigger(parent, EVENT_HIDE$1, relatedTarget);
XhmikosR's avatar
Dist.  
XhmikosR committed
2361
2362
2363
2364
2365
2366
2367
2368

      if (hideEvent.defaultPrevented) {
        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
2369
2370
2371
        var _ref2;

        (_ref2 = []).concat.apply(_ref2, document.body.children).forEach(function (elem) {
XhmikosR's avatar
XhmikosR committed
2372
2373
          return EventHandler.off(elem, 'mouseover', null, noop());
        });
XhmikosR's avatar
Dist.  
XhmikosR committed
2374
2375
2376
      }

      toggles[i].setAttribute('aria-expanded', 'false');
XhmikosR's avatar
XhmikosR committed
2377
2378
2379
2380
2381

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

XhmikosR's avatar
XhmikosR committed
2382
2383
2384
      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
2385
    }
XhmikosR's avatar
XhmikosR committed
2386
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2387

XhmikosR's avatar
XhmikosR committed
2388
2389
  Dropdown.getParentFromElement = function getParentFromElement(element) {
    return getElementFromSelector(element) || element.parentNode;
XhmikosR's avatar
XhmikosR committed
2390
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2391

XhmikosR's avatar
XhmikosR committed
2392
  Dropdown.dataApiKeydownHandler = function dataApiKeydownHandler(event) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2393
2394
2395
2396
2397
2398
2399
    // 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
2400
    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
2401
2402
2403
2404
2405
2406
      return;
    }

    event.preventDefault();
    event.stopPropagation();

XhmikosR's avatar
XhmikosR committed
2407
    if (this.disabled || this.classList.contains(CLASS_NAME_DISABLED)) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2408
2409
2410
      return;
    }

XhmikosR's avatar
XhmikosR committed
2411
    var parent = Dropdown.getParentFromElement(this);
XhmikosR's avatar
XhmikosR committed
2412
    var isActive = this.classList.contains(CLASS_NAME_SHOW$1);
XhmikosR's avatar
Dist.  
XhmikosR committed
2413

XhmikosR's avatar
XhmikosR committed
2414
    if (event.key === ESCAPE_KEY) {
XhmikosR's avatar
XhmikosR committed
2415
2416
2417
2418
2419
      var button = this.matches(SELECTOR_DATA_TOGGLE$2) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$2)[0];
      button.focus();
      Dropdown.clearMenus();
      return;
    }
XhmikosR's avatar
Dist.  
XhmikosR committed
2420

XhmikosR's avatar
XhmikosR committed
2421
    if (!isActive || event.key === SPACE_KEY) {
XhmikosR's avatar
XhmikosR committed
2422
      Dropdown.clearMenus();
XhmikosR's avatar
Dist.  
XhmikosR committed
2423
2424
2425
      return;
    }

XhmikosR's avatar
XhmikosR committed
2426
    var items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent).filter(isVisible);
XhmikosR's avatar
Dist.  
XhmikosR committed
2427
2428
2429
2430
2431

    if (!items.length) {
      return;
    }

XhmikosR's avatar
XhmikosR committed
2432
    var index = items.indexOf(event.target);
XhmikosR's avatar
Dist.  
XhmikosR committed
2433

XhmikosR's avatar
XhmikosR committed
2434
    if (event.key === ARROW_UP_KEY && index > 0) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2435
2436
2437
2438
      // Up
      index--;
    }

XhmikosR's avatar
XhmikosR committed
2439
    if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2440
2441
      // Down
      index++;
XhmikosR's avatar
XhmikosR committed
2442
2443
    } // index is -1 if the first keydown is an ArrowUp

XhmikosR's avatar
Dist.  
XhmikosR committed
2444

XhmikosR's avatar
XhmikosR committed
2445
    index = index === -1 ? 0 : index;
XhmikosR's avatar
Dist.  
XhmikosR committed
2446
    items[index].focus();
XhmikosR's avatar
XhmikosR committed
2447
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2448

XhmikosR's avatar
XhmikosR committed
2449
  Dropdown.getInstance = function getInstance(element) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2450
    return Data.getData(element, DATA_KEY$4);
XhmikosR's avatar
XhmikosR committed
2451
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2452

XhmikosR's avatar
XhmikosR committed
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
  _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;
    }
  }]);

  return Dropdown;
}();
XhmikosR's avatar
Dist.  
XhmikosR committed
2472
2473
2474
2475
2476
2477
2478
/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */


XhmikosR's avatar
XhmikosR committed
2479
2480
2481
2482
2483
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
2484
2485
  event.preventDefault();
  event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
2486
  Dropdown.dropdownInterface(this, 'toggle');
XhmikosR's avatar
Dist.  
XhmikosR committed
2487
});
XhmikosR's avatar
XhmikosR committed
2488
EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_FORM_CHILD, function (e) {
XhmikosR's avatar
XhmikosR committed
2489
2490
  return e.stopPropagation();
});
XhmikosR's avatar
Dist.  
XhmikosR committed
2491
2492
2493
2494
/**
 * ------------------------------------------------------------------------
 * jQuery
 * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
2495
 * add .Dropdown to jQuery only if jQuery is present
XhmikosR's avatar
Dist.  
XhmikosR committed
2496
2497
 */

XhmikosR's avatar
XhmikosR committed
2498
2499
2500
onDOMContentLoaded(function () {
  var $ = getjQuery();
  /* istanbul ignore if */
2501

XhmikosR's avatar
XhmikosR committed
2502
2503
2504
2505
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME$4];
    $.fn[NAME$4] = Dropdown.jQueryInterface;
    $.fn[NAME$4].Constructor = Dropdown;
XhmikosR's avatar
Dist.  
XhmikosR committed
2506

XhmikosR's avatar
XhmikosR committed
2507
2508
2509
2510
2511
2512
    $.fn[NAME$4].noConflict = function () {
      $.fn[NAME$4] = JQUERY_NO_CONFLICT;
      return Dropdown.jQueryInterface;
    };
  }
});
XhmikosR's avatar
Dist.  
XhmikosR committed
2513
2514
2515
2516
2517
2518
2519

/**
 * ------------------------------------------------------------------------
 * Constants
 * ------------------------------------------------------------------------
 */

XhmikosR's avatar
XhmikosR committed
2520
var NAME$5 = 'modal';
XhmikosR's avatar
XhmikosR committed
2521
var VERSION$5 = '5.0.0-alpha3';
XhmikosR's avatar
XhmikosR committed
2522
2523
2524
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
2525
var ESCAPE_KEY$1 = 'Escape';
XhmikosR's avatar
XhmikosR committed
2526
var Default$3 = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2527
2528
2529
2530
2531
  backdrop: true,
  keyboard: true,
  focus: true,
  show: true
};
XhmikosR's avatar
XhmikosR committed
2532
var DefaultType$3 = {
XhmikosR's avatar
Dist.  
XhmikosR committed
2533
2534
2535
2536
2537
  backdrop: '(boolean|string)',
  keyboard: 'boolean',
  focus: 'boolean',
  show: 'boolean'
};
XhmikosR's avatar
XhmikosR committed
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
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';
var SELECTOR_DATA_TOGGLE$3 = '[data-toggle="modal"]';
var SELECTOR_DATA_DISMISS = '[data-dismiss="modal"]';
var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
var SELECTOR_STICKY_CONTENT = '.sticky-top';
XhmikosR's avatar
XhmikosR committed
2562
2563
2564
2565
2566
/**
 * ------------------------------------------------------------------------
 * Class Definition
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
Dist.  
XhmikosR committed
2567

XhmikosR's avatar
XhmikosR committed
2568
var Modal = /*#__PURE__*/function () {
XhmikosR's avatar
XhmikosR committed
2569
  function Modal(element, config) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2570
2571
    this._config = this._getConfig(config);
    this._element = element;
XhmikosR's avatar
XhmikosR committed
2572
    this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, element);
XhmikosR's avatar
Dist.  
XhmikosR committed
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
    this._backdrop = null;
    this._isShown = false;
    this._isBodyOverflowing = false;
    this._ignoreBackdropClick = false;
    this._isTransitioning = false;
    this._scrollbarWidth = 0;
    Data.setData(element, DATA_KEY$5, this);
  } // Getters


XhmikosR's avatar
XhmikosR committed
2583
  var _proto = Modal.prototype;
XhmikosR's avatar
Dist.  
XhmikosR committed
2584

XhmikosR's avatar
XhmikosR committed
2585
2586
  // Public
  _proto.toggle = function toggle(relatedTarget) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2587
    return this._isShown ? this.hide() : this.show(relatedTarget);
XhmikosR's avatar
XhmikosR committed
2588
2589
2590
2591
  };

  _proto.show = function show(relatedTarget) {
    var _this = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2592
2593
2594
2595
2596

    if (this._isShown || this._isTransitioning) {
      return;
    }

XhmikosR's avatar
XhmikosR committed
2597
    if (this._element.classList.contains(CLASS_NAME_FADE)) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2598
2599
2600
      this._isTransitioning = true;
    }

XhmikosR's avatar
XhmikosR committed
2601
    var showEvent = EventHandler.trigger(this._element, EVENT_SHOW$2, {
XhmikosR's avatar
XhmikosR committed
2602
      relatedTarget: relatedTarget
XhmikosR's avatar
Dist.  
XhmikosR committed
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
    });

    if (this._isShown || showEvent.defaultPrevented) {
      return;
    }

    this._isShown = true;

    this._checkScrollbar();

    this._setScrollbar();

    this._adjustDialog();

    this._setEscapeEvent();

    this._setResizeEvent();

XhmikosR's avatar
XhmikosR committed
2621
    EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2622
2623
      return _this.hide(event);
    });
XhmikosR's avatar
XhmikosR committed
2624
2625
    EventHandler.on(this._dialog, EVENT_MOUSEDOWN_DISMISS, function () {
      EventHandler.one(_this._element, EVENT_MOUSEUP_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2626
2627
        if (event.target === _this._element) {
          _this._ignoreBackdropClick = true;
XhmikosR's avatar
Dist.  
XhmikosR committed
2628
2629
2630
2631
        }
      });
    });

XhmikosR's avatar
XhmikosR committed
2632
2633
2634
2635
2636
2637
2638
    this._showBackdrop(function () {
      return _this._showElement(relatedTarget);
    });
  };

  _proto.hide = function hide(event) {
    var _this2 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2639
2640
2641
2642
2643
2644
2645
2646
2647

    if (event) {
      event.preventDefault();
    }

    if (!this._isShown || this._isTransitioning) {
      return;
    }

XhmikosR's avatar
XhmikosR committed
2648
    var hideEvent = EventHandler.trigger(this._element, EVENT_HIDE$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2649

2650
    if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist.  
XhmikosR committed
2651
2652
2653
2654
2655
      return;
    }

    this._isShown = false;

XhmikosR's avatar
XhmikosR committed
2656
    var transition = this._element.classList.contains(CLASS_NAME_FADE);
XhmikosR's avatar
Dist.  
XhmikosR committed
2657
2658
2659
2660
2661
2662
2663
2664
2665

    if (transition) {
      this._isTransitioning = true;
    }

    this._setEscapeEvent();

    this._setResizeEvent();

XhmikosR's avatar
XhmikosR committed
2666
    EventHandler.off(document, EVENT_FOCUSIN);
XhmikosR's avatar
Dist.  
XhmikosR committed
2667

XhmikosR's avatar
XhmikosR committed
2668
    this._element.classList.remove(CLASS_NAME_SHOW$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2669

XhmikosR's avatar
XhmikosR committed
2670
2671
    EventHandler.off(this._element, EVENT_CLICK_DISMISS);
    EventHandler.off(this._dialog, EVENT_MOUSEDOWN_DISMISS);
XhmikosR's avatar
Dist.  
XhmikosR committed
2672
2673

    if (transition) {
XhmikosR's avatar
XhmikosR committed
2674
2675
2676
2677
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, function (event) {
        return _this2._hideModal(event);
      });
XhmikosR's avatar
Dist.  
XhmikosR committed
2678
2679
2680
2681
      emulateTransitionEnd(this._element, transitionDuration);
    } else {
      this._hideModal();
    }
XhmikosR's avatar
XhmikosR committed
2682
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2683

XhmikosR's avatar
XhmikosR committed
2684
2685
2686
2687
  _proto.dispose = function dispose() {
    [window, this._element, this._dialog].forEach(function (htmlElement) {
      return EventHandler.off(htmlElement, EVENT_KEY$5);
    });
XhmikosR's avatar
Dist.  
XhmikosR committed
2688
    /**
XhmikosR's avatar
XhmikosR committed
2689
     * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
XhmikosR's avatar
Dist.  
XhmikosR committed
2690
     * Do not move `document` in `htmlElements` array
XhmikosR's avatar
XhmikosR committed
2691
     * It will remove `EVENT_CLICK_DATA_API` event that should remain
XhmikosR's avatar
Dist.  
XhmikosR committed
2692
2693
     */

XhmikosR's avatar
XhmikosR committed
2694
    EventHandler.off(document, EVENT_FOCUSIN);
XhmikosR's avatar
Dist.  
XhmikosR committed
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
    Data.removeData(this._element, DATA_KEY$5);
    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;
XhmikosR's avatar
XhmikosR committed
2705
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2706

XhmikosR's avatar
XhmikosR committed
2707
  _proto.handleUpdate = function handleUpdate() {
XhmikosR's avatar
Dist.  
XhmikosR committed
2708
2709
    this._adjustDialog();
  } // Private
XhmikosR's avatar
XhmikosR committed
2710
  ;
XhmikosR's avatar
Dist.  
XhmikosR committed
2711

XhmikosR's avatar
XhmikosR committed
2712
  _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
2713
    config = _extends({}, Default$3, config);
XhmikosR's avatar
Dist.  
XhmikosR committed
2714
2715
    typeCheckConfig(NAME$5, config, DefaultType$3);
    return config;
XhmikosR's avatar
XhmikosR committed
2716
2717
2718
2719
  };

  _proto._showElement = function _showElement(relatedTarget) {
    var _this3 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2720

XhmikosR's avatar
XhmikosR committed
2721
    var transition = this._element.classList.contains(CLASS_NAME_FADE);
XhmikosR's avatar
Dist.  
XhmikosR committed
2722

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

XhmikosR's avatar
Dist.  
XhmikosR committed
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
    if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
      // Don't move modal's DOM position
      document.body.appendChild(this._element);
    }

    this._element.style.display = 'block';

    this._element.removeAttribute('aria-hidden');

    this._element.setAttribute('aria-modal', true);

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

XhmikosR's avatar
XhmikosR committed
2738
2739
2740
    this._element.scrollTop = 0;

    if (modalBody) {
XhmikosR's avatar
XhmikosR committed
2741
      modalBody.scrollTop = 0;
XhmikosR's avatar
Dist.  
XhmikosR committed
2742
2743
2744
2745
2746
2747
    }

    if (transition) {
      reflow(this._element);
    }

XhmikosR's avatar
XhmikosR committed
2748
    this._element.classList.add(CLASS_NAME_SHOW$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2749
2750
2751
2752
2753

    if (this._config.focus) {
      this._enforceFocus();
    }

XhmikosR's avatar
XhmikosR committed
2754
2755
2756
    var transitionComplete = function transitionComplete() {
      if (_this3._config.focus) {
        _this3._element.focus();
XhmikosR's avatar
Dist.  
XhmikosR committed
2757
2758
      }

XhmikosR's avatar
XhmikosR committed
2759
      _this3._isTransitioning = false;
XhmikosR's avatar
XhmikosR committed
2760
      EventHandler.trigger(_this3._element, EVENT_SHOWN$2, {
XhmikosR's avatar
XhmikosR committed
2761
        relatedTarget: relatedTarget
XhmikosR's avatar
Dist.  
XhmikosR committed
2762
2763
2764
2765
      });
    };

    if (transition) {
XhmikosR's avatar
XhmikosR committed
2766
      var transitionDuration = getTransitionDurationFromElement(this._dialog);
XhmikosR's avatar
Dist.  
XhmikosR committed
2767
2768
2769
2770
2771
      EventHandler.one(this._dialog, TRANSITION_END, transitionComplete);
      emulateTransitionEnd(this._dialog, transitionDuration);
    } else {
      transitionComplete();
    }
XhmikosR's avatar
XhmikosR committed
2772
2773
2774
2775
  };

  _proto._enforceFocus = function _enforceFocus() {
    var _this4 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2776

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

XhmikosR's avatar
XhmikosR committed
2779
    EventHandler.on(document, EVENT_FOCUSIN, function (event) {
XhmikosR's avatar
XhmikosR committed
2780
2781
      if (document !== event.target && _this4._element !== event.target && !_this4._element.contains(event.target)) {
        _this4._element.focus();
XhmikosR's avatar
Dist.  
XhmikosR committed
2782
2783
      }
    });
XhmikosR's avatar
XhmikosR committed
2784
2785
2786
2787
  };

  _proto._setEscapeEvent = function _setEscapeEvent() {
    var _this5 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2788

XhmikosR's avatar
XhmikosR committed
2789
2790
    if (this._isShown) {
      EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2791
        if (_this5._config.keyboard && event.key === ESCAPE_KEY$1) {
XhmikosR's avatar
XhmikosR committed
2792
2793
2794
          event.preventDefault();

          _this5.hide();
XhmikosR's avatar
XhmikosR committed
2795
        } else if (!_this5._config.keyboard && event.key === ESCAPE_KEY$1) {
XhmikosR's avatar
XhmikosR committed
2796
          _this5._triggerBackdropTransition();
XhmikosR's avatar
Dist.  
XhmikosR committed
2797
2798
        }
      });
2799
    } else {
XhmikosR's avatar
XhmikosR committed
2800
      EventHandler.off(this._element, EVENT_KEYDOWN_DISMISS);
XhmikosR's avatar
Dist.  
XhmikosR committed
2801
    }
XhmikosR's avatar
XhmikosR committed
2802
2803
2804
2805
  };

  _proto._setResizeEvent = function _setResizeEvent() {
    var _this6 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2806
2807

    if (this._isShown) {
XhmikosR's avatar
XhmikosR committed
2808
      EventHandler.on(window, EVENT_RESIZE, function () {
2809
        return _this6._adjustDialog();
XhmikosR's avatar
XhmikosR committed
2810
      });
XhmikosR's avatar
Dist.  
XhmikosR committed
2811
    } else {
XhmikosR's avatar
XhmikosR committed
2812
      EventHandler.off(window, EVENT_RESIZE);
XhmikosR's avatar
Dist.  
XhmikosR committed
2813
    }
XhmikosR's avatar
XhmikosR committed
2814
2815
2816
2817
  };

  _proto._hideModal = function _hideModal() {
    var _this7 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2818
2819
2820
2821
2822
2823
2824

    this._element.style.display = 'none';

    this._element.setAttribute('aria-hidden', true);

    this._element.removeAttribute('aria-modal');

Mark Otto's avatar
Mark Otto committed
2825
2826
    this._element.removeAttribute('role');

XhmikosR's avatar
Dist.  
XhmikosR committed
2827
2828
    this._isTransitioning = false;

XhmikosR's avatar
XhmikosR committed
2829
    this._showBackdrop(function () {
XhmikosR's avatar
XhmikosR committed
2830
      document.body.classList.remove(CLASS_NAME_OPEN);
XhmikosR's avatar
Dist.  
XhmikosR committed
2831

XhmikosR's avatar
XhmikosR committed
2832
      _this7._resetAdjustments();
XhmikosR's avatar
Dist.  
XhmikosR committed
2833

XhmikosR's avatar
XhmikosR committed
2834
      _this7._resetScrollbar();
XhmikosR's avatar
Dist.  
XhmikosR committed
2835

XhmikosR's avatar
XhmikosR committed
2836
      EventHandler.trigger(_this7._element, EVENT_HIDDEN$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2837
    });
XhmikosR's avatar
XhmikosR committed
2838
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2839

XhmikosR's avatar
XhmikosR committed
2840
  _proto._removeBackdrop = function _removeBackdrop() {
2841
    this._backdrop.parentNode.removeChild(this._backdrop);
XhmikosR's avatar
Dist.  
XhmikosR committed
2842

2843
    this._backdrop = null;
XhmikosR's avatar
XhmikosR committed
2844
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2845

XhmikosR's avatar
XhmikosR committed
2846
2847
2848
  _proto._showBackdrop = function _showBackdrop(callback) {
    var _this8 = this;

XhmikosR's avatar
XhmikosR committed
2849
    var animate = this._element.classList.contains(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
XhmikosR's avatar
Dist.  
XhmikosR committed
2850
2851
2852

    if (this._isShown && this._config.backdrop) {
      this._backdrop = document.createElement('div');
XhmikosR's avatar
XhmikosR committed
2853
      this._backdrop.className = CLASS_NAME_BACKDROP;
XhmikosR's avatar
Dist.  
XhmikosR committed
2854
2855
2856
2857
2858
2859

      if (animate) {
        this._backdrop.classList.add(animate);
      }

      document.body.appendChild(this._backdrop);
XhmikosR's avatar
XhmikosR committed
2860
      EventHandler.on(this._element, EVENT_CLICK_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
2861
2862
        if (_this8._ignoreBackdropClick) {
          _this8._ignoreBackdropClick = false;
XhmikosR's avatar
Dist.  
XhmikosR committed
2863
2864
2865
2866
2867
2868
2869
          return;
        }

        if (event.target !== event.currentTarget) {
          return;
        }

XhmikosR's avatar
XhmikosR committed
2870
        _this8._triggerBackdropTransition();
XhmikosR's avatar
Dist.  
XhmikosR committed
2871
2872
2873
2874
2875
2876
      });

      if (animate) {
        reflow(this._backdrop);
      }

XhmikosR's avatar
XhmikosR committed
2877
      this._backdrop.classList.add(CLASS_NAME_SHOW$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2878
2879
2880
2881
2882
2883

      if (!animate) {
        callback();
        return;
      }

XhmikosR's avatar
XhmikosR committed
2884
      var backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
XhmikosR's avatar
Dist.  
XhmikosR committed
2885
2886
2887
      EventHandler.one(this._backdrop, TRANSITION_END, callback);
      emulateTransitionEnd(this._backdrop, backdropTransitionDuration);
    } else if (!this._isShown && this._backdrop) {
XhmikosR's avatar
XhmikosR committed
2888
      this._backdrop.classList.remove(CLASS_NAME_SHOW$2);
XhmikosR's avatar
Dist.  
XhmikosR committed
2889

XhmikosR's avatar
XhmikosR committed
2890
2891
      var callbackRemove = function callbackRemove() {
        _this8._removeBackdrop();
XhmikosR's avatar
Dist.  
XhmikosR committed
2892

2893
        callback();
XhmikosR's avatar
Dist.  
XhmikosR committed
2894
2895
      };

XhmikosR's avatar
XhmikosR committed
2896
      if (this._element.classList.contains(CLASS_NAME_FADE)) {
XhmikosR's avatar
XhmikosR committed
2897
2898
        var _backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);

XhmikosR's avatar
Dist.  
XhmikosR committed
2899
        EventHandler.one(this._backdrop, TRANSITION_END, callbackRemove);
XhmikosR's avatar
XhmikosR committed
2900
        emulateTransitionEnd(this._backdrop, _backdropTransitionDuration);
XhmikosR's avatar
Dist.  
XhmikosR committed
2901
2902
2903
      } else {
        callbackRemove();
      }
2904
    } else {
XhmikosR's avatar
Dist.  
XhmikosR committed
2905
2906
      callback();
    }
XhmikosR's avatar
XhmikosR committed
2907
2908
2909
2910
2911
2912
  };

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

    if (this._config.backdrop === 'static') {
XhmikosR's avatar
XhmikosR committed
2913
      var hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED);
XhmikosR's avatar
XhmikosR committed
2914
2915
2916
2917
2918

      if (hideEvent.defaultPrevented) {
        return;
      }

XhmikosR's avatar
XhmikosR committed
2919
2920
2921
2922
2923
2924
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;

      if (!isModalOverflowing) {
        this._element.style.overflowY = 'hidden';
      }

XhmikosR's avatar
XhmikosR committed
2925
      this._element.classList.add(CLASS_NAME_STATIC);
XhmikosR's avatar
XhmikosR committed
2926

XhmikosR's avatar
XhmikosR committed
2927
2928
      var modalTransitionDuration = getTransitionDurationFromElement(this._dialog);
      EventHandler.off(this._element, TRANSITION_END);
XhmikosR's avatar
XhmikosR committed
2929
      EventHandler.one(this._element, TRANSITION_END, function () {
XhmikosR's avatar
XhmikosR committed
2930
        _this9._element.classList.remove(CLASS_NAME_STATIC);
XhmikosR's avatar
XhmikosR committed
2931
2932
2933
2934
2935
2936
2937

        if (!isModalOverflowing) {
          EventHandler.one(_this9._element, TRANSITION_END, function () {
            _this9._element.style.overflowY = '';
          });
          emulateTransitionEnd(_this9._element, modalTransitionDuration);
        }
XhmikosR's avatar
XhmikosR committed
2938
2939
2940
2941
2942
2943
2944
      });
      emulateTransitionEnd(this._element, modalTransitionDuration);

      this._element.focus();
    } else {
      this.hide();
    }
XhmikosR's avatar
Dist.  
XhmikosR committed
2945
2946
2947
  } // ----------------------------------------------------------------------
  // the following methods are used to handle overflowing modals
  // ----------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
2948
  ;
XhmikosR's avatar
Dist.  
XhmikosR committed
2949

XhmikosR's avatar
XhmikosR committed
2950
2951
  _proto._adjustDialog = function _adjustDialog() {
    var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
XhmikosR's avatar
Dist.  
XhmikosR committed
2952
2953

    if (!this._isBodyOverflowing && isModalOverflowing) {
XhmikosR's avatar
XhmikosR committed
2954
      this._element.style.paddingLeft = this._scrollbarWidth + "px";
XhmikosR's avatar
Dist.  
XhmikosR committed
2955
2956
2957
    }

    if (this._isBodyOverflowing && !isModalOverflowing) {
XhmikosR's avatar
XhmikosR committed
2958
      this._element.style.paddingRight = this._scrollbarWidth + "px";
XhmikosR's avatar
Dist.  
XhmikosR committed
2959
    }
XhmikosR's avatar
XhmikosR committed
2960
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2961

XhmikosR's avatar
XhmikosR committed
2962
  _proto._resetAdjustments = function _resetAdjustments() {
XhmikosR's avatar
Dist.  
XhmikosR committed
2963
2964
    this._element.style.paddingLeft = '';
    this._element.style.paddingRight = '';
XhmikosR's avatar
XhmikosR committed
2965
  };
XhmikosR's avatar
Dist.  
XhmikosR committed
2966

XhmikosR's avatar
XhmikosR committed
2967
2968
  _proto._checkScrollbar = function _checkScrollbar() {
    var rect = document.body.getBoundingClientRect();
XhmikosR's avatar
XhmikosR committed
2969
    this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
XhmikosR's avatar
Dist.  
XhmikosR committed
2970
    this._scrollbarWidth = this._getScrollbarWidth();
XhmikosR's avatar
XhmikosR committed
2971
2972
2973
  };

  _proto._setScrollbar = function _setScrollbar() {
XhmikosR's avatar
XhmikosR committed
2974
    var _this10 = this;
XhmikosR's avatar
Dist.  
XhmikosR committed
2975
2976
2977
2978
2979

    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
      // Adjust fixed content padding
XhmikosR's avatar
XhmikosR committed
2980
      SelectorEngine.find(SELECTOR_FIXED_CONTENT).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
2981
2982
        var actualPadding = element.style.paddingRight;
        var calculatedPadding = window.getComputedStyle(element)['padding-right'];
XhmikosR's avatar
Dist.  
XhmikosR committed
2983
        Manipulator.setDataAttribute(element, 'padding-right', actualPadding);
XhmikosR's avatar
XhmikosR committed
2984
        element.style.paddingRight = parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px";
XhmikosR's avatar
Dist.  
XhmikosR committed
2985
2986
      }); // Adjust sticky content margin

XhmikosR's avatar
XhmikosR committed
2987
      SelectorEngine.find(SELECTOR_STICKY_CONTENT).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
2988
2989
        var actualMargin = element.style.marginRight;
        var calculatedMargin = window.getComputedStyle(element)['margin-right'];
XhmikosR's avatar
Dist.  
XhmikosR committed
2990
        Manipulator.setDataAttribute(element, 'margin-right', actualMargin);
XhmikosR's avatar
XhmikosR committed
2991
        element.style.marginRight = parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px";
XhmikosR's avatar
Dist.  
XhmikosR committed
2992
2993
      }); // Adjust body padding

XhmikosR's avatar
XhmikosR committed
2994
2995
      var actualPadding = document.body.style.paddingRight;
      var calculatedPadding = window.getComputedStyle(document.body)['padding-right'];
XhmikosR's avatar
Dist.  
XhmikosR committed
2996
      Manipulator.setDataAttribute(document.body, 'padding-right', actualPadding);
XhmikosR's avatar
XhmikosR committed
2997
      document.body.style.paddingRight = parseFloat(calculatedPadding) + this._scrollbarWidth + "px";
XhmikosR's avatar
Dist.  
XhmikosR committed
2998
2999
    }

XhmikosR's avatar
XhmikosR committed
3000
    document.body.classList.add(CLASS_NAME_OPEN);
For faster browsing, not all history is shown. View entire blame