diff options
| author | Johann-S <[email protected]> | 2021-02-17 08:22:44 +0100 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2021-09-15 16:42:04 +0200 |
| commit | d73d835380f793ab7ca40b82a6ce09ba8f5946c5 (patch) | |
| tree | 7c98a87a596ae937983498980afb6e2fa239ab53 /js/src/scrollspy.js | |
| parent | bdfb4cc54d29c0c7bcd7944d3c8de2e1cd41bb6c (diff) | |
| download | bootstrap-jo-ssr-friendly.tar.xz bootstrap-jo-ssr-friendly.zip | |
being ssr friendly when accessing dom objectsjo-ssr-friendly
Diffstat (limited to 'js/src/scrollspy.js')
| -rw-r--r-- | js/src/scrollspy.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 6ac00fedd..0bcbaa88e 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -9,7 +9,8 @@ import { defineJQueryPlugin, getElement, getSelectorFromElement, - typeCheckConfig + typeCheckConfig, + getWindow } from './util/index' import EventHandler from './dom/event-handler' import Manipulator from './dom/manipulator' @@ -67,7 +68,7 @@ const METHOD_POSITION = 'position' class ScrollSpy extends BaseComponent { constructor(element, config) { super(element) - this._scrollElement = this._element.tagName === 'BODY' ? window : this._element + this._scrollElement = this._element.tagName === 'BODY' ? this._window : this._element this._config = this._getConfig(config) this._offsets = [] this._targets = [] @@ -164,14 +165,14 @@ class ScrollSpy extends BaseComponent { _getScrollHeight() { return this._scrollElement.scrollHeight || Math.max( - document.body.scrollHeight, - document.documentElement.scrollHeight + this._document.body.scrollHeight, + this._document.documentElement.scrollHeight ) } _getOffsetHeight() { return this._scrollElement === window ? - window.innerHeight : + this._window.innerHeight : this._scrollElement.getBoundingClientRect().height } @@ -278,7 +279,7 @@ class ScrollSpy extends BaseComponent { * ------------------------------------------------------------------------ */ -EventHandler.on(window, EVENT_LOAD_DATA_API, () => { +EventHandler.on(getWindow(), EVENT_LOAD_DATA_API, () => { SelectorEngine.find(SELECTOR_DATA_SPY) .forEach(spy => new ScrollSpy(spy)) }) |
