2018-11-13 07:41:12 +01:00
/ * !
2020-09-29 17:33:00 +02:00
* Bootstrap dropdown . js v5 . 0.0 - alpha2 ( https : //getbootstrap.com/)
2020-03-28 11:29:08 +01:00
* Copyright 2011 - 2020 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 ) {
2019-10-08 08:39:10 +02:00
typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( require ( './dom/data.js' ) , require ( './dom/event-handler.js' ) , require ( './dom/manipulator.js' ) , require ( 'popper.js' ) , require ( './dom/selector-engine.js' ) ) :
typeof define === 'function' && define . amd ? define ( [ './dom/data.js' , './dom/event-handler.js' , './dom/manipulator.js' , 'popper.js' , './dom/selector-engine.js' ] , factory ) :
2020-09-14 17:12:06 +02:00
( global = typeof globalThis !== 'undefined' ? globalThis : global || self , global . Dropdown = factory ( global . Data , global . EventHandler , global . Manipulator , global . Popper , global . SelectorEngine ) ) ;
2019-11-08 09:11:23 +01:00
} ( this , ( function ( Data , EventHandler , Manipulator , Popper , SelectorEngine ) { '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 } ; }
var Data _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Data ) ;
var EventHandler _ _default = /*#__PURE__*/ _interopDefaultLegacy ( EventHandler ) ;
var Manipulator _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Manipulator ) ;
var Popper _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Popper ) ;
var SelectorEngine _ _default = /*#__PURE__*/ _interopDefaultLegacy ( SelectorEngine ) ;
2018-07-24 02:51:14 +02:00
2019-03-01 17:31:34 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2020-09-29 17:33:00 +02:00
* Bootstrap ( v5 . 0.0 - alpha2 ) : 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 ) {
2019-03-01 17:31:34 +01:00
var selector = element . getAttribute ( 'data-target' ) ;
if ( ! selector || selector === '#' ) {
var hrefAttr = element . getAttribute ( 'href' ) ;
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 ) ) {
throw new Error ( componentName . toUpperCase ( ) + ": " + ( "Option \"" + property + "\" provided type \"" + valueType + "\" " ) + ( "but expected type \"" + expectedTypes + "\"." ) ) ;
}
} ) ;
} ;
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 ;
if ( jQuery && ! document . body . hasAttribute ( 'data-no-jquery' ) ) {
return jQuery ;
}
return null ;
} ;
2020-09-14 17:12:06 +02:00
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 ) ; }
2020-06-14 00:40:28 +02:00
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 ; }
2018-11-13 07:41:12 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Constants
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
var NAME = 'dropdown' ;
2020-09-29 17:33:00 +02:00
var VERSION = '5.0.0-alpha2' ;
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' ;
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 = '[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' ;
2018-11-13 07:41:12 +01:00
var Default = {
offset : 0 ,
flip : true ,
boundary : 'scrollParent' ,
reference : 'toggle' ,
2019-08-27 15:03:21 +02:00
display : 'dynamic' ,
popperConfig : null
2018-11-13 07:41:12 +01:00
} ;
var DefaultType = {
offset : '(number|string|function)' ,
flip : 'boolean' ,
boundary : '(string|element)' ,
reference : '(string|element)' ,
2019-08-27 15:03:21 +02:00
display : 'string' ,
popperConfig : '(null|object)'
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-03-28 11:29:08 +01:00
var Dropdown = /*#__PURE__*/ function ( ) {
2018-11-13 07:41:12 +01:00
function Dropdown ( element , config ) {
this . _element = element ;
this . _popper = null ;
this . _config = this . _getConfig ( config ) ;
this . _menu = this . _getMenuElement ( ) ;
this . _inNavbar = this . _detectNavbar ( ) ;
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
this . _addEventListeners ( ) ;
2019-03-01 17:31:34 +01:00
2020-09-14 17:12:06 +02:00
Data _ _default [ 'default' ] . setData ( element , DATA _KEY , 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 ;
} // Disable totally Popper.js for Dropdown in Navbar
2017-09-06 06:05:12 +02:00
2017-03-20 03:03:32 +01:00
2018-11-13 07:41:12 +01:00
if ( ! this . _inNavbar ) {
2020-09-14 17:12:06 +02:00
if ( typeof Popper _ _default [ 'default' ] === 'undefined' ) {
2019-03-01 17:31:34 +01:00
throw new TypeError ( 'Bootstrap\'s dropdowns require Popper.js (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
}
2018-11-13 07:41:12 +01:00
} // 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
2015-05-10 22:47:11 +02:00
2017-10-30 20:48:13 +01:00
2018-11-13 07:41:12 +01:00
if ( this . _config . boundary !== 'scrollParent' ) {
2020-03-28 11:29:08 +01:00
parent . classList . add ( CLASS _NAME _POSITION _STATIC ) ;
2018-07-24 02:51:14 +02:00
}
2017-09-30 23:28:03 +02:00
2020-09-14 17:12:06 +02:00
this . _popper = new Popper _ _default [ 'default' ] ( referenceElement , this . _menu , this . _getPopperConfig ( ) ) ;
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-09-14 17:12:06 +02:00
Manipulator _ _default [ 'default' ] . toggleClass ( this . _menu , CLASS _NAME _SHOW ) ;
Manipulator _ _default [ 'default' ] . toggleClass ( this . _element , CLASS _NAME _SHOW ) ;
EventHandler _ _default [ 'default' ] . trigger ( parent , 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
2019-08-27 15:03:21 +02:00
var parent = Dropdown . getParentFromElement ( this . _element ) ;
2018-11-13 07:41:12 +01:00
var relatedTarget = {
relatedTarget : this . _element
2018-07-24 02:51:14 +02:00
} ;
2020-09-14 17:12:06 +02:00
var hideEvent = EventHandler _ _default [ 'default' ] . trigger ( parent , 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-09-14 17:12:06 +02:00
Manipulator _ _default [ 'default' ] . toggleClass ( this . _menu , CLASS _NAME _SHOW ) ;
Manipulator _ _default [ 'default' ] . toggleClass ( this . _element , CLASS _NAME _SHOW ) ;
EventHandler _ _default [ 'default' ] . trigger ( parent , 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-09-14 17:12:06 +02:00
Data _ _default [ 'default' ] . removeData ( this . _element , DATA _KEY ) ;
EventHandler _ _default [ 'default' ] . off ( this . _element , EVENT _KEY ) ;
2018-11-13 07:41:12 +01:00
this . _element = null ;
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 ) {
2018-11-13 07:41:12 +01:00
this . _popper . scheduleUpdate ( ) ;
}
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 ( ) {
var _this = 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 ( ) ;
_this . toggle ( ) ;
} ) ;
} ;
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 ) ;
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 ;
2020-03-28 11:29:08 +01:00
var placement = PLACEMENT _BOTTOM ; // Handle dropup
2017-09-30 23:28:03 +02:00
2020-03-28 11:29:08 +01:00
if ( parentDropdown . classList . contains ( CLASS _NAME _DROPUP ) ) {
placement = PLACEMENT _TOP ;
2017-09-30 23:28:03 +02:00
2020-03-28 11:29:08 +01:00
if ( this . _menu . classList . contains ( CLASS _NAME _MENURIGHT ) ) {
placement = PLACEMENT _TOPEND ;
2018-11-13 07:41:12 +01:00
}
2020-03-28 11:29:08 +01:00
} 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 ;
2018-11-13 07:41:12 +01:00
}
2018-07-24 02:51:14 +02:00
2018-11-13 07:41:12 +01:00
return placement ;
} ;
_proto . _detectNavbar = function _detectNavbar ( ) {
2020-05-13 20:53:43 +02:00
return Boolean ( this . _element . closest ( "." + CLASS _NAME _NAVBAR ) ) ;
2018-11-13 07:41:12 +01:00
} ;
2017-09-30 23:28:03 +02:00
2019-02-11 20:15:34 +01:00
_proto . _getOffset = function _getOffset ( ) {
2018-11-13 07:41:12 +01:00
var _this2 = this ;
2019-02-11 20:15:34 +01:00
var offset = { } ;
2018-11-13 07:41:12 +01:00
if ( typeof this . _config . offset === 'function' ) {
2019-02-11 20:15:34 +01:00
offset . fn = function ( data ) {
2020-09-14 17:12:06 +02:00
data . offsets = _extends ( { } , data . offsets , _this2 . _config . offset ( data . offsets , _this2 . _element ) || { } ) ;
2018-11-13 07:41:12 +01:00
return data ;
} ;
} else {
2019-02-11 20:15:34 +01:00
offset . offset = this . _config . offset ;
2018-11-13 07:41:12 +01:00
}
2018-07-24 02:51:14 +02:00
2019-02-11 20:15:34 +01:00
return offset ;
} ;
_proto . _getPopperConfig = function _getPopperConfig ( ) {
2018-11-13 07:41:12 +01:00
var popperConfig = {
placement : this . _getPlacement ( ) ,
modifiers : {
2019-02-11 20:15:34 +01:00
offset : this . _getOffset ( ) ,
2018-11-13 07:41:12 +01:00
flip : {
enabled : this . _config . flip
} ,
preventOverflow : {
boundariesElement : this . _config . boundary
2017-09-06 06:05:12 +02:00
}
2019-10-08 08:39:10 +02:00
}
} ; // Disable Popper.js 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' ) {
popperConfig . modifiers . applyStyle = {
enabled : false
} ;
}
2017-09-30 23:28:03 +02:00
2020-09-14 17:12:06 +02:00
return _extends ( { } , popperConfig , 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 ++ ) {
2019-08-27 15:03:21 +02:00
var parent = Dropdown . getParentFromElement ( toggles [ 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
2020-09-14 17:12:06 +02:00
var hideEvent = EventHandler _ _default [ 'default' ] . trigger ( parent , 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 ) ;
2020-09-14 17:12:06 +02:00
EventHandler _ _default [ 'default' ] . trigger ( parent , 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
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-05-13 20:53:43 +02:00
var index = items . indexOf ( event . target ) ;
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
// Up
index -- ;
}
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
// Down
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
2019-08-27 15:03:21 +02:00
Dropdown . getInstance = function getInstance ( element ) {
2020-09-14 17:12:06 +02:00
return Data _ _default [ 'default' ] . getData ( element , DATA _KEY ) ;
2019-03-01 17:31:34 +01:00
} ;
2018-11-13 07:41:12 +01:00
_createClass ( Dropdown , null , [ {
key : "VERSION" ,
get : function get ( ) {
return VERSION ;
}
} , {
key : "Default" ,
get : function get ( ) {
return Default ;
}
} , {
key : "DefaultType" ,
get : function get ( ) {
return DefaultType ;
}
} ] ) ;
2018-07-24 02:51:14 +02:00
return Dropdown ;
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
} ) ;
2019-08-27 15:03:21 +02:00
var $ = getjQuery ( ) ;
2018-11-13 07:41:12 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* jQuery
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2019-03-01 17:31:34 +01:00
* add . dropdown to jQuery only if jQuery is present
2018-11-13 07:41:12 +01:00
* /
2019-07-24 08:13:50 +02:00
/* istanbul ignore if */
2019-08-27 15:03:21 +02:00
if ( $ ) {
var JQUERY _NO _CONFLICT = $ . fn [ NAME ] ;
$ . fn [ NAME ] = Dropdown . jQueryInterface ;
$ . fn [ NAME ] . Constructor = Dropdown ;
2018-11-13 07:41:12 +01:00
2019-08-27 15:03:21 +02:00
$ . fn [ NAME ] . noConflict = function ( ) {
$ . fn [ NAME ] = JQUERY _NO _CONFLICT ;
return Dropdown . jQueryInterface ;
2019-03-01 17:31:34 +01:00
} ;
}
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