1 (function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('popper.js'), require('./util.js')) :
3 typeof define === 'function' && define.amd ? define(['jquery', 'popper.js', './util.js'], factory) :
4 (global.Dropdown = factory(global.jQuery,global.Popper,global.Util));
5 }(this, (function ($,Popper,Util) { 'use strict';
7 $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
8 Popper = Popper && Popper.hasOwnProperty('default') ? Popper['default'] : Popper;
9 Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;
11 function _defineProperties(target, props) {
12 for (var i = 0; i < props.length; i++) {
13 var descriptor = props[i];
14 descriptor.enumerable = descriptor.enumerable || false;
15 descriptor.configurable = true;
16 if ("value" in descriptor) descriptor.writable = true;
17 Object.defineProperty(target, descriptor.key, descriptor);
21 function _createClass(Constructor, protoProps, staticProps) {
22 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23 if (staticProps) _defineProperties(Constructor, staticProps);
27 function _defineProperty(obj, key, value) {
29 Object.defineProperty(obj, key, {
42 function _objectSpread(target) {
43 for (var i = 1; i < arguments.length; i++) {
44 var source = arguments[i] != null ? arguments[i] : {};
45 var ownKeys = Object.keys(source);
47 if (typeof Object.getOwnPropertySymbols === 'function') {
48 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
49 return Object.getOwnPropertyDescriptor(source, sym).enumerable;
53 ownKeys.forEach(function (key) {
54 _defineProperty(target, key, source[key]);
62 * --------------------------------------------------------------------------
63 * Bootstrap (v4.1.3): dropdown.js
64 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
65 * --------------------------------------------------------------------------
68 var Dropdown = function ($$$1) {
70 * ------------------------------------------------------------------------
72 * ------------------------------------------------------------------------
74 var NAME = 'dropdown';
75 var VERSION = '4.1.3';
76 var DATA_KEY = 'bs.dropdown';
77 var EVENT_KEY = "." + DATA_KEY;
78 var DATA_API_KEY = '.data-api';
79 var JQUERY_NO_CONFLICT = $$$1.fn[NAME];
80 var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
82 var SPACE_KEYCODE = 32; // KeyboardEvent.which value for space key
84 var TAB_KEYCODE = 9; // KeyboardEvent.which value for tab key
86 var ARROW_UP_KEYCODE = 38; // KeyboardEvent.which value for up arrow key
88 var ARROW_DOWN_KEYCODE = 40; // KeyboardEvent.which value for down arrow key
90 var RIGHT_MOUSE_BUTTON_WHICH = 3; // MouseEvent.which value for the right button (assuming a right-handed mouse)
92 var REGEXP_KEYDOWN = new RegExp(ARROW_UP_KEYCODE + "|" + ARROW_DOWN_KEYCODE + "|" + ESCAPE_KEYCODE);
94 HIDE: "hide" + EVENT_KEY,
95 HIDDEN: "hidden" + EVENT_KEY,
96 SHOW: "show" + EVENT_KEY,
97 SHOWN: "shown" + EVENT_KEY,
98 CLICK: "click" + EVENT_KEY,
99 CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
100 KEYDOWN_DATA_API: "keydown" + EVENT_KEY + DATA_API_KEY,
101 KEYUP_DATA_API: "keyup" + EVENT_KEY + DATA_API_KEY
104 DISABLED: 'disabled',
107 DROPRIGHT: 'dropright',
108 DROPLEFT: 'dropleft',
109 MENURIGHT: 'dropdown-menu-right',
110 MENULEFT: 'dropdown-menu-left',
111 POSITION_STATIC: 'position-static'
114 DATA_TOGGLE: '[data-toggle="dropdown"]',
115 FORM_CHILD: '.dropdown form',
116 MENU: '.dropdown-menu',
117 NAVBAR_NAV: '.navbar-nav',
118 VISIBLE_ITEMS: '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
120 var AttachmentMap = {
123 BOTTOM: 'bottom-start',
124 BOTTOMEND: 'bottom-end',
125 RIGHT: 'right-start',
126 RIGHTEND: 'right-end',
133 boundary: 'scrollParent',
138 offset: '(number|string|function)',
140 boundary: '(string|element)',
141 reference: '(string|element)',
144 * ------------------------------------------------------------------------
146 * ------------------------------------------------------------------------
154 function Dropdown(element, config) {
155 this._element = element;
157 this._config = this._getConfig(config);
158 this._menu = this._getMenuElement();
159 this._inNavbar = this._detectNavbar();
161 this._addEventListeners();
165 var _proto = Dropdown.prototype;
168 _proto.toggle = function toggle() {
169 if (this._element.disabled || $$$1(this._element).hasClass(ClassName.DISABLED)) {
173 var parent = Dropdown._getParentFromElement(this._element);
175 var isActive = $$$1(this._menu).hasClass(ClassName.SHOW);
177 Dropdown._clearMenus();
183 var relatedTarget = {
184 relatedTarget: this._element
186 var showEvent = $$$1.Event(Event.SHOW, relatedTarget);
187 $$$1(parent).trigger(showEvent);
189 if (showEvent.isDefaultPrevented()) {
191 } // Disable totally Popper.js for Dropdown in Navbar
194 if (!this._inNavbar) {
196 * Check for Popper dependency
197 * Popper - https://popper.js.org
199 if (typeof Popper === 'undefined') {
200 throw new TypeError('Bootstrap dropdown require Popper.js (https://popper.js.org)');
203 var referenceElement = this._element;
205 if (this._config.reference === 'parent') {
206 referenceElement = parent;
207 } else if (Util.isElement(this._config.reference)) {
208 referenceElement = this._config.reference; // Check if it's jQuery element
210 if (typeof this._config.reference.jquery !== 'undefined') {
211 referenceElement = this._config.reference[0];
213 } // If boundary is not `scrollParent`, then set position to `static`
214 // to allow the menu to "escape" the scroll parent's boundaries
215 // https://github.com/twbs/bootstrap/issues/24251
218 if (this._config.boundary !== 'scrollParent') {
219 $$$1(parent).addClass(ClassName.POSITION_STATIC);
222 this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig());
223 } // If this is a touch-enabled device we add extra
224 // empty mouseover listeners to the body's immediate children;
225 // only needed because of broken event delegation on iOS
226 // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
229 if ('ontouchstart' in document.documentElement && $$$1(parent).closest(Selector.NAVBAR_NAV).length === 0) {
230 $$$1(document.body).children().on('mouseover', null, $$$1.noop);
233 this._element.focus();
235 this._element.setAttribute('aria-expanded', true);
237 $$$1(this._menu).toggleClass(ClassName.SHOW);
238 $$$1(parent).toggleClass(ClassName.SHOW).trigger($$$1.Event(Event.SHOWN, relatedTarget));
241 _proto.dispose = function dispose() {
242 $$$1.removeData(this._element, DATA_KEY);
243 $$$1(this._element).off(EVENT_KEY);
244 this._element = null;
247 if (this._popper !== null) {
248 this._popper.destroy();
254 _proto.update = function update() {
255 this._inNavbar = this._detectNavbar();
257 if (this._popper !== null) {
258 this._popper.scheduleUpdate();
263 _proto._addEventListeners = function _addEventListeners() {
266 $$$1(this._element).on(Event.CLICK, function (event) {
267 event.preventDefault();
268 event.stopPropagation();
274 _proto._getConfig = function _getConfig(config) {
275 config = _objectSpread({}, this.constructor.Default, $$$1(this._element).data(), config);
276 Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
280 _proto._getMenuElement = function _getMenuElement() {
282 var parent = Dropdown._getParentFromElement(this._element);
285 this._menu = parent.querySelector(Selector.MENU);
292 _proto._getPlacement = function _getPlacement() {
293 var $parentDropdown = $$$1(this._element.parentNode);
294 var placement = AttachmentMap.BOTTOM; // Handle dropup
296 if ($parentDropdown.hasClass(ClassName.DROPUP)) {
297 placement = AttachmentMap.TOP;
299 if ($$$1(this._menu).hasClass(ClassName.MENURIGHT)) {
300 placement = AttachmentMap.TOPEND;
302 } else if ($parentDropdown.hasClass(ClassName.DROPRIGHT)) {
303 placement = AttachmentMap.RIGHT;
304 } else if ($parentDropdown.hasClass(ClassName.DROPLEFT)) {
305 placement = AttachmentMap.LEFT;
306 } else if ($$$1(this._menu).hasClass(ClassName.MENURIGHT)) {
307 placement = AttachmentMap.BOTTOMEND;
313 _proto._detectNavbar = function _detectNavbar() {
314 return $$$1(this._element).closest('.navbar').length > 0;
317 _proto._getPopperConfig = function _getPopperConfig() {
322 if (typeof this._config.offset === 'function') {
323 offsetConf.fn = function (data) {
324 data.offsets = _objectSpread({}, data.offsets, _this2._config.offset(data.offsets) || {});
328 offsetConf.offset = this._config.offset;
332 placement: this._getPlacement(),
336 enabled: this._config.flip
339 boundariesElement: this._config.boundary
341 } // Disable Popper.js if we have a static display
345 if (this._config.display === 'static') {
346 popperConfig.modifiers.applyStyle = {
355 Dropdown._jQueryInterface = function _jQueryInterface(config) {
356 return this.each(function () {
357 var data = $$$1(this).data(DATA_KEY);
359 var _config = typeof config === 'object' ? config : null;
362 data = new Dropdown(this, _config);
363 $$$1(this).data(DATA_KEY, data);
366 if (typeof config === 'string') {
367 if (typeof data[config] === 'undefined') {
368 throw new TypeError("No method named \"" + config + "\"");
376 Dropdown._clearMenus = function _clearMenus(event) {
377 if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
381 var toggles = [].slice.call(document.querySelectorAll(Selector.DATA_TOGGLE));
383 for (var i = 0, len = toggles.length; i < len; i++) {
384 var parent = Dropdown._getParentFromElement(toggles[i]);
386 var context = $$$1(toggles[i]).data(DATA_KEY);
387 var relatedTarget = {
388 relatedTarget: toggles[i]
391 if (event && event.type === 'click') {
392 relatedTarget.clickEvent = event;
399 var dropdownMenu = context._menu;
401 if (!$$$1(parent).hasClass(ClassName.SHOW)) {
405 if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $$$1.contains(parent, event.target)) {
409 var hideEvent = $$$1.Event(Event.HIDE, relatedTarget);
410 $$$1(parent).trigger(hideEvent);
412 if (hideEvent.isDefaultPrevented()) {
414 } // If this is a touch-enabled device we remove the extra
415 // empty mouseover listeners we added for iOS support
418 if ('ontouchstart' in document.documentElement) {
419 $$$1(document.body).children().off('mouseover', null, $$$1.noop);
422 toggles[i].setAttribute('aria-expanded', 'false');
423 $$$1(dropdownMenu).removeClass(ClassName.SHOW);
424 $$$1(parent).removeClass(ClassName.SHOW).trigger($$$1.Event(Event.HIDDEN, relatedTarget));
428 Dropdown._getParentFromElement = function _getParentFromElement(element) {
430 var selector = Util.getSelectorFromElement(element);
433 parent = document.querySelector(selector);
436 return parent || element.parentNode;
437 }; // eslint-disable-next-line complexity
440 Dropdown._dataApiKeydownHandler = function _dataApiKeydownHandler(event) {
441 // If not input/textarea:
442 // - And not a key in REGEXP_KEYDOWN => not a dropdown command
443 // If input/textarea:
444 // - If space key => not a dropdown command
445 // - If key is other than escape
446 // - If key is not up or down => not a dropdown command
447 // - If trigger inside the menu => not a dropdown command
448 if (/input|textarea/i.test(event.target.tagName) ? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && (event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE || $$$1(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) {
452 event.preventDefault();
453 event.stopPropagation();
455 if (this.disabled || $$$1(this).hasClass(ClassName.DISABLED)) {
459 var parent = Dropdown._getParentFromElement(this);
461 var isActive = $$$1(parent).hasClass(ClassName.SHOW);
463 if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
464 if (event.which === ESCAPE_KEYCODE) {
465 var toggle = parent.querySelector(Selector.DATA_TOGGLE);
466 $$$1(toggle).trigger('focus');
469 $$$1(this).trigger('click');
473 var items = [].slice.call(parent.querySelectorAll(Selector.VISIBLE_ITEMS));
475 if (items.length === 0) {
479 var index = items.indexOf(event.target);
481 if (event.which === ARROW_UP_KEYCODE && index > 0) {
486 if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
495 items[index].focus();
498 _createClass(Dropdown, null, [{
500 get: function get() {
505 get: function get() {
510 get: function get() {
518 * ------------------------------------------------------------------------
519 * Data Api implementation
520 * ------------------------------------------------------------------------
524 $$$1(document).on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler).on(Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown._dataApiKeydownHandler).on(Event.CLICK_DATA_API + " " + Event.KEYUP_DATA_API, Dropdown._clearMenus).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
525 event.preventDefault();
526 event.stopPropagation();
528 Dropdown._jQueryInterface.call($$$1(this), 'toggle');
529 }).on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
533 * ------------------------------------------------------------------------
535 * ------------------------------------------------------------------------
538 $$$1.fn[NAME] = Dropdown._jQueryInterface;
539 $$$1.fn[NAME].Constructor = Dropdown;
541 $$$1.fn[NAME].noConflict = function () {
542 $$$1.fn[NAME] = JQUERY_NO_CONFLICT;
543 return Dropdown._jQueryInterface;
552 //# sourceMappingURL=dropdown.js.map