2018-11-13 01:41:12 -05:00
/ * !
2021-09-07 11:37:44 -04:00
* Bootstrap collapse . js v5 . 1.1 ( https : //getbootstrap.com/)
2021-02-10 11:14:51 -05:00
* Copyright 2011 - 2021 The Bootstrap Authors ( https : //github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 14:50:01 -04:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
2018-11-13 01:41:12 -05:00
* /
2018-07-23 20:51:14 -04:00
( function ( global , factory ) {
2021-08-04 11:41:51 -04:00
typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( 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 ( [ './dom/data' , './dom/event-handler' , './dom/manipulator' , './dom/selector-engine' , './base-component' ] , factory ) :
( global = typeof globalThis !== 'undefined' ? globalThis : global || self , global . Collapse = factory ( global . Data , global . EventHandler , global . Manipulator , global . SelectorEngine , global . Base ) ) ;
} ( this , ( function ( Data , EventHandler , Manipulator , SelectorEngine , BaseComponent ) { 'use strict' ;
2018-07-23 20:51:14 -04:00
2020-09-14 11:12:06 -04: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 ) ;
2021-08-04 11:41:51 -04:00
var SelectorEngine _ _default = /*#__PURE__*/ _interopDefaultLegacy ( SelectorEngine ) ;
2021-02-10 11:14:51 -05:00
var BaseComponent _ _default = /*#__PURE__*/ _interopDefaultLegacy ( BaseComponent ) ;
2021-08-04 11:41:51 -04:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2021-09-07 11:37:44 -04:00
* Bootstrap ( v5 . 1.1 ) : util / index . js
2021-08-04 11:41:51 -04:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2021-03-23 12:26:54 -04:00
const toType = obj => {
2020-03-28 06:29:08 -04:00
if ( obj === null || obj === undefined ) {
2021-03-23 12:26:54 -04:00
return ` ${ obj } ` ;
2020-03-28 06:29:08 -04:00
}
2019-03-01 11:31:34 -05:00
return { } . toString . call ( obj ) . match ( /\s([a-z]+)/i ) [ 1 ] . toLowerCase ( ) ;
} ;
2021-03-23 12:26:54 -04:00
const getSelector = element => {
let selector = element . getAttribute ( 'data-bs-target' ) ;
2019-03-01 11:31:34 -05:00
if ( ! selector || selector === '#' ) {
2021-03-23 12:26:54 -04:00
let hrefAttr = element . getAttribute ( 'href' ) ; // The only valid content that could double as a selector are IDs or classes,
2021-02-10 11:14:51 -05:00
// 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 ( '#' ) ) {
2021-05-05 15:32:12 -04:00
hrefAttr = ` # ${ hrefAttr . split ( '#' ) [ 1 ] } ` ;
2021-02-10 11:14:51 -05:00
}
2019-08-27 09:03:21 -04:00
selector = hrefAttr && hrefAttr !== '#' ? hrefAttr . trim ( ) : null ;
2019-03-01 11:31:34 -05:00
}
2019-08-27 09:03:21 -04:00
return selector ;
} ;
2021-03-23 12:26:54 -04:00
const getSelectorFromElement = element => {
const selector = getSelector ( element ) ;
2019-08-27 09:03:21 -04:00
if ( selector ) {
2019-03-01 11:31:34 -05:00
return document . querySelector ( selector ) ? selector : null ;
}
2019-08-27 09:03:21 -04:00
return null ;
} ;
2021-03-23 12:26:54 -04:00
const getElementFromSelector = element => {
const selector = getSelector ( element ) ;
2019-08-27 09:03:21 -04:00
return selector ? document . querySelector ( selector ) : null ;
2019-03-01 11:31:34 -05:00
} ;
2021-05-13 12:22:20 -04:00
const isElement = obj => {
if ( ! obj || typeof obj !== 'object' ) {
return false ;
}
2019-03-01 11:31:34 -05:00
2021-05-13 12:22:20 -04:00
if ( typeof obj . jquery !== 'undefined' ) {
obj = obj [ 0 ] ;
}
2019-03-01 11:31:34 -05:00
2021-05-13 12:22:20 -04:00
return typeof obj . nodeType !== 'undefined' ;
2019-03-01 11:31:34 -05:00
} ;
2021-05-13 12:22:20 -04:00
const getElement = obj => {
if ( isElement ( obj ) ) {
// it's a jQuery object or a node element
return obj . jquery ? obj [ 0 ] : obj ;
}
2019-03-01 11:31:34 -05:00
2021-05-13 12:22:20 -04:00
if ( typeof obj === 'string' && obj . length > 0 ) {
2021-08-04 11:41:51 -04:00
return document . querySelector ( obj ) ;
2019-03-01 11:31:34 -05:00
}
2021-05-13 12:22:20 -04:00
return null ;
2019-03-01 11:31:34 -05:00
} ;
2021-03-23 12:26:54 -04:00
const typeCheckConfig = ( componentName , config , configTypes ) => {
Object . keys ( configTypes ) . forEach ( property => {
const expectedTypes = configTypes [ property ] ;
const value = config [ property ] ;
const valueType = value && isElement ( value ) ? 'element' : toType ( value ) ;
2019-03-01 11:31:34 -05:00
if ( ! new RegExp ( expectedTypes ) . test ( valueType ) ) {
2021-05-05 15:32:12 -04:00
throw new TypeError ( ` ${ componentName . toUpperCase ( ) } : Option " ${ property } " provided type " ${ valueType } " but expected type " ${ expectedTypes } ". ` ) ;
2019-03-01 11:31:34 -05:00
}
} ) ;
} ;
2021-08-04 11:41:51 -04:00
/ * *
* Trick to restart an element ' s animation
*
* @ param { HTMLElement } element
* @ return void
*
* @ see https : //www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
* /
2019-03-01 11:31:34 -05:00
2021-08-04 11:41:51 -04:00
const reflow = element => {
// eslint-disable-next-line no-unused-expressions
element . offsetHeight ;
} ;
2019-03-01 11:31:34 -05:00
2021-03-23 12:26:54 -04:00
const getjQuery = ( ) => {
const {
jQuery
} = window ;
2019-08-27 09:03:21 -04:00
2020-11-23 08:17:16 -05:00
if ( jQuery && ! document . body . hasAttribute ( 'data-bs-no-jquery' ) ) {
2019-08-27 09:03:21 -04:00
return jQuery ;
}
return null ;
} ;
2021-06-22 14:29:16 -04:00
const DOMContentLoadedCallbacks = [ ] ;
2021-03-23 12:26:54 -04:00
const onDOMContentLoaded = callback => {
2020-11-11 12:07:37 -05:00
if ( document . readyState === 'loading' ) {
2021-06-22 14:29:16 -04:00
// add listener on the first call when the document is in loading state
if ( ! DOMContentLoadedCallbacks . length ) {
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
DOMContentLoadedCallbacks . forEach ( callback => callback ( ) ) ;
} ) ;
}
DOMContentLoadedCallbacks . push ( callback ) ;
2020-11-11 12:07:37 -05:00
} else {
callback ( ) ;
}
} ;
2021-05-13 12:22:20 -04:00
const defineJQueryPlugin = plugin => {
2021-03-23 12:26:54 -04:00
onDOMContentLoaded ( ( ) => {
const $ = getjQuery ( ) ;
2021-02-10 11:14:51 -05:00
/* istanbul ignore if */
2020-12-03 09:18:59 -05:00
2021-02-10 11:14:51 -05:00
if ( $ ) {
2021-05-13 12:22:20 -04:00
const name = plugin . NAME ;
2021-03-23 12:26:54 -04:00
const JQUERY _NO _CONFLICT = $ . fn [ name ] ;
2021-02-10 11:14:51 -05:00
$ . fn [ name ] = plugin . jQueryInterface ;
$ . fn [ name ] . Constructor = plugin ;
2020-12-03 09:18:59 -05:00
2021-03-23 12:26:54 -04:00
$ . fn [ name ] . noConflict = ( ) => {
2021-02-10 11:14:51 -05:00
$ . fn [ name ] = JQUERY _NO _CONFLICT ;
return plugin . jQueryInterface ;
} ;
2020-12-03 09:18:59 -05:00
}
2021-02-10 11:14:51 -05:00
} ) ;
} ;
2020-12-03 09:18:59 -05:00
2021-03-23 12:26:54 -04:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2021-09-07 11:37:44 -04:00
* Bootstrap ( v5 . 1.1 ) : collapse . js
2021-03-23 12:26:54 -04:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2020-12-03 09:18:59 -05:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Constants
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2021-03-23 12:26:54 -04:00
const NAME = 'collapse' ;
const DATA _KEY = 'bs.collapse' ;
const EVENT _KEY = ` . ${ DATA _KEY } ` ;
const DATA _API _KEY = '.data-api' ;
const Default = {
2018-11-13 01:41:12 -05:00
toggle : true ,
2021-08-04 11:41:51 -04:00
parent : null
2018-11-13 01:41:12 -05:00
} ;
2021-03-23 12:26:54 -04:00
const DefaultType = {
2018-11-13 01:41:12 -05:00
toggle : 'boolean' ,
2021-08-04 11:41:51 -04:00
parent : '(null|element)'
2018-11-13 01:41:12 -05:00
} ;
2021-03-23 12:26:54 -04:00
const EVENT _SHOW = ` show ${ EVENT _KEY } ` ;
const EVENT _SHOWN = ` shown ${ EVENT _KEY } ` ;
const EVENT _HIDE = ` hide ${ EVENT _KEY } ` ;
const EVENT _HIDDEN = ` hidden ${ EVENT _KEY } ` ;
const EVENT _CLICK _DATA _API = ` click ${ EVENT _KEY } ${ DATA _API _KEY } ` ;
const CLASS _NAME _SHOW = 'show' ;
const CLASS _NAME _COLLAPSE = 'collapse' ;
const CLASS _NAME _COLLAPSING = 'collapsing' ;
const CLASS _NAME _COLLAPSED = 'collapsed' ;
2021-08-04 11:41:51 -04:00
const CLASS _NAME _HORIZONTAL = 'collapse-horizontal' ;
2021-03-23 12:26:54 -04:00
const WIDTH = 'width' ;
const HEIGHT = 'height' ;
2021-09-07 11:37:44 -04:00
const SELECTOR _ACTIVES = '.collapse.show, .collapse.collapsing' ;
2021-03-23 12:26:54 -04:00
const SELECTOR _DATA _TOGGLE = '[data-bs-toggle="collapse"]' ;
2019-10-08 02:39:10 -04:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Class Definition
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2018-11-13 01:41:12 -05:00
2021-03-23 12:26:54 -04:00
class Collapse extends BaseComponent _ _default [ 'default' ] {
constructor ( element , config ) {
super ( element ) ;
this . _isTransitioning = false ;
this . _config = this . _getConfig ( config ) ;
2021-08-04 11:41:51 -04:00
this . _triggerArray = [ ] ;
2021-03-23 12:26:54 -04:00
const toggleList = SelectorEngine _ _default [ 'default' ] . find ( SELECTOR _DATA _TOGGLE ) ;
2020-12-03 09:18:59 -05:00
2021-03-23 12:26:54 -04:00
for ( let i = 0 , len = toggleList . length ; i < len ; i ++ ) {
const elem = toggleList [ i ] ;
const selector = getSelectorFromElement ( elem ) ;
const filterElement = SelectorEngine _ _default [ 'default' ] . find ( selector ) . filter ( foundElem => foundElem === this . _element ) ;
2017-05-16 03:59:44 -04:00
2019-03-01 11:31:34 -05:00
if ( selector !== null && filterElement . length ) {
2021-03-23 12:26:54 -04:00
this . _selector = selector ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
this . _triggerArray . push ( elem ) ;
2018-07-23 20:51:14 -04:00
}
2018-11-13 01:41:12 -05:00
}
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
this . _initializeChildren ( ) ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
if ( ! this . _config . parent ) {
2021-08-04 11:41:51 -04:00
this . _addAriaAndCollapsedClass ( this . _triggerArray , this . _isShown ( ) ) ;
2018-11-13 01:41:12 -05:00
}
2015-08-13 00:12:03 -04:00
2021-03-23 12:26:54 -04:00
if ( this . _config . toggle ) {
this . toggle ( ) ;
2018-11-13 01:41:12 -05:00
}
} // Getters
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
static get Default ( ) {
return Default ;
}
2021-05-13 12:22:20 -04:00
static get NAME ( ) {
return NAME ;
2021-03-23 12:26:54 -04:00
} // Public
2016-10-09 20:26:51 -04:00
2021-03-23 12:26:54 -04:00
toggle ( ) {
2021-08-04 11:41:51 -04:00
if ( this . _isShown ( ) ) {
2018-11-13 01:41:12 -05:00
this . hide ( ) ;
} else {
this . show ( ) ;
}
2021-03-23 12:26:54 -04:00
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
show ( ) {
2021-08-04 11:41:51 -04:00
if ( this . _isTransitioning || this . _isShown ( ) ) {
2018-11-13 01:41:12 -05:00
return ;
}
2018-09-17 15:34:34 -04:00
2021-08-04 11:41:51 -04:00
let actives = [ ] ;
2021-03-23 12:26:54 -04:00
let activesData ;
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
if ( this . _config . parent ) {
const children = SelectorEngine _ _default [ 'default' ] . find ( ` . ${ CLASS _NAME _COLLAPSE } . ${ CLASS _NAME _COLLAPSE } ` , this . _config . parent ) ;
actives = SelectorEngine _ _default [ 'default' ] . find ( SELECTOR _ACTIVES , this . _config . parent ) . filter ( elem => ! children . includes ( elem ) ) ; // remove children if greater depth
2018-11-13 01:41:12 -05:00
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const container = SelectorEngine _ _default [ 'default' ] . findOne ( this . _selector ) ;
2019-03-01 11:31:34 -05:00
2021-08-04 11:41:51 -04:00
if ( actives . length ) {
2021-03-23 12:26:54 -04:00
const tempActiveData = actives . find ( elem => container !== elem ) ;
2021-06-22 14:29:16 -04:00
activesData = tempActiveData ? Collapse . getInstance ( tempActiveData ) : null ;
2015-05-10 02:00:59 -04:00
2018-11-13 01:41:12 -05:00
if ( activesData && activesData . _isTransitioning ) {
2018-07-23 20:51:14 -04:00
return ;
}
2018-11-13 01:41:12 -05:00
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const startEvent = EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _SHOW ) ;
2015-05-10 02:00:59 -04:00
2019-03-01 11:31:34 -05:00
if ( startEvent . defaultPrevented ) {
2018-11-13 01:41:12 -05:00
return ;
}
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
actives . forEach ( elemActive => {
if ( container !== elemActive ) {
Collapse . getOrCreateInstance ( elemActive , {
toggle : false
} ) . hide ( ) ;
}
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
if ( ! activesData ) {
Data _ _default [ 'default' ] . set ( elemActive , DATA _KEY , null ) ;
}
} ) ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const dimension = this . _getDimension ( ) ;
2018-11-13 01:41:12 -05:00
2020-03-28 06:29:08 -04:00
this . _element . classList . remove ( CLASS _NAME _COLLAPSE ) ;
2019-03-01 11:31:34 -05:00
2020-03-28 06:29:08 -04:00
this . _element . classList . add ( CLASS _NAME _COLLAPSING ) ;
2019-03-01 11:31:34 -05:00
2018-11-13 01:41:12 -05:00
this . _element . style [ dimension ] = 0 ;
2021-08-04 11:41:51 -04:00
this . _addAriaAndCollapsedClass ( this . _triggerArray , true ) ;
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
this . _isTransitioning = true ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const complete = ( ) => {
2021-08-04 11:41:51 -04:00
this . _isTransitioning = false ;
2021-03-23 12:26:54 -04:00
this . _element . classList . remove ( CLASS _NAME _COLLAPSING ) ;
2019-03-01 11:31:34 -05:00
2021-03-23 12:26:54 -04:00
this . _element . classList . add ( CLASS _NAME _COLLAPSE , CLASS _NAME _SHOW ) ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
this . _element . style [ dimension ] = '' ;
EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _SHOWN ) ;
2018-07-23 20:51:14 -04:00
} ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const capitalizedDimension = dimension [ 0 ] . toUpperCase ( ) + dimension . slice ( 1 ) ;
const scrollSize = ` scroll ${ capitalizedDimension } ` ;
2021-05-13 12:22:20 -04:00
this . _queueCallback ( complete , this . _element , true ) ;
2021-03-23 12:26:54 -04:00
this . _element . style [ dimension ] = ` ${ this . _element [ scrollSize ] } px ` ;
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
hide ( ) {
2021-08-04 11:41:51 -04:00
if ( this . _isTransitioning || ! this . _isShown ( ) ) {
2018-11-13 01:41:12 -05:00
return ;
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const startEvent = EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _HIDE ) ;
2015-05-10 02:00:59 -04:00
2019-03-01 11:31:34 -05:00
if ( startEvent . defaultPrevented ) {
2018-11-13 01:41:12 -05:00
return ;
}
2021-03-23 12:26:54 -04:00
const dimension = this . _getDimension ( ) ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
this . _element . style [ dimension ] = ` ${ this . _element . getBoundingClientRect ( ) [ dimension ] } px ` ;
2019-03-01 11:31:34 -05:00
reflow ( this . _element ) ;
2020-03-28 06:29:08 -04:00
this . _element . classList . add ( CLASS _NAME _COLLAPSING ) ;
2019-03-01 11:31:34 -05:00
2020-05-13 14:53:43 -04:00
this . _element . classList . remove ( CLASS _NAME _COLLAPSE , CLASS _NAME _SHOW ) ;
2019-03-01 11:31:34 -05:00
2021-03-23 12:26:54 -04:00
const triggerArrayLength = this . _triggerArray . length ;
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
for ( let i = 0 ; i < triggerArrayLength ; i ++ ) {
const trigger = this . _triggerArray [ i ] ;
const elem = getElementFromSelector ( trigger ) ;
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
if ( elem && ! this . _isShown ( elem ) ) {
this . _addAriaAndCollapsedClass ( [ trigger ] , false ) ;
2017-09-06 00:05:12 -04:00
}
2018-11-13 01:41:12 -05:00
}
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
this . _isTransitioning = true ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
const complete = ( ) => {
2021-08-04 11:41:51 -04:00
this . _isTransitioning = false ;
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
this . _element . classList . remove ( CLASS _NAME _COLLAPSING ) ;
2019-03-01 11:31:34 -05:00
2021-03-23 12:26:54 -04:00
this . _element . classList . add ( CLASS _NAME _COLLAPSE ) ;
2019-03-01 11:31:34 -05:00
2021-03-23 12:26:54 -04:00
EventHandler _ _default [ 'default' ] . trigger ( this . _element , EVENT _HIDDEN ) ;
2018-07-23 20:51:14 -04:00
} ;
2016-10-09 20:26:51 -04:00
2018-11-13 01:41:12 -05:00
this . _element . style [ dimension ] = '' ;
2021-05-13 12:22:20 -04:00
this . _queueCallback ( complete , this . _element , true ) ;
2021-03-23 12:26:54 -04:00
}
2016-10-09 20:26:51 -04:00
2021-08-04 11:41:51 -04:00
_isShown ( element = this . _element ) {
return element . classList . contains ( CLASS _NAME _SHOW ) ;
2019-01-04 11:29:45 -05:00
} // Private
2016-10-09 20:26:51 -04:00
2021-03-23 12:26:54 -04:00
_getConfig ( config ) {
config = { ... Default ,
2021-08-04 11:41:51 -04:00
... Manipulator _ _default [ 'default' ] . getDataAttributes ( this . _element ) ,
2021-03-23 12:26:54 -04:00
... config
} ;
2018-11-13 01:41:12 -05:00
config . toggle = Boolean ( config . toggle ) ; // Coerce string values
2017-09-30 17:28:03 -04:00
2021-08-04 11:41:51 -04:00
config . parent = getElement ( config . parent ) ;
2019-03-01 11:31:34 -05:00
typeCheckConfig ( NAME , config , DefaultType ) ;
2018-11-13 01:41:12 -05:00
return config ;
2021-03-23 12:26:54 -04:00
}
2017-09-30 17:28:03 -04:00
2021-03-23 12:26:54 -04:00
_getDimension ( ) {
2021-08-04 11:41:51 -04:00
return this . _element . classList . contains ( CLASS _NAME _HORIZONTAL ) ? WIDTH : HEIGHT ;
2021-03-23 12:26:54 -04:00
}
2017-09-30 17:28:03 -04:00
2021-08-04 11:41:51 -04:00
_initializeChildren ( ) {
if ( ! this . _config . parent ) {
return ;
}
const children = SelectorEngine _ _default [ 'default' ] . find ( ` . ${ CLASS _NAME _COLLAPSE } . ${ CLASS _NAME _COLLAPSE } ` , this . _config . parent ) ;
SelectorEngine _ _default [ 'default' ] . find ( SELECTOR _DATA _TOGGLE , this . _config . parent ) . filter ( elem => ! children . includes ( elem ) ) . forEach ( element => {
2021-03-23 12:26:54 -04:00
const selected = getElementFromSelector ( element ) ;
2019-07-24 02:13:50 -04:00
2021-08-04 11:41:51 -04:00
if ( selected ) {
this . _addAriaAndCollapsedClass ( [ element ] , this . _isShown ( selected ) ) ;
}
2018-11-13 01:41:12 -05:00
} ) ;
2021-03-23 12:26:54 -04:00
}
2015-05-10 02:00:59 -04:00
2021-08-04 11:41:51 -04:00
_addAriaAndCollapsedClass ( triggerArray , isOpen ) {
if ( ! triggerArray . length ) {
2020-09-14 11:12:06 -04:00
return ;
2018-11-13 01:41:12 -05:00
}
2020-09-14 11:12:06 -04:00
2021-03-23 12:26:54 -04:00
triggerArray . forEach ( elem => {
2020-09-14 11:12:06 -04:00
if ( isOpen ) {
elem . classList . remove ( CLASS _NAME _COLLAPSED ) ;
} else {
elem . classList . add ( CLASS _NAME _COLLAPSED ) ;
}
elem . setAttribute ( 'aria-expanded' , isOpen ) ;
} ) ;
2019-01-04 11:29:45 -05:00
} // Static
2017-09-30 17:28:03 -04:00
2021-08-04 11:41:51 -04:00
static jQueryInterface ( config ) {
return this . each ( function ( ) {
const _config = { } ;
2018-07-23 20:51:14 -04:00
2021-08-04 11:41:51 -04:00
if ( typeof config === 'string' && /show|hide/ . test ( config ) ) {
_config . toggle = false ;
2018-11-13 01:41:12 -05:00
}
2017-09-30 17:28:03 -04:00
2021-08-04 11:41:51 -04:00
const data = Collapse . getOrCreateInstance ( this , _config ) ;
2017-09-30 17:28:03 -04:00
2021-08-04 11:41:51 -04:00
if ( typeof config === 'string' ) {
if ( typeof data [ config ] === 'undefined' ) {
throw new TypeError ( ` No method named " ${ config } " ` ) ;
}
data [ config ] ( ) ;
}
2018-11-13 01:41:12 -05:00
} ) ;
2021-03-23 12:26:54 -04:00
}
2015-05-10 02:00:59 -04:00
2021-03-23 12:26:54 -04:00
}
2018-11-13 01:41:12 -05:00
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* Data Api implementation
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
2017-09-30 17:28:03 -04:00
2015-05-10 02:00:59 -04:00
2020-09-14 11:12:06 -04:00
EventHandler _ _default [ 'default' ] . on ( document , EVENT _CLICK _DATA _API , SELECTOR _DATA _TOGGLE , function ( event ) {
2018-11-13 01:41:12 -05:00
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
2021-02-10 11:14:51 -05:00
if ( event . target . tagName === 'A' || event . delegateTarget && event . delegateTarget . tagName === 'A' ) {
2018-11-13 01:41:12 -05:00
event . preventDefault ( ) ;
}
2017-09-30 17:28:03 -04:00
2021-03-23 12:26:54 -04:00
const selector = getSelectorFromElement ( this ) ;
const selectorElements = SelectorEngine _ _default [ 'default' ] . find ( selector ) ;
selectorElements . forEach ( element => {
2021-08-04 11:41:51 -04:00
Collapse . getOrCreateInstance ( element , {
toggle : false
} ) . toggle ( ) ;
2018-11-13 01:41:12 -05:00
} ) ;
} ) ;
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* jQuery
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2020-11-11 12:07:37 -05:00
* add . Collapse to jQuery only if jQuery is present
2018-11-13 01:41:12 -05:00
* /
2015-05-10 02:00:59 -04:00
2021-05-13 12:22:20 -04:00
defineJQueryPlugin ( Collapse ) ;
2015-05-10 02:00:59 -04:00
return Collapse ;
2018-07-23 20:51:14 -04:00
2019-11-08 03:11:23 -05:00
} ) ) ) ;
2018-07-23 20:51:14 -04:00
//# sourceMappingURL=collapse.js.map