source: imaps-frontend/node_modules/bootstrap/js/dist/dom/selector-engine.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*!
2 * Bootstrap selector-engine.js v5.3.3 (https://getbootstrap.com/)
3 * Copyright 2011-2024 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('../util/index.js')) :
8 typeof define === 'function' && define.amd ? define(['../util/index'], factory) :
9 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SelectorEngine = factory(global.Index));
10})(this, (function (index_js) { 'use strict';
11
12 /**
13 * --------------------------------------------------------------------------
14 * Bootstrap dom/selector-engine.js
15 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
16 * --------------------------------------------------------------------------
17 */
18
19 const getSelector = element => {
20 let selector = element.getAttribute('data-bs-target');
21 if (!selector || selector === '#') {
22 let hrefAttribute = element.getAttribute('href');
23
24 // The only valid content that could double as a selector are IDs or classes,
25 // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
26 // `document.querySelector` will rightfully complain it is invalid.
27 // See https://github.com/twbs/bootstrap/issues/32273
28 if (!hrefAttribute || !hrefAttribute.includes('#') && !hrefAttribute.startsWith('.')) {
29 return null;
30 }
31
32 // Just in case some CMS puts out a full URL with the anchor appended
33 if (hrefAttribute.includes('#') && !hrefAttribute.startsWith('#')) {
34 hrefAttribute = `#${hrefAttribute.split('#')[1]}`;
35 }
36 selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null;
37 }
38 return selector ? selector.split(',').map(sel => index_js.parseSelector(sel)).join(',') : null;
39 };
40 const SelectorEngine = {
41 find(selector, element = document.documentElement) {
42 return [].concat(...Element.prototype.querySelectorAll.call(element, selector));
43 },
44 findOne(selector, element = document.documentElement) {
45 return Element.prototype.querySelector.call(element, selector);
46 },
47 children(element, selector) {
48 return [].concat(...element.children).filter(child => child.matches(selector));
49 },
50 parents(element, selector) {
51 const parents = [];
52 let ancestor = element.parentNode.closest(selector);
53 while (ancestor) {
54 parents.push(ancestor);
55 ancestor = ancestor.parentNode.closest(selector);
56 }
57 return parents;
58 },
59 prev(element, selector) {
60 let previous = element.previousElementSibling;
61 while (previous) {
62 if (previous.matches(selector)) {
63 return [previous];
64 }
65 previous = previous.previousElementSibling;
66 }
67 return [];
68 },
69 // TODO: this is now unused; remove later along with prev()
70 next(element, selector) {
71 let next = element.nextElementSibling;
72 while (next) {
73 if (next.matches(selector)) {
74 return [next];
75 }
76 next = next.nextElementSibling;
77 }
78 return [];
79 },
80 focusableChildren(element) {
81 const focusables = ['a', 'button', 'input', 'textarea', 'select', 'details', '[tabindex]', '[contenteditable="true"]'].map(selector => `${selector}:not([tabindex^="-"])`).join(',');
82 return this.find(focusables, element).filter(el => !index_js.isDisabled(el) && index_js.isVisible(el));
83 },
84 getSelectorFromElement(element) {
85 const selector = getSelector(element);
86 if (selector) {
87 return SelectorEngine.findOne(selector) ? selector : null;
88 }
89 return null;
90 },
91 getElementFromSelector(element) {
92 const selector = getSelector(element);
93 return selector ? SelectorEngine.findOne(selector) : null;
94 },
95 getMultipleElementsFromSelector(element) {
96 const selector = getSelector(element);
97 return selector ? SelectorEngine.find(selector) : [];
98 }
99 };
100
101 return SelectorEngine;
102
103}));
104//# sourceMappingURL=selector-engine.js.map
Note: See TracBrowser for help on using the repository browser.