Skip to content

Commit

Permalink
scrollspy.js: move code
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Oct 7, 2021
1 parent 8828df2 commit 6279ea4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,26 @@ class ScrollSpy extends BaseComponent {
this._scrollHeight = this._getScrollHeight()

const targets = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)

for (const item of targets.map(element => {
const targetSelector = getSelectorFromElement(element)
const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null

if (target) {
const targetBCR = target.getBoundingClientRect()
if (targetBCR.width || targetBCR.height) {
return [
Manipulator[offsetMethod](target).top + offsetBase,
targetSelector
]
.map(element => {
const targetSelector = getSelectorFromElement(element)
const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null

if (target) {
const targetBCR = target.getBoundingClientRect()
if (targetBCR.width || targetBCR.height) {
return [
Manipulator[offsetMethod](target).top + offsetBase,
targetSelector
]
}
}
}

return null
})
.filter(item => item)
.sort((a, b) => a[0] - b[0])) {
return null
})
.filter(item => item)
.sort((a, b) => a[0] - b[0])

for (const item of targets) {
this._offsets.push(item[0])
this._targets.push(item[1])
}
Expand Down

0 comments on commit 6279ea4

Please sign in to comment.