Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollspy.js: chain functions #35139

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, should have been target but well...

this._offsets.push(item[0])
this._targets.push(item[1])
}
Expand Down