2018-11-13 07:41:12 +01:00
/ * !
2019-02-13 17:01:40 +01:00
* Bootstrap dropdown . js v4 . 3.1 ( https : //getbootstrap.com/)
2019-01-04 17:29:45 +01:00
* Copyright 2011 - 2019 The Bootstrap Authors ( https : //github.com/twbs/bootstrap/graphs/contributors)
2018-11-13 07:41:12 +01:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/master/LICENSE)
* /
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 ) :
2019-03-01 17:31:34 +01:00
( global = 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
Data = Data && Data . hasOwnProperty ( 'default' ) ? Data [ 'default' ] : Data ;
EventHandler = EventHandler && EventHandler . hasOwnProperty ( 'default' ) ? EventHandler [ 'default' ] : EventHandler ;
Manipulator = Manipulator && Manipulator . hasOwnProperty ( 'default' ) ? Manipulator [ 'default' ] : Manipulator ;
2018-07-24 02:51:14 +02:00
Popper = Popper && Popper . hasOwnProperty ( 'default' ) ? Popper [ 'default' ] : Popper ;
2019-03-01 17:31:34 +01:00
SelectorEngine = SelectorEngine && SelectorEngine . hasOwnProperty ( 'default' ) ? SelectorEngine [ 'default' ] : SelectorEngine ;
2018-07-24 02:51:14 +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 ;
}
function _defineProperty ( obj , key , value ) {
if ( key in obj ) {
Object . defineProperty ( obj , key , {
value : value ,
enumerable : true ,
configurable : true ,
writable : true
} ) ;
} else {
obj [ key ] = value ;
}
return obj ;
}
2019-07-24 08:13:50 +02:00
function ownKeys ( object , enumerableOnly ) {
var keys = Object . keys ( object ) ;
if ( Object . getOwnPropertySymbols ) {
var symbols = Object . getOwnPropertySymbols ( object ) ;
if ( enumerableOnly ) symbols = symbols . filter ( function ( sym ) {
return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ;
} ) ;
keys . push . apply ( keys , symbols ) ;
}
return keys ;
}
function _objectSpread2 ( target ) {
2018-07-24 02:51:14 +02:00
for ( var i = 1 ; i < arguments . length ; i ++ ) {
var source = arguments [ i ] != null ? arguments [ i ] : { } ;
2019-07-24 08:13:50 +02:00
if ( i % 2 ) {
ownKeys ( source , true ) . forEach ( function ( key ) {
_defineProperty ( target , key , source [ key ] ) ;
} ) ;
} else if ( Object . getOwnPropertyDescriptors ) {
Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ;
} else {
ownKeys ( source ) . forEach ( function ( key ) {
Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ;
} ) ;
2018-07-24 02:51:14 +02:00
}
}
2017-09-06 06:05:12 +02:00
2018-07-24 02:51:14 +02:00
return target ;
}
2015-05-10 22:47:11 +02:00
2019-03-01 17:31:34 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Bootstrap ( v4 . 3.1 ) : util / index . js
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/master/LICENSE)
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
var toType = function toType ( obj ) {
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 + "\"." ) ) ;
}
} ) ;
} ;
var makeArray = function makeArray ( nodeList ) {
if ( ! nodeList ) {
return [ ] ;
}
return [ ] . slice . call ( nodeList ) ;
} ;
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 ;
} ;
2018-11-13 07:41:12 +01:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Constants
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
var NAME = 'dropdown' ;
2019-02-13 17:01:40 +01:00
var VERSION = '4.3.1' ;
2018-11-13 07:41:12 +01:00
var DATA _KEY = 'bs.dropdown' ;
var EVENT _KEY = "." + DATA _KEY ;
var DATA _API _KEY = '.data-api' ;
var ESCAPE _KEYCODE = 27 ; // KeyboardEvent.which value for Escape (Esc) key
var SPACE _KEYCODE = 32 ; // KeyboardEvent.which value for space key
var TAB _KEYCODE = 9 ; // KeyboardEvent.which value for tab key
var ARROW _UP _KEYCODE = 38 ; // KeyboardEvent.which value for up arrow key
var ARROW _DOWN _KEYCODE = 40 ; // KeyboardEvent.which value for down arrow key
var RIGHT _MOUSE _BUTTON _WHICH = 3 ; // MouseEvent.which value for the right button (assuming a right-handed mouse)
var REGEXP _KEYDOWN = new RegExp ( ARROW _UP _KEYCODE + "|" + ARROW _DOWN _KEYCODE + "|" + ESCAPE _KEYCODE ) ;
var Event = {
HIDE : "hide" + EVENT _KEY ,
HIDDEN : "hidden" + EVENT _KEY ,
SHOW : "show" + EVENT _KEY ,
SHOWN : "shown" + EVENT _KEY ,
CLICK : "click" + EVENT _KEY ,
CLICK _DATA _API : "click" + EVENT _KEY + DATA _API _KEY ,
KEYDOWN _DATA _API : "keydown" + EVENT _KEY + DATA _API _KEY ,
KEYUP _DATA _API : "keyup" + EVENT _KEY + DATA _API _KEY
} ;
var ClassName = {
DISABLED : 'disabled' ,
SHOW : 'show' ,
DROPUP : 'dropup' ,
DROPRIGHT : 'dropright' ,
DROPLEFT : 'dropleft' ,
MENURIGHT : 'dropdown-menu-right' ,
POSITION _STATIC : 'position-static'
} ;
var Selector = {
DATA _TOGGLE : '[data-toggle="dropdown"]' ,
FORM _CHILD : '.dropdown form' ,
MENU : '.dropdown-menu' ,
NAVBAR _NAV : '.navbar-nav' ,
VISIBLE _ITEMS : '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
} ;
var AttachmentMap = {
TOP : 'top-start' ,
TOPEND : 'top-end' ,
BOTTOM : 'bottom-start' ,
BOTTOMEND : 'bottom-end' ,
RIGHT : 'right-start' ,
RIGHTEND : 'right-end' ,
LEFT : 'left-start' ,
LEFTEND : 'left-end'
} ;
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
2018-11-13 07:41:12 +01:00
var Dropdown =
/*#__PURE__*/
function ( ) {
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
Data . 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 ( ) {
2019-03-01 17:31:34 +01:00
if ( this . _element . disabled || this . _element . classList . contains ( ClassName . DISABLED ) ) {
2018-11-13 07:41:12 +01:00
return ;
}
2015-05-10 22:47:11 +02:00
2019-03-01 17:31:34 +01:00
var isActive = this . _menu . classList . contains ( ClassName . 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 ( ) {
if ( this . _element . disabled || this . _element . classList . contains ( ClassName . DISABLED ) || this . _menu . classList . contains ( ClassName . SHOW ) ) {
return ;
}
var parent = Dropdown . getParentFromElement ( this . _element ) ;
2018-11-13 07:41:12 +01:00
var relatedTarget = {
relatedTarget : this . _element
} ;
2019-03-01 17:31:34 +01:00
var showEvent = EventHandler . trigger ( parent , 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 ) {
if ( typeof Popper === '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' ) {
2019-03-01 17:31:34 +01:00
parent . classList . add ( ClassName . POSITION _STATIC ) ;
2018-07-24 02:51:14 +02:00
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
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
2017-09-30 23:28:03 +02:00
2019-03-01 17:31:34 +01:00
if ( 'ontouchstart' in document . documentElement && ! makeArray ( SelectorEngine . closest ( parent , Selector . NAVBAR _NAV ) ) . length ) {
makeArray ( document . body . children ) . forEach ( function ( elem ) {
return EventHandler . on ( elem , 'mouseover' , null , noop ( ) ) ;
} ) ;
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
2019-03-01 17:31:34 +01:00
Manipulator . toggleClass ( this . _menu , ClassName . SHOW ) ;
Manipulator . toggleClass ( parent , ClassName . SHOW ) ;
EventHandler . trigger ( parent , Event . SHOWN , relatedTarget ) ;
2018-11-13 07:41:12 +01:00
} ;
_proto . hide = function hide ( ) {
2019-03-01 17:31:34 +01:00
if ( this . _element . disabled || this . _element . classList . contains ( ClassName . DISABLED ) || ! this . _menu . classList . contains ( ClassName . 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
} ;
2019-03-01 17:31:34 +01:00
var hideEvent = EventHandler . 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 ( ) ;
}
2019-03-01 17:31:34 +01:00
Manipulator . toggleClass ( this . _menu , ClassName . SHOW ) ;
Manipulator . toggleClass ( parent , ClassName . SHOW ) ;
EventHandler . 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 ( ) {
2019-03-01 17:31:34 +01:00
Data . removeData ( this . _element , DATA _KEY ) ;
EventHandler . 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
2019-03-01 17:31:34 +01:00
EventHandler . 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 ) {
2019-07-24 08:13:50 +02:00
config = _objectSpread2 ( { } , this . constructor . Default , { } , Manipulator . 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 ( ) {
2019-08-27 15:03:21 +02:00
var parent = Dropdown . getParentFromElement ( this . _element ) ;
2019-07-24 08:13:50 +02:00
return SelectorEngine . findOne ( Selector . MENU , parent ) ;
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 ;
2018-11-13 07:41:12 +01:00
var placement = AttachmentMap . BOTTOM ; // Handle dropup
2017-09-30 23:28:03 +02:00
2019-03-01 17:31:34 +01:00
if ( parentDropdown . classList . contains ( ClassName . DROPUP ) ) {
2018-11-13 07:41:12 +01:00
placement = AttachmentMap . TOP ;
2017-09-30 23:28:03 +02:00
2019-03-01 17:31:34 +01:00
if ( this . _menu . classList . contains ( ClassName . MENURIGHT ) ) {
2018-11-13 07:41:12 +01:00
placement = AttachmentMap . TOPEND ;
}
2019-03-01 17:31:34 +01:00
} else if ( parentDropdown . classList . contains ( ClassName . DROPRIGHT ) ) {
2018-11-13 07:41:12 +01:00
placement = AttachmentMap . RIGHT ;
2019-03-01 17:31:34 +01:00
} else if ( parentDropdown . classList . contains ( ClassName . DROPLEFT ) ) {
2018-11-13 07:41:12 +01:00
placement = AttachmentMap . LEFT ;
2019-03-01 17:31:34 +01:00
} else if ( this . _menu . classList . contains ( ClassName . MENURIGHT ) ) {
2018-11-13 07:41:12 +01:00
placement = AttachmentMap . BOTTOMEND ;
}
2018-07-24 02:51:14 +02:00
2018-11-13 07:41:12 +01:00
return placement ;
} ;
_proto . _detectNavbar = function _detectNavbar ( ) {
2019-03-01 17:31:34 +01:00
return Boolean ( SelectorEngine . closest ( this . _element , '.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 ) {
2019-07-24 08:13:50 +02:00
data . offsets = _objectSpread2 ( { } , 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
2019-08-27 15:03:21 +02:00
return _objectSpread2 ( { } , 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 ) {
2019-03-01 17:31:34 +01:00
var data = Data . 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 ) {
2018-11-13 07:41:12 +01:00
if ( event && ( event . which === RIGHT _MOUSE _BUTTON _WHICH || event . type === 'keyup' && event . which !== TAB _KEYCODE ) ) {
return ;
}
2016-10-10 02:26:51 +02:00
2019-03-01 17:31:34 +01:00
var toggles = makeArray ( SelectorEngine . 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 ] ) ;
2019-03-01 17:31:34 +01:00
var context = Data . 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
2019-03-01 17:31:34 +01:00
if ( ! parent . classList . contains ( ClassName . SHOW ) ) {
2018-11-13 07:41:12 +01:00
continue ;
}
2017-12-31 04:41:36 +01:00
2019-03-01 17:31:34 +01:00
if ( event && ( event . type === 'click' && /input|textarea/i . test ( event . target . tagName ) || event . type === 'keyup' && event . which === TAB _KEYCODE ) && parent . 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
2019-03-01 17:31:34 +01:00
var hideEvent = EventHandler . 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 ) {
2019-03-01 17:31:34 +01:00
makeArray ( document . body . children ) . forEach ( function ( elem ) {
return EventHandler . off ( elem , 'mouseover' , null , noop ( ) ) ;
} ) ;
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 ( ) ;
}
2019-03-01 17:31:34 +01:00
dropdownMenu . classList . remove ( ClassName . SHOW ) ;
parent . classList . remove ( ClassName . SHOW ) ;
EventHandler . 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
2019-03-01 17:31:34 +01:00
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 || SelectorEngine . closest ( event . target , Selector . MENU ) ) : ! REGEXP _KEYDOWN . test ( event . which ) ) {
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
2019-03-01 17:31:34 +01:00
if ( this . disabled || this . classList . contains ( ClassName . 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 ) ;
2019-03-01 17:31:34 +01:00
var isActive = parent . classList . contains ( ClassName . SHOW ) ;
2015-08-19 05:28:28 +02:00
2018-12-16 00:13:22 +01:00
if ( ! isActive || isActive && ( event . which === ESCAPE _KEYCODE || event . which === SPACE _KEYCODE ) ) {
2018-11-13 07:41:12 +01:00
if ( event . which === ESCAPE _KEYCODE ) {
2019-07-12 23:56:26 +02:00
SelectorEngine . findOne ( Selector . DATA _TOGGLE , parent ) . focus ( ) ;
2018-07-24 02:51:14 +02:00
}
2015-05-10 22:47:11 +02:00
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
2019-11-08 09:11:23 +01:00
var items = makeArray ( SelectorEngine . 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
2018-11-13 07:41:12 +01:00
var index = items . indexOf ( event . target ) ;
2015-05-10 22:47:11 +02:00
2018-11-13 07:41:12 +01:00
if ( event . which === ARROW _UP _KEYCODE && index > 0 ) {
// Up
index -- ;
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if ( event . which === ARROW _DOWN _KEYCODE && index < items . length - 1 ) {
// Down
index ++ ;
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if ( index < 0 ) {
index = 0 ;
}
2015-05-10 22:47:11 +02:00
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 ) {
2019-03-01 17:31:34 +01:00
return Data . getData ( element , DATA _KEY ) ;
} ;
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
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2019-08-27 15:03:21 +02:00
EventHandler . on ( document , Event . KEYDOWN _DATA _API , Selector . DATA _TOGGLE , Dropdown . dataApiKeydownHandler ) ;
EventHandler . on ( document , Event . KEYDOWN _DATA _API , Selector . MENU , Dropdown . dataApiKeydownHandler ) ;
EventHandler . on ( document , Event . CLICK _DATA _API , Dropdown . clearMenus ) ;
EventHandler . on ( document , Event . KEYUP _DATA _API , Dropdown . clearMenus ) ;
2019-03-01 17:31:34 +01:00
EventHandler . 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
} ) ;
EventHandler . on ( document , Event . CLICK _DATA _API , Selector . FORM _CHILD , function ( e ) {
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