vendor: 4,867 bytes, lines 1-149
1import { E as EventHandler, S as SelectorEngine, d as defineJQueryPlugin, B as BaseComponent, r as reflow, g as getElement } from './dom.js?5.3.8'; 2 3/** 4 * -------------------------------------------------------------------------- 5 * Bootstrap collapse.js 6 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 7 * -------------------------------------------------------------------------- 8 */ 9 10 11/** 12 * Constants 13 */ 14 15const NAME = 'collapse'; 16const DATA_KEY = 'bs.collapse'; 17const EVENT_KEY = `.${DATA_KEY}`; 18const DATA_API_KEY = '.data-api'; 19const EVENT_SHOW = `show${EVENT_KEY}`; 20const EVENT_SHOWN = `shown${EVENT_KEY}`; 21const EVENT_HIDE = `hide${EVENT_KEY}`; 22const EVENT_HIDDEN = `hidden${EVENT_KEY}`; 23const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`; 24const CLASS_NAME_SHOW = 'show'; 25const CLASS_NAME_COLLAPSE = 'collapse'; 26const CLASS_NAME_COLLAPSING = 'collapsing'; 27const CLASS_NAME_COLLAPSED = 'collapsed'; 28const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`; 29const CLASS_NAME_HORIZONTAL = 'collapse-horizontal'; 30const WIDTH = 'width'; 31const HEIGHT = 'height'; 32const SELECTOR_ACTIVES = '.collapse.show, .collapse.collapsing'; 33const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]'; 34const Default = { 35 parent: null, 36 toggle: true 37}; 38const DefaultType = { 39 parent: '(null|element)', 40 toggle: 'boolean' 41}; 42 43/** 44 * Class definition 45 */ 46 47class Collapse extends BaseComponent { 48 constructor(element, config) { 49 super(element, config); 50 this._isTransitioning = false; 51 this._triggerArray = []; 52 const toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE); 53 for (const elem of toggleList) { 54 const selector = SelectorEngine.getSelectorFromElement(elem); 55 const filterElement = SelectorEngine.find(selector).filter(foundElement => foundElement === this._element); 56 if (selector !== null && filterElement.length) { 57 this._triggerArray.push(elem); 58 } 59 } 60 this._initializeChildren(); 61 if (!this._config.parent) { 62 this._addAriaAndCollapsedClass(this._triggerArray, this._isShown()); 63 } 64 if (this._config.toggle) { 65 this.toggle(); 66 } 67 } 68 69 // Getters 70 static get Default() { 71 return Default; 72 } 73 static get DefaultType() { 74 return DefaultType; 75 } 76 static get NAME() { 77 return NAME; 78 } 79 80 // Public 81 toggle() { 82 if (this._isShown()) { 83 this.hide(); 84 } else { 85 this.show(); 86 } 87 } 88 show() { 89 if (this._isTransitioning || this._isShown()) { 90 return; 91 } 92 let activeChildren = []; 93 94 // find active children 95 if (this._config.parent) { 96 activeChildren = this._getFirstLevelChildren(SELECTOR_ACTIVES).filter(element => element !== this._element).map(element => Collapse.getOrCreateInstance(element, { 97 toggle: false 98 })); 99 } 100 if (activeChildren.length && activeChildren[0]._isTransitioning) { 101 return; 102 } 103 const startEvent = EventHandler.trigger(this._element, EVENT_SHOW); 104 if (startEvent.defaultPrevented) { 105 return; 106 } 107 for (const activeInstance of activeChildren) { 108 activeInstance.hide(); 109 } 110 const dimension = this._getDimension(); 111 this._element.classList.remove(CLASS_NAME_COLLAPSE); 112 this._element.classList.add(CLASS_NAME_COLLAPSING); 113 this._element.style[dimension] = 0; 114 this._addAriaAndCollapsedClass(this._triggerArray, true); 115 this._isTransitioning = true; 116 const complete = () => { 117 this._isTransitioning = false; 118 this._element.classList.remove(CLASS_NAME_COLLAPSING); 119 this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW); 120 this._element.style[dimension] = ''; 121 EventHandler.trigger(this._element, EVENT_SHOWN); 122 }; 123 const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1); 124 const scrollSize = `scroll${capitalizedDimension}`; 125 this._queueCallback(complete, this._element, true); 126 this._element.style[dimension] = `${this._element[scrollSize]}px`; 127 } 128 hide() { 129 if (this._isTransitioning || !this._isShown()) { 130 return; 131 } 132 const startEvent = EventHandler.trigger(this._element, EVENT_HIDE); 133 if (startEvent.defaultPrevented) { 134 return; 135 } 136 const dimension = this._getDimension(); 137 this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`; 138 reflow(this._element); 139 this._element.classList.add(CLASS_NAME_COLLAPSING); 140 this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW); 141 for (const trigger of this._triggerArray) { 142 const element = SelectorEngine.getElementFromSelector(trigger); 143 if (element && !this._isShown(element)) { 144 this._addAriaAndCollapsedClass([trigger], false); 145 } 146 } 147 this._isTransitioning = true; 148 const complete = () => { 149 this._isTransitioning = false;
150 this._element.classList.remove(CLASS_NAME_COLLAPSING); 151 this._element.classList.add(CLASS_NAME_COLLAPSE); 152 EventHandler.trigger(this._element, EVENT_HIDDEN); 153 }; 154 this._element.style[dimension] = ''; 155 this._queueCallback(complete, this._element, true); 156 } 157 158 // Private 159 _isShown(element = this._element) { 160 return element.classList.contains(CLASS_NAME_SHOW); 161 } 162 _configAfterMerge(config) { 163 config.toggle = Boolean(config.toggle); // Coerce string values 164 config.parent = getElement(config.parent); 165 return config; 166 } 167 _getDimension() { 168 return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT; 169 } 170 _initializeChildren() { 171 if (!this._config.parent) { 172 return; 173 } 174 const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE); 175 for (const element of children) { 176 const selected = SelectorEngine.getElementFromSelector(element); 177 if (selected) { 178 this._addAriaAndCollapsedClass([element], this._isShown(selected)); 179 } 180 } 181 } 182 _getFirstLevelChildren(selector) { 183 const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent); 184 // remove children if greater depth 185 return SelectorEngine.find(selector, this._config.parent).filter(element => !children.includes(element)); 186 } 187 _addAriaAndCollapsedClass(triggerArray, isOpen) { 188 if (!triggerArray.length) { 189 return; 190 } 191 for (const element of triggerArray) { 192 element.classList.toggle(CLASS_NAME_COLLAPSED, !isOpen); 193 element.setAttribute('aria-expanded', isOpen); 194 } 195 } 196 197 // Static 198 static jQueryInterface(config) { 199 const _config = {}; 200 if (typeof config === 'string' && /show|hide/.test(config)) { 201 _config.toggle = false; 202 } 203 return this.each(function () { 204 const data = Collapse.getOrCreateInstance(this, _config); 205 if (typeof config === 'string') { 206 if (typeof data[config] === 'undefined') { 207 throw new TypeError(`No method named "${config}"`); 208 } 209 data[config](); 210 } 211 }); 212 } 213} 214 215/** 216 * Data API implementation 217 */ 218 219EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { 220 // preventDefault only for <a> elements (which change the URL) not inside the collapsible element 221 if (event.target.tagName === 'A' || event.delegateTarget && event.delegateTarget.tagName === 'A') { 222 event.preventDefault(); 223 } 224 for (const element of SelectorEngine.getMultipleElementsFromSelector(this)) { 225 Collapse.getOrCreateInstance(element, { 226 toggle: false 227 }).toggle(); 228 } 229}); 230 231/** 232 * jQuery 233 */ 234 235defineJQueryPlugin(Collapse); 236 237window.bootstrap = window.bootstrap || {}; 238window.bootstrap.Collapse = Collapse; 239if (Joomla && Joomla.getOptions) { 240 // Get the elements/configurations from the PHP 241 const collapses = { 242 ...Joomla.getOptions('bootstrap.collapse'), 243 ...Joomla.getOptions('bootstrap.accordion') 244 }; 245 // Initialise the elements 246 Object.keys(collapses).forEach(collapse => { 247 const opt = collapses[collapse]; 248 const options = { 249 toggle: opt.toggle ? opt.toggle : true 250 }; 251 if (opt.parent) { 252 options.parent = opt.parent; 253 } 254 const elements = Array.from(document.querySelectorAll(collapse)); 255 if (elements.length) { 256 elements.map(el => new window.bootstrap.Collapse(el, options)); 257 } 258 }); 259} 260 261export { Collapse as C };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.