mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-03 02:13:01 +02:00
rewritten scrollspy without jquery
This commit is contained in:
committed by
XhmikosR
parent
9744886519
commit
0263d1742c
@@ -40,6 +40,22 @@ const Manipulator = {
|
||||
element.removeAttribute(`data-${key.replace(/[A-Z]/g, (chr) => `-${chr.toLowerCase()}`)}`)
|
||||
},
|
||||
|
||||
offset(element) {
|
||||
const rect = element.getBoundingClientRect()
|
||||
|
||||
return {
|
||||
top: rect.top + document.body.scrollTop,
|
||||
left: rect.left + document.body.scrollLeft
|
||||
}
|
||||
},
|
||||
|
||||
position(element) {
|
||||
return {
|
||||
top: element.offsetTop,
|
||||
left: element.offsetLeft
|
||||
}
|
||||
},
|
||||
|
||||
toggleClass(element, className) {
|
||||
if (typeof element === 'undefined' || element === null) {
|
||||
return
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
Reference in New Issue
Block a user