source: trip-planner-front/node_modules/bootstrap/js/dist/tab.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 10.7 KB
Line 
1/*!
2 * Bootstrap tab.js v5.1.3 (https://getbootstrap.com/)
3 * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5 */
6(function (global, factory) {
7 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
8 typeof define === 'function' && define.amd ? define(['./dom/event-handler', './dom/selector-engine', './base-component'], factory) :
9 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tab = factory(global.EventHandler, global.SelectorEngine, global.Base));
10})(this, (function (EventHandler, SelectorEngine, BaseComponent) { 'use strict';
11
12 const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
13
14 const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
15 const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
16 const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
17
18 /**
19 * --------------------------------------------------------------------------
20 * Bootstrap (v5.1.3): util/index.js
21 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
22 * --------------------------------------------------------------------------
23 */
24
25 const getSelector = element => {
26 let selector = element.getAttribute('data-bs-target');
27
28 if (!selector || selector === '#') {
29 let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
30 // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
31 // `document.querySelector` will rightfully complain it is invalid.
32 // See https://github.com/twbs/bootstrap/issues/32273
33
34 if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
35 return null;
36 } // Just in case some CMS puts out a full URL with the anchor appended
37
38
39 if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
40 hrefAttr = `#${hrefAttr.split('#')[1]}`;
41 }
42
43 selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
44 }
45
46 return selector;
47 };
48
49 const getElementFromSelector = element => {
50 const selector = getSelector(element);
51 return selector ? document.querySelector(selector) : null;
52 };
53
54 const isDisabled = element => {
55 if (!element || element.nodeType !== Node.ELEMENT_NODE) {
56 return true;
57 }
58
59 if (element.classList.contains('disabled')) {
60 return true;
61 }
62
63 if (typeof element.disabled !== 'undefined') {
64 return element.disabled;
65 }
66
67 return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
68 };
69 /**
70 * Trick to restart an element's animation
71 *
72 * @param {HTMLElement} element
73 * @return void
74 *
75 * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
76 */
77
78
79 const reflow = element => {
80 // eslint-disable-next-line no-unused-expressions
81 element.offsetHeight;
82 };
83
84 const getjQuery = () => {
85 const {
86 jQuery
87 } = window;
88
89 if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
90 return jQuery;
91 }
92
93 return null;
94 };
95
96 const DOMContentLoadedCallbacks = [];
97
98 const onDOMContentLoaded = callback => {
99 if (document.readyState === 'loading') {
100 // add listener on the first call when the document is in loading state
101 if (!DOMContentLoadedCallbacks.length) {
102 document.addEventListener('DOMContentLoaded', () => {
103 DOMContentLoadedCallbacks.forEach(callback => callback());
104 });
105 }
106
107 DOMContentLoadedCallbacks.push(callback);
108 } else {
109 callback();
110 }
111 };
112
113 const defineJQueryPlugin = plugin => {
114 onDOMContentLoaded(() => {
115 const $ = getjQuery();
116 /* istanbul ignore if */
117
118 if ($) {
119 const name = plugin.NAME;
120 const JQUERY_NO_CONFLICT = $.fn[name];
121 $.fn[name] = plugin.jQueryInterface;
122 $.fn[name].Constructor = plugin;
123
124 $.fn[name].noConflict = () => {
125 $.fn[name] = JQUERY_NO_CONFLICT;
126 return plugin.jQueryInterface;
127 };
128 }
129 });
130 };
131
132 /**
133 * --------------------------------------------------------------------------
134 * Bootstrap (v5.1.3): tab.js
135 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
136 * --------------------------------------------------------------------------
137 */
138 /**
139 * ------------------------------------------------------------------------
140 * Constants
141 * ------------------------------------------------------------------------
142 */
143
144 const NAME = 'tab';
145 const DATA_KEY = 'bs.tab';
146 const EVENT_KEY = `.${DATA_KEY}`;
147 const DATA_API_KEY = '.data-api';
148 const EVENT_HIDE = `hide${EVENT_KEY}`;
149 const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
150 const EVENT_SHOW = `show${EVENT_KEY}`;
151 const EVENT_SHOWN = `shown${EVENT_KEY}`;
152 const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
153 const CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu';
154 const CLASS_NAME_ACTIVE = 'active';
155 const CLASS_NAME_FADE = 'fade';
156 const CLASS_NAME_SHOW = 'show';
157 const SELECTOR_DROPDOWN = '.dropdown';
158 const SELECTOR_NAV_LIST_GROUP = '.nav, .list-group';
159 const SELECTOR_ACTIVE = '.active';
160 const SELECTOR_ACTIVE_UL = ':scope > li > .active';
161 const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="tab"], [data-bs-toggle="pill"], [data-bs-toggle="list"]';
162 const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
163 const SELECTOR_DROPDOWN_ACTIVE_CHILD = ':scope > .dropdown-menu .active';
164 /**
165 * ------------------------------------------------------------------------
166 * Class Definition
167 * ------------------------------------------------------------------------
168 */
169
170 class Tab extends BaseComponent__default.default {
171 // Getters
172 static get NAME() {
173 return NAME;
174 } // Public
175
176
177 show() {
178 if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(CLASS_NAME_ACTIVE)) {
179 return;
180 }
181
182 let previous;
183 const target = getElementFromSelector(this._element);
184
185 const listElement = this._element.closest(SELECTOR_NAV_LIST_GROUP);
186
187 if (listElement) {
188 const itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? SELECTOR_ACTIVE_UL : SELECTOR_ACTIVE;
189 previous = SelectorEngine__default.default.find(itemSelector, listElement);
190 previous = previous[previous.length - 1];
191 }
192
193 const hideEvent = previous ? EventHandler__default.default.trigger(previous, EVENT_HIDE, {
194 relatedTarget: this._element
195 }) : null;
196 const showEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW, {
197 relatedTarget: previous
198 });
199
200 if (showEvent.defaultPrevented || hideEvent !== null && hideEvent.defaultPrevented) {
201 return;
202 }
203
204 this._activate(this._element, listElement);
205
206 const complete = () => {
207 EventHandler__default.default.trigger(previous, EVENT_HIDDEN, {
208 relatedTarget: this._element
209 });
210 EventHandler__default.default.trigger(this._element, EVENT_SHOWN, {
211 relatedTarget: previous
212 });
213 };
214
215 if (target) {
216 this._activate(target, target.parentNode, complete);
217 } else {
218 complete();
219 }
220 } // Private
221
222
223 _activate(element, container, callback) {
224 const activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? SelectorEngine__default.default.find(SELECTOR_ACTIVE_UL, container) : SelectorEngine__default.default.children(container, SELECTOR_ACTIVE);
225 const active = activeElements[0];
226 const isTransitioning = callback && active && active.classList.contains(CLASS_NAME_FADE);
227
228 const complete = () => this._transitionComplete(element, active, callback);
229
230 if (active && isTransitioning) {
231 active.classList.remove(CLASS_NAME_SHOW);
232
233 this._queueCallback(complete, element, true);
234 } else {
235 complete();
236 }
237 }
238
239 _transitionComplete(element, active, callback) {
240 if (active) {
241 active.classList.remove(CLASS_NAME_ACTIVE);
242 const dropdownChild = SelectorEngine__default.default.findOne(SELECTOR_DROPDOWN_ACTIVE_CHILD, active.parentNode);
243
244 if (dropdownChild) {
245 dropdownChild.classList.remove(CLASS_NAME_ACTIVE);
246 }
247
248 if (active.getAttribute('role') === 'tab') {
249 active.setAttribute('aria-selected', false);
250 }
251 }
252
253 element.classList.add(CLASS_NAME_ACTIVE);
254
255 if (element.getAttribute('role') === 'tab') {
256 element.setAttribute('aria-selected', true);
257 }
258
259 reflow(element);
260
261 if (element.classList.contains(CLASS_NAME_FADE)) {
262 element.classList.add(CLASS_NAME_SHOW);
263 }
264
265 let parent = element.parentNode;
266
267 if (parent && parent.nodeName === 'LI') {
268 parent = parent.parentNode;
269 }
270
271 if (parent && parent.classList.contains(CLASS_NAME_DROPDOWN_MENU)) {
272 const dropdownElement = element.closest(SELECTOR_DROPDOWN);
273
274 if (dropdownElement) {
275 SelectorEngine__default.default.find(SELECTOR_DROPDOWN_TOGGLE, dropdownElement).forEach(dropdown => dropdown.classList.add(CLASS_NAME_ACTIVE));
276 }
277
278 element.setAttribute('aria-expanded', true);
279 }
280
281 if (callback) {
282 callback();
283 }
284 } // Static
285
286
287 static jQueryInterface(config) {
288 return this.each(function () {
289 const data = Tab.getOrCreateInstance(this);
290
291 if (typeof config === 'string') {
292 if (typeof data[config] === 'undefined') {
293 throw new TypeError(`No method named "${config}"`);
294 }
295
296 data[config]();
297 }
298 });
299 }
300
301 }
302 /**
303 * ------------------------------------------------------------------------
304 * Data Api implementation
305 * ------------------------------------------------------------------------
306 */
307
308
309 EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
310 if (['A', 'AREA'].includes(this.tagName)) {
311 event.preventDefault();
312 }
313
314 if (isDisabled(this)) {
315 return;
316 }
317
318 const data = Tab.getOrCreateInstance(this);
319 data.show();
320 });
321 /**
322 * ------------------------------------------------------------------------
323 * jQuery
324 * ------------------------------------------------------------------------
325 * add .Tab to jQuery only if jQuery is present
326 */
327
328 defineJQueryPlugin(Tab);
329
330 return Tab;
331
332}));
333//# sourceMappingURL=tab.js.map
Note: See TracBrowser for help on using the repository browser.