aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/tab.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/tab.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/tab.js150
1 files changed, 46 insertions, 104 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/tab.js b/vendor/twbs/bootstrap/js/dist/tab.js
index c11e68d37..6fd8deab6 100644
--- a/vendor/twbs/bootstrap/js/dist/tab.js
+++ b/vendor/twbs/bootstrap/js/dist/tab.js
@@ -1,26 +1,21 @@
/*!
- * Bootstrap tab.js v5.2.2 (https://getbootstrap.com/)
+ * Bootstrap tab.js v5.3.0-alpha1 (https://getbootstrap.com/)
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./util/index'), require('./dom/event-handler'), require('./dom/selector-engine'), require('./base-component')) :
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./util/index.js'), require('./dom/event-handler.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
typeof define === 'function' && define.amd ? define(['./util/index', './dom/event-handler', './dom/selector-engine', './base-component'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tab = factory(global.Index, global.EventHandler, global.SelectorEngine, global.BaseComponent));
-})(this, (function (index, EventHandler, SelectorEngine, BaseComponent) { 'use strict';
-
- const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
-
- const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
- const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
- const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+})(this, (function (index_js, EventHandler, SelectorEngine, BaseComponent) { 'use strict';
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.2.2): tab.js
+ * Bootstrap (v5.3.0-alpha1): tab.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
+
/**
* Constants
*/
@@ -50,133 +45,108 @@
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}`;
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="tab"], [data-bs-toggle="pill"], [data-bs-toggle="list"]'; // todo:v6: could be only `tab`
-
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"]`;
+
/**
* Class definition
*/
- class Tab extends BaseComponent__default.default {
+ class Tab extends BaseComponent {
constructor(element) {
super(element);
this._parent = this._element.closest(SELECTOR_TAB_PANEL);
-
if (!this._parent) {
- return; // todo: should Throw exception on v6
+ return;
+ // todo: should Throw exception on v6
// throw new TypeError(`${element.outerHTML} has not a valid parent ${SELECTOR_INNER_ELEM}`)
- } // Set up initial aria attributes
-
+ }
+ // Set up initial aria attributes
this._setInitialAttributes(this._parent, this._getChildren());
+ EventHandler.on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
+ }
- EventHandler__default.default.on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
- } // Getters
-
-
+ // Getters
static get NAME() {
return NAME;
- } // Public
-
+ }
+ // Public
show() {
// Shows this elem and deactivate the active sibling if exists
const innerElem = this._element;
-
if (this._elemIsActive(innerElem)) {
return;
- } // Search for active tab on same parent to deactivate it
-
+ }
+ // Search for active tab on same parent to deactivate it
const active = this._getActiveElem();
-
- const hideEvent = active ? EventHandler__default.default.trigger(active, EVENT_HIDE, {
+ const hideEvent = active ? EventHandler.trigger(active, EVENT_HIDE, {
relatedTarget: innerElem
}) : null;
- const showEvent = EventHandler__default.default.trigger(innerElem, EVENT_SHOW, {
+ const showEvent = EventHandler.trigger(innerElem, EVENT_SHOW, {
relatedTarget: active
});
-
if (showEvent.defaultPrevented || hideEvent && hideEvent.defaultPrevented) {
return;
}
-
this._deactivate(active, innerElem);
-
this._activate(innerElem, active);
- } // Private
-
+ }
+ // Private
_activate(element, relatedElem) {
if (!element) {
return;
}
-
element.classList.add(CLASS_NAME_ACTIVE);
-
- this._activate(index.getElementFromSelector(element)); // Search and activate/show the proper section
-
+ this._activate(SelectorEngine.getElementFromSelector(element)); // Search and activate/show the proper section
const complete = () => {
if (element.getAttribute('role') !== 'tab') {
element.classList.add(CLASS_NAME_SHOW);
return;
}
-
element.removeAttribute('tabindex');
element.setAttribute('aria-selected', true);
-
this._toggleDropDown(element, true);
-
- EventHandler__default.default.trigger(element, EVENT_SHOWN, {
+ EventHandler.trigger(element, EVENT_SHOWN, {
relatedTarget: relatedElem
});
};
-
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE));
}
-
_deactivate(element, relatedElem) {
if (!element) {
return;
}
-
element.classList.remove(CLASS_NAME_ACTIVE);
element.blur();
-
- this._deactivate(index.getElementFromSelector(element)); // Search and deactivate the shown section too
-
+ this._deactivate(SelectorEngine.getElementFromSelector(element)); // Search and deactivate the shown section too
const complete = () => {
if (element.getAttribute('role') !== 'tab') {
element.classList.remove(CLASS_NAME_SHOW);
return;
}
-
element.setAttribute('aria-selected', false);
element.setAttribute('tabindex', '-1');
-
this._toggleDropDown(element, false);
-
- EventHandler__default.default.trigger(element, EVENT_HIDDEN, {
+ EventHandler.trigger(element, EVENT_HIDDEN, {
relatedTarget: relatedElem
});
};
-
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE));
}
-
_keydown(event) {
if (![ARROW_LEFT_KEY, ARROW_RIGHT_KEY, ARROW_UP_KEY, ARROW_DOWN_KEY].includes(event.key)) {
return;
}
-
event.stopPropagation(); // stopPropagation/preventDefault both added to support up/down keys without scrolling the page
-
event.preventDefault();
const isNext = [ARROW_RIGHT_KEY, ARROW_DOWN_KEY].includes(event.key);
- const nextActiveElement = index.getNextActiveElement(this._getChildren().filter(element => !index.isDisabled(element)), event.target, isNext, true);
-
+ const nextActiveElement = index_js.getNextActiveElement(this._getChildren().filter(element => !index_js.isDisabled(element)), event.target, isNext, true);
if (nextActiveElement) {
nextActiveElement.focus({
preventScroll: true
@@ -184,141 +154,113 @@
Tab.getOrCreateInstance(nextActiveElement).show();
}
}
-
_getChildren() {
// collection of inner elements
- return SelectorEngine__default.default.find(SELECTOR_INNER_ELEM, this._parent);
+ return SelectorEngine.find(SELECTOR_INNER_ELEM, this._parent);
}
-
_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);
}
}
-
_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');
}
-
if (!isActive) {
child.setAttribute('tabindex', '-1');
}
+ this._setAttributeIfNotExists(child, 'role', 'tab');
- this._setAttributeIfNotExists(child, 'role', 'tab'); // set attributes to the related panel too
-
-
+ // set attributes to the related panel too
this._setInitialAttributesOnTargetPanel(child);
}
-
_setInitialAttributesOnTargetPanel(child) {
- const target = index.getElementFromSelector(child);
-
+ const target = SelectorEngine.getElementFromSelector(child);
if (!target) {
return;
}
-
this._setAttributeIfNotExists(target, 'role', 'tabpanel');
-
if (child.id) {
this._setAttributeIfNotExists(target, 'aria-labelledby', `#${child.id}`);
}
}
-
_toggleDropDown(element, open) {
const outerElem = this._getOuterElement(element);
-
if (!outerElem.classList.contains(CLASS_DROPDOWN)) {
return;
}
-
const toggle = (selector, className) => {
- const element = SelectorEngine__default.default.findOne(selector, outerElem);
-
+ const element = SelectorEngine.findOne(selector, outerElem);
if (element) {
element.classList.toggle(className, open);
}
};
-
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);
}
}
-
_elemIsActive(elem) {
return elem.classList.contains(CLASS_NAME_ACTIVE);
- } // Try to get the inner element (usually the .nav-link)
-
+ }
+ // Try to get the inner element (usually the .nav-link)
_getInnerElement(elem) {
- return elem.matches(SELECTOR_INNER_ELEM) ? elem : SelectorEngine__default.default.findOne(SELECTOR_INNER_ELEM, elem);
- } // Try to get the outer element (usually the .nav-item)
-
+ return elem.matches(SELECTOR_INNER_ELEM) ? elem : SelectorEngine.findOne(SELECTOR_INNER_ELEM, elem);
+ }
+ // Try to get the outer element (usually the .nav-item)
_getOuterElement(elem) {
return elem.closest(SELECTOR_OUTER) || elem;
- } // Static
-
+ }
+ // Static
static jQueryInterface(config) {
return this.each(function () {
const data = Tab.getOrCreateInstance(this);
-
if (typeof config !== 'string') {
return;
}
-
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
throw new TypeError(`No method named "${config}"`);
}
-
data[config]();
});
}
-
}
+
/**
* Data API implementation
*/
-
- EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
+ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
if (['A', 'AREA'].includes(this.tagName)) {
event.preventDefault();
}
-
- if (index.isDisabled(this)) {
+ if (index_js.isDisabled(this)) {
return;
}
-
Tab.getOrCreateInstance(this).show();
});
+
/**
* Initialize on focus
*/
-
- EventHandler__default.default.on(window, EVENT_LOAD_DATA_API, () => {
- for (const element of SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE_ACTIVE)) {
+ EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
+ for (const element of SelectorEngine.find(SELECTOR_DATA_TOGGLE_ACTIVE)) {
Tab.getOrCreateInstance(element);
}
});
@@ -326,7 +268,7 @@
* jQuery
*/
- index.defineJQueryPlugin(Tab);
+ index_js.defineJQueryPlugin(Tab);
return Tab;