mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-27 07:14:36 +02:00
Extract Component config functionality to a separate class (#33872)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user