diff options
| author | Alessandro Chitolina <[email protected]> | 2017-09-25 09:09:01 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-20 22:05:45 +0200 |
| commit | 0263d1742ce8ad25f0f2de30beebae69b2f55f10 (patch) | |
| tree | 4f3d1b376f0050c2a74addebd32341b45d0ec38a /js/src/dom/selectorEngine.js | |
| parent | 9744886519a834deba45b1cadbb0603ac2446102 (diff) | |
| download | bootstrap-0263d1742ce8ad25f0f2de30beebae69b2f55f10.tar.xz bootstrap-0263d1742ce8ad25f0f2de30beebae69b2f55f10.zip | |
rewritten scrollspy without jquery
Diffstat (limited to 'js/src/dom/selectorEngine.js')
| -rw-r--r-- | js/src/dom/selectorEngine.js | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/js/src/dom/selectorEngine.js b/js/src/dom/selectorEngine.js index a3e88ad6e..e51516445 100644 --- a/js/src/dom/selectorEngine.js +++ b/js/src/dom/selectorEngine.js @@ -111,10 +111,6 @@ const SelectorEngine = (() => { return null } - if (selector.indexOf('#') === 0) { - return SelectorEngine.findOne(selector, element) - } - return findFn.call(element, selector) }, @@ -135,8 +131,46 @@ const SelectorEngine = (() => { return children.filter((child) => this.matches(child, selector)) }, + parents(element, selector) { + if (typeof selector !== 'string') { + return null + } + + const parents = [] + + let ancestor = element.parentNode + while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE) { + if (fnMatches.call(ancestor, selector)) { + parents.push(ancestor) + } + + ancestor = ancestor.parentNode + } + + return parents + }, + closest(element, selector) { return fnClosest(element, selector) + }, + + prev(element, selector) { + if (typeof selector !== 'string') { + return null + } + + const siblings = [] + + let previous = element.previousSibling + while (previous) { + if (fnMatches.call(previous, selector)) { + siblings.push(previous) + } + + previous = previous.previousSibling + } + + return siblings } } })() |
