From 0263d1742ce8ad25f0f2de30beebae69b2f55f10 Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Mon, 25 Sep 2017 09:09:01 +0200 Subject: rewritten scrollspy without jquery --- js/src/dom/selectorEngine.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'js/src/dom/selectorEngine.js') 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 } } })() -- cgit v1.2.3