2018-11-13 07:41:12 +01:00
/ * !
2021-02-10 17:14:51 +01:00
* Bootstrap dropdown . js v5 . 0.0 - beta2 ( https : //getbootstrap.com/)
* Copyright 2011 - 2021 The Bootstrap Authors ( https : //github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 20:50:01 +02:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
2018-11-13 07:41:12 +01:00
* /
2018-07-24 02:51:14 +02:00
( function ( global , factory ) {
2021-02-10 17:14:51 +01:00
typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( require ( '@popperjs/core' ) , require ( './dom/data.js' ) , require ( './dom/event-handler.js' ) , require ( './dom/manipulator.js' ) , require ( './dom/selector-engine.js' ) , require ( './base-component.js' ) ) :
typeof define === 'function' && define . amd ? define ( [ '@popperjs/core' , './dom/data' , './dom/event-handler' , './dom/manipulator' , './dom/selector-engine' , './base-component' ] , factory ) :
( global = typeof globalThis !== 'undefined' ? globalThis : global || self , global . Dropdown = factory ( global . Popper , global . Data , global . EventHandler , global . Manipulator , global . SelectorEngine , global . Base ) ) ;
} ( this , ( function ( Popper , Data , EventHandler , Manipulator , SelectorEngine , BaseComponent ) { 'use strict' ;
2019-03-01 17:31:34 +01:00
2020-09-14 17:12:06 +02:00
function _interopDefaultLegacy ( e ) { return e && typeof e === 'object' && 'default' in e ? e : { 'default' : e } ; }
2020-12-07 16:50:24 +01:00
function _interopNamespace ( e ) {
if ( e && e . _ _esModule ) return e ;
var n = Object . create ( null ) ;
if ( e ) {
Object . keys ( e ) . forEach ( function ( k ) {
if ( k !== 'default' ) {
var d = Object . getOwnPropertyDescriptor ( e , k ) ;
Object . defineProperty ( n , k , d . get ? d : {
enumerable : true ,
get : function ( ) {
return e [ k ] ;
}
} ) ;
}
} ) ;
}
n [ 'default' ] = e ;
return Object . freeze ( n ) ;
}
var Popper _ _namespace = /*#__PURE__*/ _interopNamespace ( Popper ) ;
2020-09-14 17:12:06 +02:00
var Data _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Data ) ;
var EventHandler _ _default = /*#__PURE__*/ _interopDefaultLegacy ( EventHandler ) ;
var Manipulator _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Manipulator ) ;
var SelectorEngine _ _default = /*#__PURE__*/ _interopDefaultLegacy ( SelectorEngine ) ;
2021-02-10 17:14:51 +01:00
var BaseComponent _ _default = /*#__PURE__*/ _interopDefaultLegacy ( BaseComponent ) ;
function _defineProperties ( target , props ) {
for ( var i = 0 ; i < props . length ; i ++ ) {
var descriptor = props [ i ] ;
descriptor . enumerable = descriptor . enumerable || false ;
descriptor . configurable = true ;
if ( "value" in descriptor ) descriptor . writable = true ;
Object . defineProperty ( target , descriptor . key , descriptor ) ;
}
}
function _createClass ( Constructor , protoProps , staticProps ) {
if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ;
if ( staticProps ) _defineProperties ( Constructor , staticProps ) ;
return Constructor ;
}
function _extends ( ) {
_extends = Object . assign || function ( target ) {
for ( var i = 1 ; i < arguments . length ; i ++ ) {
var source = arguments [ i ] ;
for ( var key in source ) {
if ( Object . prototype . hasOwnProperty . call ( source , key ) ) {
target [ key ] = source [ key ] ;
}
}
}
return target ;
} ;
return _extends . apply ( this , arguments ) ;
}
function _inheritsLoose ( subClass , superClass ) {
subClass . prototype = Object . create ( superClass . prototype ) ;
subClass . prototype . constructor = subClass ;
2021-02-11 16:22:18 +01:00
_setPrototypeOf ( subClass , superClass ) ;
}
function _setPrototypeOf ( o , p ) {
_setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) {
o . _ _proto _ _ = p ;
return o ;
} ;
return _setPrototypeOf ( o , p ) ;
2021-02-10 17:14:51 +01:00
}
2018-07-24 02:51:14 +02:00
2019-03-01 17:31:34 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2021-02-10 17:14:51 +01:00
* Bootstrap ( v5 . 0.0 - beta2 ) : util / index . js
2020-06-16 20:50:01 +02:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
var toType = function toType ( obj ) {
2020-03-28 11:29:08 +01:00
if ( obj === null || obj === undefined ) {
return "" + obj ;
}
2019-03-01 17:31:34 +01:00
return { } . toString . call ( obj ) . match ( /\s([a-z]+)/i ) [ 1 ] . toLowerCase ( ) ;
} ;
2019-08-27 15:03:21 +02:00
var getSelector = function getSelector ( element ) {
2020-11-23 14:17:16 +01:00
var selector = element . getAttribute ( 'data-bs-target' ) ;
2019-03-01 17:31:34 +01:00
if ( ! selector || selector === '#' ) {
2021-02-10 17:14:51 +01:00
var hrefAttr = element . getAttribute ( 'href' ) ; // The only valid content that could double as a selector are IDs or classes,
// so everything starting with `#` or `.`. If a "real" URL is used as the selector,
// `document.querySelector` will rightfully complain it is invalid.
// See https://github.com/twbs/bootstrap/issues/32273
if ( ! hrefAttr || ! hrefAttr . includes ( '#' ) && ! hrefAttr . startsWith ( '.' ) ) {
return null ;
} // Just in case some CMS puts out a full URL with the anchor appended
if ( hrefAttr . includes ( '#' ) && ! hrefAttr . startsWith ( '#' ) ) {
hrefAttr = '#' + hrefAttr . split ( '#' ) [ 1 ] ;
}
2019-08-27 15:03:21 +02:00
selector = hrefAttr && hrefAttr !== '#' ? hrefAttr . trim ( ) : null ;
2019-03-01 17:31:34 +01:00
}
2019-08-27 15:03:21 +02:00
return selector ;
} ;
var getElementFromSelector = function getElementFromSelector ( element ) {
var selector = getSelector ( element ) ;
return selector ? document . querySelector ( selector ) : null ;
2019-03-01 17:31:34 +01:00
} ;
var isElement = function isElement ( obj ) {
return ( obj [ 0 ] || obj ) . nodeType ;
} ;
var typeCheckConfig = function typeCheckConfig ( componentName , config , configTypes ) {
Object . keys ( configTypes ) . forEach ( function ( property ) {
var expectedTypes = configTypes [ property ] ;
var value = config [ property ] ;
var valueType = value && isElement ( value ) ? 'element' : toType ( value ) ;
if ( ! new RegExp ( expectedTypes ) . test ( valueType ) ) {
2021-02-10 17:14:51 +01:00
throw new TypeError ( componentName . toUpperCase ( ) + ": " + ( "Option \"" + property + "\" provided type \"" + valueType + "\" " ) + ( "but expected type \"" + expectedTypes + "\"." ) ) ;
2019-03-01 17:31:34 +01:00
}
} ) ;
} ;
2019-11-08 09:11:23 +01:00
var isVisible = function isVisible ( element ) {
if ( ! element ) {
return false ;
}
if ( element . style && element . parentNode && element . parentNode . style ) {
var elementStyle = getComputedStyle ( element ) ;
var parentNodeStyle = getComputedStyle ( element . parentNode ) ;
return elementStyle . display !== 'none' && parentNodeStyle . display !== 'none' && elementStyle . visibility !== 'hidden' ;
}
return false ;
} ;
2019-03-01 17:31:34 +01:00
var noop = function noop ( ) {
return function ( ) { } ;
} ;
2019-08-27 15:03:21 +02:00
var getjQuery = function getjQuery ( ) {
var _window = window ,
jQuery = _window . jQuery ;
2020-11-23 14:17:16 +01:00
if ( jQuery && ! document . body . hasAttribute ( 'data-bs-no-jquery' ) ) {
2019-08-27 15:03:21 +02:00
return jQuery ;
}
return null ;
} ;
2020-11-11 18:07:37 +01:00
var onDOMContentLoaded = function onDOMContentLoaded ( callback ) {
if ( document . readyState === 'loading' ) {
document . addEventListener ( 'DOMContentLoaded' , callback ) ;
} else {
callback ( ) ;
}
} ;
2020-12-03 14:08:31 +01:00
var isRTL = document . documentElement . dir === 'rtl' ;
2021-02-10 17:14:51 +01:00
var defineJQueryPlugin = function defineJQueryPlugin ( name , plugin ) {
onDOMContentLoaded ( function ( ) {
var $ = getjQuery ( ) ;
/* istanbul ignore if */
2020-12-03 15:18:59 +01:00
2021-02-10 17:14:51 +01:00
if ( $ ) {
var JQUERY _NO _CONFLICT = $ . fn [ name ] ;
$ . fn [ name ] = plugin . jQueryInterface ;
$ . fn [ name ] . Constructor = plugin ;
2020-12-03 15:18:59 +01:00
2021-02-10 17:14:51 +01:00
$ . fn [ name ] . noConflict = function ( ) {
$ . fn [ name ] = JQUERY _NO _CONFLICT ;
return plugin . jQueryInterface ;
} ;
2020-12-03 15:18:59 +01:00
}
2021-02-10 17:14:51 +01:00
} ) ;
} ;
2020-12-03 15:18:59 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Constants
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
var NAME = 'dropdown' ;
2018-11-13 07:41:12 +01:00
var DATA _KEY = 'bs.dropdown' ;
var EVENT _KEY = "." + DATA _KEY ;
var DATA _API _KEY = '.data-api' ;
2020-05-13 20:53:43 +02:00
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 ) ;
2020-03-28 11:29:08 +01:00
var EVENT _HIDE = "hide" + EVENT _KEY ;
var EVENT _HIDDEN = "hidden" + EVENT _KEY ;
var EVENT _SHOW = "show" + EVENT _KEY ;
var EVENT _SHOWN = "shown" + EVENT _KEY ;
var EVENT _CLICK = "click" + EVENT _KEY ;
var EVENT _CLICK _DATA _API = "click" + EVENT _KEY + DATA _API _KEY ;
var EVENT _KEYDOWN _DATA _API = "keydown" + EVENT _KEY + DATA _API _KEY ;
var EVENT _KEYUP _DATA _API = "keyup" + EVENT _KEY + DATA _API _KEY ;
var CLASS _NAME _DISABLED = 'disabled' ;
var CLASS _NAME _SHOW = 'show' ;
var CLASS _NAME _DROPUP = 'dropup' ;
2020-12-03 14:08:31 +01:00
var CLASS _NAME _DROPEND = 'dropend' ;
var CLASS _NAME _DROPSTART = 'dropstart' ;
2020-03-28 11:29:08 +01:00
var CLASS _NAME _NAVBAR = 'navbar' ;
2020-11-23 14:17:16 +01:00
var SELECTOR _DATA _TOGGLE = '[data-bs-toggle="dropdown"]' ;
2020-03-28 11:29:08 +01:00
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)' ;
2020-12-03 14:08:31 +01:00
var PLACEMENT _TOP = isRTL ? 'top-end' : 'top-start' ;
var PLACEMENT _TOPEND = isRTL ? 'top-start' : 'top-end' ;
var PLACEMENT _BOTTOM = isRTL ? 'bottom-end' : 'bottom-start' ;
var PLACEMENT _BOTTOMEND = isRTL ? 'bottom-start' : 'bottom-end' ;
var PLACEMENT _RIGHT = isRTL ? 'left-start' : 'right-start' ;
var PLACEMENT _LEFT = isRTL ? 'right-start' : 'left-start' ;
2018-11-13 07:41:12 +01:00
var Default = {
2021-02-10 17:14:51 +01:00
offset : [ 0 , 2 ] ,
2018-11-13 07:41:12 +01:00
flip : true ,
2020-12-07 16:50:24 +01:00
boundary : 'clippingParents' ,
2018-11-13 07:41:12 +01:00
reference : 'toggle' ,
2019-08-27 15:03:21 +02:00
display : 'dynamic' ,
popperConfig : null
2018-11-13 07:41:12 +01:00
} ;
var DefaultType = {
2021-02-10 17:14:51 +01:00
offset : '(array|string|function)' ,
2018-11-13 07:41:12 +01:00
flip : 'boolean' ,
boundary : '(string|element)' ,
2021-02-10 17:14:51 +01:00
reference : '(string|element|object)' ,
2019-08-27 15:03:21 +02:00
display : 'string' ,
2021-02-10 17:14:51 +01:00
popperConfig : '(null|object|function)'
2018-11-13 07:41:12 +01:00
} ;
2019-10-08 08:39:10 +02:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Class Definition
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2015-05-13 21:48:34 +02:00
2020-12-03 15:18:59 +01:00
var Dropdown = /*#__PURE__*/ function ( _BaseComponent ) {
_inheritsLoose ( Dropdown , _BaseComponent ) ;
2018-11-13 07:41:12 +01:00
function Dropdown ( element , config ) {
2020-12-03 15:18:59 +01:00
var _this ;
_this = _BaseComponent . call ( this , element ) || this ;
_this . _popper = null ;
_this . _config = _this . _getConfig ( config ) ;
_this . _menu = _this . _getMenuElement ( ) ;
_this . _inNavbar = _this . _detectNavbar ( ) ;
2015-05-10 22:47:11 +02:00
2020-12-03 15:18:59 +01:00
_this . _addEventListeners ( ) ;
2019-03-01 17:31:34 +01:00
2020-12-03 15:18:59 +01:00
return _this ;
2018-11-13 07:41:12 +01:00
} // Getters
2015-08-13 06:12:03 +02:00
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
var _proto = Dropdown . prototype ;
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
// Public
_proto . toggle = function toggle ( ) {
2020-03-28 11:29:08 +01:00
if ( this . _element . disabled || this . _element . classList . contains ( CLASS _NAME _DISABLED ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2015-05-10 22:47:11 +02:00
2020-03-28 11:29:08 +01:00
var isActive = this . _element . classList . contains ( CLASS _NAME _SHOW ) ;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . clearMenus ( ) ;
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
if ( isActive ) {
return ;
}
2017-10-30 00:19:14 +01:00
2019-08-27 15:03:21 +02:00
this . show ( ) ;
} ;
_proto . show = function show ( ) {
2020-03-28 11:29:08 +01:00
if ( this . _element . disabled || this . _element . classList . contains ( CLASS _NAME _DISABLED ) || this . _menu . classList . contains ( CLASS _NAME _SHOW ) ) {
2019-08-27 15:03:21 +02:00
return ;
}
var parent = Dropdown . getParentFromElement ( this . _element ) ;
2018-11-13 07:41:12 +01:00
var relatedTarget = {
relatedTarget : this . _element
} ;
2020-09-14 17:12:06 +02:00
var showEvent = EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _SHOW , relatedTarget ) ;
2017-10-30 00:19:14 +01:00
2019-03-01 17:31:34 +01:00
if ( showEvent . defaultPrevented ) {
2018-11-13 07:41:12 +01:00
return ;
2020-11-23 14:17:16 +01:00
} // Totally disable Popper for Dropdowns in Navbar
2017-09-06 06:05:12 +02:00
2017-03-20 03:03:32 +01:00
2021-02-10 17:14:51 +01:00
if ( this . _inNavbar ) {
Manipulator _ _default [ 'default' ] . setDataAttribute ( this . _menu , 'popper' , 'none' ) ;
} else {
2020-12-07 16:50:24 +01:00
if ( typeof Popper _ _namespace === 'undefined' ) {
2020-11-23 14:17:16 +01:00
throw new TypeError ( 'Bootstrap\'s dropdowns require Popper (https://popper.js.org)' ) ;
2018-11-13 07:41:12 +01:00
}
2018-02-11 23:53:29 +01:00
2018-11-13 07:41:12 +01:00
var referenceElement = this . _element ;
2017-12-23 01:21:54 +01:00
2018-11-13 07:41:12 +01:00
if ( this . _config . reference === 'parent' ) {
referenceElement = parent ;
2019-03-01 17:31:34 +01:00
} else if ( isElement ( this . _config . reference ) ) {
2018-11-13 07:41:12 +01:00
referenceElement = this . _config . reference ; // Check if it's jQuery element
2017-12-23 01:21:54 +01:00
2018-11-13 07:41:12 +01:00
if ( typeof this . _config . reference . jquery !== 'undefined' ) {
referenceElement = this . _config . reference [ 0 ] ;
2018-07-24 02:51:14 +02:00
}
2021-02-10 17:14:51 +01:00
} else if ( typeof this . _config . reference === 'object' ) {
referenceElement = this . _config . reference ;
2018-07-24 02:51:14 +02:00
}
2017-09-30 23:28:03 +02:00
2021-02-10 17:14:51 +01:00
var popperConfig = this . _getPopperConfig ( ) ;
var isDisplayStatic = popperConfig . modifiers . find ( function ( modifier ) {
return modifier . name === 'applyStyles' && modifier . enabled === false ;
} ) ;
this . _popper = Popper . createPopper ( referenceElement , this . _menu , popperConfig ) ;
if ( isDisplayStatic ) {
Manipulator _ _default [ 'default' ] . setDataAttribute ( this . _menu , 'popper' , 'static' ) ;
}
2018-11-13 07:41:12 +01:00
} // 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
2017-09-30 23:28:03 +02:00
2020-05-13 20:53:43 +02:00
if ( 'ontouchstart' in document . documentElement && ! parent . closest ( SELECTOR _NAVBAR _NAV ) ) {
2020-03-28 11:29:08 +01:00
var _ref ;
( _ref = [ ] ) . concat . apply ( _ref , document . body . children ) . forEach ( function ( elem ) {
2020-09-14 17:12:06 +02:00
return EventHandler _ _default [ 'default' ] . on ( elem , 'mouseover' , null , noop ( ) ) ;
2019-03-01 17:31:34 +01:00
} ) ;
2018-11-13 07:41:12 +01:00
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
this . _element . focus ( ) ;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
this . _element . setAttribute ( 'aria-expanded' , true ) ;
2015-05-13 21:48:34 +02:00
2020-10-28 04:45:48 +01:00
this . _menu . classList . toggle ( CLASS _NAME _SHOW ) ;
this . _element . classList . toggle ( CLASS _NAME _SHOW ) ;
2021-02-10 17:14:51 +01:00
EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _SHOWN , relatedTarget ) ;
2018-11-13 07:41:12 +01:00
} ;
_proto . hide = function hide ( ) {
2020-03-28 11:29:08 +01:00
if ( this . _element . disabled || this . _element . classList . contains ( CLASS _NAME _DISABLED ) || ! this . _menu . classList . contains ( CLASS _NAME _SHOW ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
var relatedTarget = {
relatedTarget : this . _element
2018-07-24 02:51:14 +02:00
} ;
2021-02-10 17:14:51 +01:00
var hideEvent = EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _HIDE , relatedTarget ) ;
2017-05-16 09:59:44 +02:00
2019-03-01 17:31:34 +01:00
if ( hideEvent . defaultPrevented ) {
2018-11-13 07:41:12 +01:00
return ;
}
2017-09-30 23:28:03 +02:00
2019-08-27 15:03:21 +02:00
if ( this . _popper ) {
this . _popper . destroy ( ) ;
}
2020-10-28 04:45:48 +01:00
this . _menu . classList . toggle ( CLASS _NAME _SHOW ) ;
this . _element . classList . toggle ( CLASS _NAME _SHOW ) ;
2021-02-10 17:14:51 +01:00
Manipulator _ _default [ 'default' ] . removeDataAttribute ( this . _menu , 'popper' ) ;
EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _HIDDEN , relatedTarget ) ;
2018-11-13 07:41:12 +01:00
} ;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
_proto . dispose = function dispose ( ) {
2020-12-03 15:18:59 +01:00
_BaseComponent . prototype . dispose . call ( this ) ;
2020-09-14 17:12:06 +02:00
EventHandler _ _default [ 'default' ] . off ( this . _element , EVENT _KEY ) ;
2018-11-13 07:41:12 +01:00
this . _menu = null ;
2017-09-30 23:28:03 +02:00
2019-08-27 15:03:21 +02:00
if ( this . _popper ) {
2018-11-13 07:41:12 +01:00
this . _popper . destroy ( ) ;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
this . _popper = null ;
}
} ;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
_proto . update = function update ( ) {
this . _inNavbar = this . _detectNavbar ( ) ;
2017-09-30 23:28:03 +02:00
2019-08-27 15:03:21 +02:00
if ( this . _popper ) {
2020-12-07 16:50:24 +01:00
this . _popper . update ( ) ;
2018-11-13 07:41:12 +01:00
}
2019-01-04 17:29:45 +01:00
} // Private
;
2017-10-16 00:51:44 +02:00
2018-11-13 07:41:12 +01:00
_proto . _addEventListeners = function _addEventListeners ( ) {
2020-12-03 15:18:59 +01:00
var _this2 = this ;
2017-10-16 00:51:44 +02:00
2020-09-14 17:12:06 +02:00
EventHandler _ _default [ 'default' ] . on ( this . _element , EVENT _CLICK , function ( event ) {
2018-11-13 07:41:12 +01:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2020-12-03 15:18:59 +01:00
_this2 . toggle ( ) ;
2018-11-13 07:41:12 +01:00
} ) ;
} ;
2018-02-19 23:50:56 +01:00
2018-11-13 07:41:12 +01:00
_proto . _getConfig = function _getConfig ( config ) {
2020-09-14 17:12:06 +02:00
config = _extends ( { } , this . constructor . Default , Manipulator _ _default [ 'default' ] . getDataAttributes ( this . _element ) , config ) ;
2019-03-01 17:31:34 +01:00
typeCheckConfig ( NAME , config , this . constructor . DefaultType ) ;
2021-02-10 17:14:51 +01:00
if ( typeof config . reference === 'object' && ! isElement ( config . reference ) && typeof config . reference . getBoundingClientRect !== 'function' ) {
// Popper virtual elements require a getBoundingClientRect method
throw new TypeError ( NAME . toUpperCase ( ) + ": Option \"reference\" provided type \"object\" without a required \"getBoundingClientRect\" method." ) ;
}
2018-11-13 07:41:12 +01:00
return config ;
} ;
2018-02-19 23:50:56 +01:00
2018-11-13 07:41:12 +01:00
_proto . _getMenuElement = function _getMenuElement ( ) {
2020-09-14 17:12:06 +02:00
return SelectorEngine _ _default [ 'default' ] . next ( this . _element , SELECTOR _MENU ) [ 0 ] ;
2018-11-13 07:41:12 +01:00
} ;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
_proto . _getPlacement = function _getPlacement ( ) {
2019-03-01 17:31:34 +01:00
var parentDropdown = this . _element . parentNode ;
2017-09-30 23:28:03 +02:00
2020-12-07 16:50:24 +01:00
if ( parentDropdown . classList . contains ( CLASS _NAME _DROPEND ) ) {
return PLACEMENT _RIGHT ;
2018-11-13 07:41:12 +01:00
}
2018-07-24 02:51:14 +02:00
2020-12-07 16:50:24 +01:00
if ( parentDropdown . classList . contains ( CLASS _NAME _DROPSTART ) ) {
return PLACEMENT _LEFT ;
} // We need to trim the value because custom properties can also include spaces
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
2020-12-07 16:50:24 +01:00
var isEnd = getComputedStyle ( this . _menu ) . getPropertyValue ( '--bs-position' ) . trim ( ) === 'end' ;
2018-11-13 07:41:12 +01:00
2020-12-07 16:50:24 +01:00
if ( parentDropdown . classList . contains ( CLASS _NAME _DROPUP ) ) {
return isEnd ? PLACEMENT _TOPEND : PLACEMENT _TOP ;
2018-11-13 07:41:12 +01:00
}
2018-07-24 02:51:14 +02:00
2020-12-07 16:50:24 +01:00
return isEnd ? PLACEMENT _BOTTOMEND : PLACEMENT _BOTTOM ;
} ;
_proto . _detectNavbar = function _detectNavbar ( ) {
return this . _element . closest ( "." + CLASS _NAME _NAVBAR ) !== null ;
2019-02-11 20:15:34 +01:00
} ;
2021-02-10 17:14:51 +01:00
_proto . _getOffset = function _getOffset ( ) {
var _this3 = this ;
var offset = this . _config . offset ;
if ( typeof offset === 'string' ) {
return offset . split ( ',' ) . map ( function ( val ) {
return Number . parseInt ( val , 10 ) ;
} ) ;
}
if ( typeof offset === 'function' ) {
return function ( popperData ) {
return offset ( popperData , _this3 . _element ) ;
} ;
}
return offset ;
} ;
2019-02-11 20:15:34 +01:00
_proto . _getPopperConfig = function _getPopperConfig ( ) {
2021-02-10 17:14:51 +01:00
var defaultBsPopperConfig = {
2018-11-13 07:41:12 +01:00
placement : this . _getPlacement ( ) ,
2020-12-07 16:50:24 +01:00
modifiers : [ {
name : 'preventOverflow' ,
options : {
altBoundary : this . _config . flip ,
2021-02-10 17:14:51 +01:00
boundary : this . _config . boundary
}
} , {
name : 'offset' ,
options : {
offset : this . _getOffset ( )
2017-09-06 06:05:12 +02:00
}
2020-12-07 16:50:24 +01:00
} ]
2020-11-23 14:17:16 +01:00
} ; // Disable Popper if we have a static display
2017-06-18 09:14:35 +02:00
2018-11-13 07:41:12 +01:00
if ( this . _config . display === 'static' ) {
2021-02-10 17:14:51 +01:00
defaultBsPopperConfig . modifiers = [ {
2020-12-07 16:50:24 +01:00
name : 'applyStyles' ,
2018-11-13 07:41:12 +01:00
enabled : false
2020-12-07 16:50:24 +01:00
} ] ;
2018-11-13 07:41:12 +01:00
}
2017-09-30 23:28:03 +02:00
2021-02-10 17:14:51 +01:00
return _extends ( { } , defaultBsPopperConfig , typeof this . _config . popperConfig === 'function' ? this . _config . popperConfig ( defaultBsPopperConfig ) : this . _config . popperConfig ) ;
2019-01-04 17:29:45 +01:00
} // Static
;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . dropdownInterface = function dropdownInterface ( element , config ) {
2020-09-14 17:12:06 +02:00
var data = Data _ _default [ 'default' ] . getData ( element , DATA _KEY ) ;
2015-05-10 22:47:11 +02:00
2019-03-01 17:31:34 +01:00
var _config = typeof config === 'object' ? config : null ;
2015-05-10 22:47:11 +02:00
2019-03-01 17:31:34 +01:00
if ( ! data ) {
data = new Dropdown ( element , _config ) ;
}
if ( typeof config === 'string' ) {
if ( typeof data [ config ] === 'undefined' ) {
2019-03-11 16:13:30 +01:00
throw new TypeError ( "No method named \"" + config + "\"" ) ;
2018-11-13 07:41:12 +01:00
}
2017-05-16 09:59:44 +02:00
2019-03-01 17:31:34 +01:00
data [ config ] ( ) ;
}
} ;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . jQueryInterface = function jQueryInterface ( config ) {
2019-03-01 17:31:34 +01:00
return this . each ( function ( ) {
2019-08-27 15:03:21 +02:00
Dropdown . dropdownInterface ( this , config ) ;
2018-11-13 07:41:12 +01:00
} ) ;
} ;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . clearMenus = function clearMenus ( event ) {
2020-05-13 20:53:43 +02:00
if ( event && ( event . button === RIGHT _MOUSE _BUTTON || event . type === 'keyup' && event . key !== TAB _KEY ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2016-10-10 02:26:51 +02:00
2020-09-14 17:12:06 +02:00
var toggles = SelectorEngine _ _default [ 'default' ] . find ( SELECTOR _DATA _TOGGLE ) ;
2017-03-20 03:03:32 +01:00
2018-11-13 07:41:12 +01:00
for ( var i = 0 , len = toggles . length ; i < len ; i ++ ) {
2020-09-14 17:12:06 +02:00
var context = Data _ _default [ 'default' ] . getData ( toggles [ i ] , DATA _KEY ) ;
2018-11-13 07:41:12 +01:00
var relatedTarget = {
relatedTarget : toggles [ i ]
} ;
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
if ( event && event . type === 'click' ) {
relatedTarget . clickEvent = event ;
2017-09-06 06:05:12 +02:00
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if ( ! context ) {
continue ;
2018-07-24 02:51:14 +02:00
}
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
var dropdownMenu = context . _menu ;
2017-09-06 06:05:12 +02:00
2020-03-28 11:29:08 +01:00
if ( ! toggles [ i ] . classList . contains ( CLASS _NAME _SHOW ) ) {
2018-11-13 07:41:12 +01:00
continue ;
}
2017-12-31 04:41:36 +01:00
2020-05-13 20:53:43 +02:00
if ( event && ( event . type === 'click' && /input|textarea/i . test ( event . target . tagName ) || event . type === 'keyup' && event . key === TAB _KEY ) && dropdownMenu . contains ( event . target ) ) {
2018-11-13 07:41:12 +01:00
continue ;
2018-07-24 02:51:14 +02:00
}
2015-05-10 22:47:11 +02:00
2021-02-10 17:14:51 +01:00
var hideEvent = EventHandler _ _default [ 'default' ] . trigger ( toggles [ i ] , EVENT _HIDE , relatedTarget ) ;
2018-11-13 07:41:12 +01:00
2019-03-01 17:31:34 +01:00
if ( hideEvent . defaultPrevented ) {
2018-11-13 07:41:12 +01:00
continue ;
} // If this is a touch-enabled device we remove the extra
// empty mouseover listeners we added for iOS support
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
if ( 'ontouchstart' in document . documentElement ) {
2020-03-28 11:29:08 +01:00
var _ref2 ;
( _ref2 = [ ] ) . concat . apply ( _ref2 , document . body . children ) . forEach ( function ( elem ) {
2020-09-14 17:12:06 +02:00
return EventHandler _ _default [ 'default' ] . off ( elem , 'mouseover' , null , noop ( ) ) ;
2019-03-01 17:31:34 +01:00
} ) ;
2018-07-24 02:51:14 +02:00
}
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
toggles [ i ] . setAttribute ( 'aria-expanded' , 'false' ) ;
2019-08-27 15:03:21 +02:00
if ( context . _popper ) {
context . _popper . destroy ( ) ;
}
2020-03-28 11:29:08 +01:00
dropdownMenu . classList . remove ( CLASS _NAME _SHOW ) ;
toggles [ i ] . classList . remove ( CLASS _NAME _SHOW ) ;
2021-02-10 17:14:51 +01:00
Manipulator _ _default [ 'default' ] . removeDataAttribute ( dropdownMenu , 'popper' ) ;
EventHandler _ _default [ 'default' ] . trigger ( toggles [ i ] , EVENT _HIDDEN , relatedTarget ) ;
2018-11-13 07:41:12 +01:00
}
} ;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . getParentFromElement = function getParentFromElement ( element ) {
return getElementFromSelector ( element ) || element . parentNode ;
2019-03-01 17:31:34 +01:00
} ;
2015-05-10 22:47:11 +02:00
2019-08-27 15:03:21 +02:00
Dropdown . dataApiKeydownHandler = function dataApiKeydownHandler ( event ) {
2018-11-13 07:41:12 +01:00
// 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
2020-05-13 20:53:43 +02:00
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 ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2015-05-10 22:47:11 +02:00
2020-03-28 11:29:08 +01:00
if ( this . disabled || this . classList . contains ( CLASS _NAME _DISABLED ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2015-08-19 05:28:28 +02:00
2019-08-27 15:03:21 +02:00
var parent = Dropdown . getParentFromElement ( this ) ;
2020-03-28 11:29:08 +01:00
var isActive = this . classList . contains ( CLASS _NAME _SHOW ) ;
2015-08-19 05:28:28 +02:00
2020-05-13 20:53:43 +02:00
if ( event . key === ESCAPE _KEY ) {
2020-09-14 17:12:06 +02:00
var button = this . matches ( SELECTOR _DATA _TOGGLE ) ? this : SelectorEngine _ _default [ 'default' ] . prev ( this , SELECTOR _DATA _TOGGLE ) [ 0 ] ;
2020-03-28 11:29:08 +01:00
button . focus ( ) ;
Dropdown . clearMenus ( ) ;
return ;
}
2015-05-10 22:47:11 +02:00
2021-02-10 17:14:51 +01:00
if ( ! isActive && ( event . key === ARROW _UP _KEY || event . key === ARROW _DOWN _KEY ) ) {
var _button = this . matches ( SELECTOR _DATA _TOGGLE ) ? this : SelectorEngine _ _default [ 'default' ] . prev ( this , SELECTOR _DATA _TOGGLE ) [ 0 ] ;
_button . click ( ) ;
return ;
}
2020-05-13 20:53:43 +02:00
if ( ! isActive || event . key === SPACE _KEY ) {
2019-08-27 15:03:21 +02:00
Dropdown . clearMenus ( ) ;
2018-11-13 07:41:12 +01:00
return ;
}
2017-09-30 23:28:03 +02:00
2020-09-14 17:12:06 +02:00
var items = SelectorEngine _ _default [ 'default' ] . find ( SELECTOR _VISIBLE _ITEMS , parent ) . filter ( isVisible ) ;
2017-09-30 23:28:03 +02:00
2019-03-01 17:31:34 +01:00
if ( ! items . length ) {
2018-11-13 07:41:12 +01:00
return ;
}
2015-05-10 22:47:11 +02:00
2020-12-03 15:18:59 +01:00
var index = items . indexOf ( event . target ) ; // Up
2015-05-10 22:47:11 +02:00
2020-05-13 20:53:43 +02:00
if ( event . key === ARROW _UP _KEY && index > 0 ) {
2018-11-13 07:41:12 +01:00
index -- ;
2020-12-03 15:18:59 +01:00
} // Down
2017-09-30 23:28:03 +02:00
2020-05-13 20:53:43 +02:00
if ( event . key === ARROW _DOWN _KEY && index < items . length - 1 ) {
2018-11-13 07:41:12 +01:00
index ++ ;
2020-05-13 20:53:43 +02:00
} // index is -1 if the first keydown is an ArrowUp
2017-09-30 23:28:03 +02:00
2020-05-13 20:53:43 +02:00
index = index === - 1 ? 0 : index ;
2018-11-13 07:41:12 +01:00
items [ index ] . focus ( ) ;
2018-07-24 02:51:14 +02:00
} ;
2017-09-30 23:28:03 +02:00
2021-02-10 17:14:51 +01:00
_createClass ( Dropdown , null , [ {
2018-11-13 07:41:12 +01:00
key : "Default" ,
get : function get ( ) {
return Default ;
}
} , {
key : "DefaultType" ,
get : function get ( ) {
return DefaultType ;
}
2020-12-03 15:18:59 +01:00
} , {
key : "DATA_KEY" ,
get : function get ( ) {
return DATA _KEY ;
}
2018-11-13 07:41:12 +01:00
} ] ) ;
2018-07-24 02:51:14 +02:00
return Dropdown ;
2021-02-10 17:14:51 +01:00
} ( BaseComponent _ _default [ 'default' ] ) ;
2018-11-13 07:41:12 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Data Api implementation
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2020-09-14 17:12:06 +02:00
EventHandler _ _default [ 'default' ] . on ( document , EVENT _KEYDOWN _DATA _API , SELECTOR _DATA _TOGGLE , Dropdown . dataApiKeydownHandler ) ;
EventHandler _ _default [ 'default' ] . on ( document , EVENT _KEYDOWN _DATA _API , SELECTOR _MENU , Dropdown . dataApiKeydownHandler ) ;
EventHandler _ _default [ 'default' ] . on ( document , EVENT _CLICK _DATA _API , Dropdown . clearMenus ) ;
EventHandler _ _default [ 'default' ] . on ( document , EVENT _KEYUP _DATA _API , Dropdown . clearMenus ) ;
EventHandler _ _default [ 'default' ] . on ( document , EVENT _CLICK _DATA _API , SELECTOR _DATA _TOGGLE , function ( event ) {
2018-11-13 07:41:12 +01:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2019-08-27 15:03:21 +02:00
Dropdown . dropdownInterface ( this , 'toggle' ) ;
2019-03-01 17:31:34 +01:00
} ) ;
2020-09-14 17:12:06 +02:00
EventHandler _ _default [ 'default' ] . on ( document , EVENT _CLICK _DATA _API , SELECTOR _FORM _CHILD , function ( e ) {
2019-03-01 17:31:34 +01:00
return e . stopPropagation ( ) ;
2018-11-13 07:41:12 +01:00
} ) ;
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* jQuery
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2020-11-11 18:07:37 +01:00
* add . Dropdown to jQuery only if jQuery is present
2018-11-13 07:41:12 +01:00
* /
2021-02-10 17:14:51 +01:00
defineJQueryPlugin ( NAME , Dropdown ) ;
2015-05-10 22:47:11 +02:00
return Dropdown ;
2018-07-24 02:51:14 +02:00
2019-11-08 09:11:23 +01:00
} ) ) ) ;
2018-07-24 02:51:14 +02:00
//# sourceMappingURL=dropdown.js.map