From eb0f705621a044d25d6de0e5d1b4dde306b5004d Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 8 Oct 2021 12:28:05 +0300 Subject: [PATCH] scrollspy.js: chain functions (#35139) --- js/src/scrollspy.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index df9a14e220..e0e2e9bf91 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -110,25 +110,26 @@ class ScrollSpy extends BaseComponent { this._scrollHeight = this._getScrollHeight() const targets = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target) + .map(element => { + const targetSelector = getSelectorFromElement(element) + const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null - 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 - ] + 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]) }