2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-02 16:04:07 +03:00

rewritten scrollspy without jquery

This commit is contained in:
Alessandro Chitolina
2017-09-25 09:09:01 +02:00
committed by XhmikosR
parent 9744886519
commit 0263d1742c
5 changed files with 117 additions and 49 deletions
+38 -4
View File
@@ -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
}
}
})()