diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-12-10 19:18:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 19:18:18 +0300 |
commit | 886b940796b3595a03b44230ca8b78197c5ee1c5 (patch) | |
tree | 6b37d0208ae9fd9816e052572ab3496095cc88b6 /js/src/scrollspy.js | |
parent | 68f226750db03bc26ed5ead6bb074804a4f63853 (diff) |
Extract Component config functionality to a separate class (#33872)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Diffstat (limited to 'js/src/scrollspy.js')
-rw-r--r-- | js/src/scrollspy.js | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 27bc0cd877..dc082a1b3a 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -8,8 +8,7 @@ import { defineJQueryPlugin, getElement, - getSelectorFromElement, - typeCheckConfig + getSelectorFromElement } from './util/index' import EventHandler from './dom/event-handler' import Manipulator from './dom/manipulator' @@ -62,9 +61,8 @@ const DefaultType = { class ScrollSpy extends BaseComponent { constructor(element, config) { - super(element) + super(element, config) this._scrollElement = this._element.tagName === 'BODY' ? window : this._element - this._config = this._getConfig(config) this._offsets = [] this._targets = [] this._activeTarget = null @@ -81,6 +79,10 @@ class ScrollSpy extends BaseComponent { return Default } + static get DefaultType() { + return DefaultType + } + static get NAME() { return NAME } @@ -135,17 +137,10 @@ class ScrollSpy extends BaseComponent { } // Private - _getConfig(config) { - config = { - ...Default, - ...Manipulator.getDataAttributes(this._element), - ...(typeof config === 'object' && config ? config : {}) - } + _configAfterMerge(config) { config.target = getElement(config.target) || document.documentElement - typeCheckConfig(NAME, config, DefaultType) - return config } |