2018-11-13 07:41:12 +01:00
|
|
|
/*!
|
2024-02-20 16:14:29 +01:00
|
|
|
* Bootstrap tab.js v5.3.3 (https://getbootstrap.com/)
|
|
|
|
* Copyright 2011-2024 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) {
|
2023-04-03 09:26:50 +02:00
|
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./base-component.js'), require('./dom/event-handler.js'), require('./dom/selector-engine.js'), require('./util/index.js')) :
|
|
|
|
typeof define === 'function' && define.amd ? define(['./base-component', './dom/event-handler', './dom/selector-engine', './util/index'], factory) :
|
|
|
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tab = factory(global.BaseComponent, global.EventHandler, global.SelectorEngine, global.Index));
|
|
|
|
})(this, (function (BaseComponent, EventHandler, SelectorEngine, index_js) { 'use strict';
|
2021-02-10 17:14:51 +01:00
|
|
|
|
2021-08-04 17:41:51 +02:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2023-03-24 15:30:16 +01:00
|
|
|
* Bootstrap tab.js
|
2021-08-04 17:41:51 +02:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2023-05-30 17:15:55 +02:00
|
|
|
|
2021-08-04 17:41:51 +02:00
|
|
|
/**
|
2020-12-03 15:18:59 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
|
2021-03-23 17:26:54 +01:00
|
|
|
const NAME = 'tab';
|
|
|
|
const DATA_KEY = 'bs.tab';
|
|
|
|
const EVENT_KEY = `.${DATA_KEY}`;
|
|
|
|
const EVENT_HIDE = `hide${EVENT_KEY}`;
|
|
|
|
const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
|
|
|
|
const EVENT_SHOW = `show${EVENT_KEY}`;
|
|
|
|
const EVENT_SHOWN = `shown${EVENT_KEY}`;
|
2022-05-13 08:07:23 +02:00
|
|
|
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}`;
|
|
|
|
const EVENT_KEYDOWN = `keydown${EVENT_KEY}`;
|
|
|
|
const EVENT_LOAD_DATA_API = `load${EVENT_KEY}`;
|
|
|
|
const ARROW_LEFT_KEY = 'ArrowLeft';
|
|
|
|
const ARROW_RIGHT_KEY = 'ArrowRight';
|
|
|
|
const ARROW_UP_KEY = 'ArrowUp';
|
|
|
|
const ARROW_DOWN_KEY = 'ArrowDown';
|
2023-07-26 09:46:38 +02:00
|
|
|
const HOME_KEY = 'Home';
|
|
|
|
const END_KEY = 'End';
|
2021-03-23 17:26:54 +01:00
|
|
|
const CLASS_NAME_ACTIVE = 'active';
|
|
|
|
const CLASS_NAME_FADE = 'fade';
|
|
|
|
const CLASS_NAME_SHOW = 'show';
|
2022-05-13 08:07:23 +02:00
|
|
|
const CLASS_DROPDOWN = 'dropdown';
|
2021-03-23 17:26:54 +01:00
|
|
|
const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
|
2022-05-13 08:07:23 +02:00
|
|
|
const SELECTOR_DROPDOWN_MENU = '.dropdown-menu';
|
2023-09-14 16:19:27 +02:00
|
|
|
const NOT_SELECTOR_DROPDOWN_TOGGLE = `:not(${SELECTOR_DROPDOWN_TOGGLE})`;
|
2022-05-13 08:07:23 +02:00
|
|
|
const SELECTOR_TAB_PANEL = '.list-group, .nav, [role="tablist"]';
|
|
|
|
const SELECTOR_OUTER = '.nav-item, .list-group-item';
|
|
|
|
const SELECTOR_INNER = `.nav-link${NOT_SELECTOR_DROPDOWN_TOGGLE}, .list-group-item${NOT_SELECTOR_DROPDOWN_TOGGLE}, [role="tab"]${NOT_SELECTOR_DROPDOWN_TOGGLE}`;
|
2023-04-03 09:26:50 +02:00
|
|
|
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="tab"], [data-bs-toggle="pill"], [data-bs-toggle="list"]'; // TODO: could only be `tab` in v6
|
2022-05-13 08:07:23 +02:00
|
|
|
const SELECTOR_INNER_ELEM = `${SELECTOR_INNER}, ${SELECTOR_DATA_TOGGLE}`;
|
|
|
|
const SELECTOR_DATA_TOGGLE_ACTIVE = `.${CLASS_NAME_ACTIVE}[data-bs-toggle="tab"], .${CLASS_NAME_ACTIVE}[data-bs-toggle="pill"], .${CLASS_NAME_ACTIVE}[data-bs-toggle="list"]`;
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2019-10-08 08:39:10 +02:00
|
|
|
/**
|
2022-05-13 08:07:23 +02:00
|
|
|
* Class definition
|
2019-10-08 08:39:10 +02:00
|
|
|
*/
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
class Tab extends BaseComponent {
|
2022-05-13 08:07:23 +02:00
|
|
|
constructor(element) {
|
|
|
|
super(element);
|
|
|
|
this._parent = this._element.closest(SELECTOR_TAB_PANEL);
|
|
|
|
if (!this._parent) {
|
2022-12-24 17:37:22 +01:00
|
|
|
return;
|
2023-04-03 09:26:50 +02:00
|
|
|
// TODO: should throw exception in v6
|
2022-05-13 08:07:23 +02:00
|
|
|
// throw new TypeError(`${element.outerHTML} has not a valid parent ${SELECTOR_INNER_ELEM}`)
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Set up initial aria attributes
|
2022-05-13 08:07:23 +02:00
|
|
|
this._setInitialAttributes(this._parent, this._getChildren());
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Getters
|
2021-05-13 18:22:20 +02:00
|
|
|
static get NAME() {
|
|
|
|
return NAME;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Public
|
2021-03-23 17:26:54 +01:00
|
|
|
show() {
|
2022-05-13 08:07:23 +02:00
|
|
|
// Shows this elem and deactivate the active sibling if exists
|
|
|
|
const innerElem = this._element;
|
|
|
|
if (this._elemIsActive(innerElem)) {
|
|
|
|
return;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Search for active tab on same parent to deactivate it
|
2022-05-13 08:07:23 +02:00
|
|
|
const active = this._getActiveElem();
|
2022-12-24 17:37:22 +01:00
|
|
|
const hideEvent = active ? EventHandler.trigger(active, EVENT_HIDE, {
|
2022-05-13 08:07:23 +02:00
|
|
|
relatedTarget: innerElem
|
2021-02-10 17:14:51 +01:00
|
|
|
}) : null;
|
2022-12-24 17:37:22 +01:00
|
|
|
const showEvent = EventHandler.trigger(innerElem, EVENT_SHOW, {
|
2022-05-13 08:07:23 +02:00
|
|
|
relatedTarget: active
|
2019-03-01 17:31:34 +01:00
|
|
|
});
|
2022-05-13 08:07:23 +02:00
|
|
|
if (showEvent.defaultPrevented || hideEvent && hideEvent.defaultPrevented) {
|
2018-11-13 07:41:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
this._deactivate(active, innerElem);
|
|
|
|
this._activate(innerElem, active);
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Private
|
2022-05-13 08:07:23 +02:00
|
|
|
_activate(element, relatedElem) {
|
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.classList.add(CLASS_NAME_ACTIVE);
|
2022-12-24 17:37:22 +01:00
|
|
|
this._activate(SelectorEngine.getElementFromSelector(element)); // Search and activate/show the proper section
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2021-03-23 17:26:54 +01:00
|
|
|
const complete = () => {
|
2022-05-13 08:07:23 +02:00
|
|
|
if (element.getAttribute('role') !== 'tab') {
|
2022-07-19 17:43:58 +02:00
|
|
|
element.classList.add(CLASS_NAME_SHOW);
|
2022-05-13 08:07:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.removeAttribute('tabindex');
|
|
|
|
element.setAttribute('aria-selected', true);
|
|
|
|
this._toggleDropDown(element, true);
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.trigger(element, EVENT_SHOWN, {
|
2022-05-13 08:07:23 +02:00
|
|
|
relatedTarget: relatedElem
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
2022-05-13 08:07:23 +02:00
|
|
|
};
|
2022-07-19 17:43:58 +02:00
|
|
|
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE));
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
_deactivate(element, relatedElem) {
|
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.classList.remove(CLASS_NAME_ACTIVE);
|
|
|
|
element.blur();
|
2022-12-24 17:37:22 +01:00
|
|
|
this._deactivate(SelectorEngine.getElementFromSelector(element)); // Search and deactivate the shown section too
|
2022-05-13 08:07:23 +02:00
|
|
|
|
|
|
|
const complete = () => {
|
|
|
|
if (element.getAttribute('role') !== 'tab') {
|
2022-07-19 17:43:58 +02:00
|
|
|
element.classList.remove(CLASS_NAME_SHOW);
|
2022-05-13 08:07:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.setAttribute('aria-selected', false);
|
|
|
|
element.setAttribute('tabindex', '-1');
|
|
|
|
this._toggleDropDown(element, false);
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.trigger(element, EVENT_HIDDEN, {
|
2022-05-13 08:07:23 +02:00
|
|
|
relatedTarget: relatedElem
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
2017-09-30 23:28:03 +02:00
|
|
|
};
|
2022-07-19 17:43:58 +02:00
|
|
|
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE));
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
_keydown(event) {
|
2023-07-26 09:46:38 +02:00
|
|
|
if (![ARROW_LEFT_KEY, ARROW_RIGHT_KEY, ARROW_UP_KEY, ARROW_DOWN_KEY, HOME_KEY, END_KEY].includes(event.key)) {
|
2022-05-13 08:07:23 +02:00
|
|
|
return;
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
event.stopPropagation(); // stopPropagation/preventDefault both added to support up/down keys without scrolling the page
|
|
|
|
event.preventDefault();
|
2023-07-26 09:46:38 +02:00
|
|
|
const children = this._getChildren().filter(element => !index_js.isDisabled(element));
|
|
|
|
let nextActiveElement;
|
|
|
|
if ([HOME_KEY, END_KEY].includes(event.key)) {
|
|
|
|
nextActiveElement = children[event.key === HOME_KEY ? 0 : children.length - 1];
|
|
|
|
} else {
|
|
|
|
const isNext = [ARROW_RIGHT_KEY, ARROW_DOWN_KEY].includes(event.key);
|
|
|
|
nextActiveElement = index_js.getNextActiveElement(children, event.target, isNext, true);
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
if (nextActiveElement) {
|
2022-10-03 09:44:02 +02:00
|
|
|
nextActiveElement.focus({
|
|
|
|
preventScroll: true
|
|
|
|
});
|
2022-05-13 08:07:23 +02:00
|
|
|
Tab.getOrCreateInstance(nextActiveElement).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_getChildren() {
|
|
|
|
// collection of inner elements
|
2022-12-24 17:37:22 +01:00
|
|
|
return SelectorEngine.find(SELECTOR_INNER_ELEM, this._parent);
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
_getActiveElem() {
|
|
|
|
return this._getChildren().find(child => this._elemIsActive(child)) || null;
|
|
|
|
}
|
|
|
|
_setInitialAttributes(parent, children) {
|
|
|
|
this._setAttributeIfNotExists(parent, 'role', 'tablist');
|
|
|
|
for (const child of children) {
|
|
|
|
this._setInitialAttributesOnChild(child);
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
_setInitialAttributesOnChild(child) {
|
|
|
|
child = this._getInnerElement(child);
|
|
|
|
const isActive = this._elemIsActive(child);
|
|
|
|
const outerElem = this._getOuterElement(child);
|
|
|
|
child.setAttribute('aria-selected', isActive);
|
|
|
|
if (outerElem !== child) {
|
|
|
|
this._setAttributeIfNotExists(outerElem, 'role', 'presentation');
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
if (!isActive) {
|
|
|
|
child.setAttribute('tabindex', '-1');
|
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
this._setAttributeIfNotExists(child, 'role', 'tab');
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// set attributes to the related panel too
|
2022-05-13 08:07:23 +02:00
|
|
|
this._setInitialAttributesOnTargetPanel(child);
|
|
|
|
}
|
|
|
|
_setInitialAttributesOnTargetPanel(child) {
|
2022-12-24 17:37:22 +01:00
|
|
|
const target = SelectorEngine.getElementFromSelector(child);
|
2022-05-13 08:07:23 +02:00
|
|
|
if (!target) {
|
|
|
|
return;
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
this._setAttributeIfNotExists(target, 'role', 'tabpanel');
|
|
|
|
if (child.id) {
|
2023-03-24 15:30:16 +01:00
|
|
|
this._setAttributeIfNotExists(target, 'aria-labelledby', `${child.id}`);
|
2019-02-11 20:15:34 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
_toggleDropDown(element, open) {
|
|
|
|
const outerElem = this._getOuterElement(element);
|
|
|
|
if (!outerElem.classList.contains(CLASS_DROPDOWN)) {
|
|
|
|
return;
|
2021-05-05 21:32:12 +02:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
const toggle = (selector, className) => {
|
2022-12-24 17:37:22 +01:00
|
|
|
const element = SelectorEngine.findOne(selector, outerElem);
|
2022-05-13 08:07:23 +02:00
|
|
|
if (element) {
|
|
|
|
element.classList.toggle(className, open);
|
2018-07-24 02:51:14 +02:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
};
|
|
|
|
toggle(SELECTOR_DROPDOWN_TOGGLE, CLASS_NAME_ACTIVE);
|
|
|
|
toggle(SELECTOR_DROPDOWN_MENU, CLASS_NAME_SHOW);
|
|
|
|
outerElem.setAttribute('aria-expanded', open);
|
|
|
|
}
|
|
|
|
_setAttributeIfNotExists(element, attribute, value) {
|
|
|
|
if (!element.hasAttribute(attribute)) {
|
|
|
|
element.setAttribute(attribute, value);
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
_elemIsActive(elem) {
|
|
|
|
return elem.classList.contains(CLASS_NAME_ACTIVE);
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Try to get the inner element (usually the .nav-link)
|
2022-05-13 08:07:23 +02:00
|
|
|
_getInnerElement(elem) {
|
2022-12-24 17:37:22 +01:00
|
|
|
return elem.matches(SELECTOR_INNER_ELEM) ? elem : SelectorEngine.findOne(SELECTOR_INNER_ELEM, elem);
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Try to get the outer element (usually the .nav-item)
|
2022-05-13 08:07:23 +02:00
|
|
|
_getOuterElement(elem) {
|
|
|
|
return elem.closest(SELECTOR_OUTER) || elem;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Static
|
2021-03-23 17:26:54 +01:00
|
|
|
static jQueryInterface(config) {
|
2018-11-13 07:41:12 +01:00
|
|
|
return this.each(function () {
|
2021-06-22 20:29:16 +02:00
|
|
|
const data = Tab.getOrCreateInstance(this);
|
2022-05-13 08:07:23 +02:00
|
|
|
if (typeof config !== 'string') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
|
|
|
throw new TypeError(`No method named "${config}"`);
|
2017-09-30 23:28:03 +02:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
data[config]();
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2018-11-13 07:41:12 +01:00
|
|
|
/**
|
2022-05-13 08:07:23 +02:00
|
|
|
* Data API implementation
|
2018-11-13 07:41:12 +01:00
|
|
|
*/
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
2021-05-05 21:32:12 +02:00
|
|
|
if (['A', 'AREA'].includes(this.tagName)) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
if (index_js.isDisabled(this)) {
|
2021-05-05 21:32:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
Tab.getOrCreateInstance(this).show();
|
|
|
|
});
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2022-05-13 08:07:23 +02:00
|
|
|
/**
|
|
|
|
* Initialize on focus
|
|
|
|
*/
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
|
|
|
for (const element of SelectorEngine.find(SELECTOR_DATA_TOGGLE_ACTIVE)) {
|
2022-05-13 08:07:23 +02:00
|
|
|
Tab.getOrCreateInstance(element);
|
|
|
|
}
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
|
|
|
/**
|
|
|
|
* jQuery
|
|
|
|
*/
|
2015-05-11 21:29:06 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
index_js.defineJQueryPlugin(Tab);
|
2015-05-11 21:29:06 +02:00
|
|
|
|
|
|
|
return Tab;
|
2018-07-24 02:51:14 +02:00
|
|
|
|
2021-10-05 17:50:18 +02:00
|
|
|
}));
|
2018-07-24 02:51:14 +02:00
|
|
|
//# sourceMappingURL=tab.js.map
|