mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 06:36:33 +02:00
fix #15301
This commit is contained in:
@@ -217,7 +217,7 @@ const Modal = (($) => {
|
||||
|
||||
$(this._element).addClass(ClassName.IN)
|
||||
|
||||
this._enforceFocus()
|
||||
if (this._config.focus) this._enforceFocus()
|
||||
|
||||
let shownEvent = $.Event(Event.SHOWN, {
|
||||
relatedTarget: relatedTarget
|
||||
|
@@ -26,7 +26,8 @@ const ScrollSpy = (($) => {
|
||||
|
||||
const Default = {
|
||||
offset : 10,
|
||||
method : 'auto'
|
||||
method : 'auto',
|
||||
target : ''
|
||||
}
|
||||
|
||||
const Event = {
|
||||
@@ -43,8 +44,9 @@ const ScrollSpy = (($) => {
|
||||
const Selector = {
|
||||
DATA_SPY : '[data-spy="scroll"]',
|
||||
ACTIVE : '.active',
|
||||
LI : 'li',
|
||||
LI_DROPDOWN : 'li.dropdown',
|
||||
LI : 'li'
|
||||
NAV_ANCHORS : '.nav li > a'
|
||||
}
|
||||
|
||||
const OffsetMethod = {
|
||||
@@ -64,8 +66,8 @@ const ScrollSpy = (($) => {
|
||||
constructor(element, config) {
|
||||
this._element = element
|
||||
this._scrollElement = element.tagName === 'BODY' ? window : element
|
||||
this._config = $.extend({}, Default, config)
|
||||
this._selector = `${this._config.target || ''} .nav li > a`
|
||||
this._config = this._getConfig(config)
|
||||
this._selector = `${this._config.target} ${Selector.NAV_ANCHORS}`
|
||||
this._offsets = []
|
||||
this._targets = []
|
||||
this._activeTarget = null
|
||||
@@ -150,6 +152,21 @@ const ScrollSpy = (($) => {
|
||||
|
||||
// private
|
||||
|
||||
_getConfig(config) {
|
||||
config = $.extend({}, Default, config)
|
||||
|
||||
if (typeof config.target !== 'string') {
|
||||
let id = $(config.target).attr('id')
|
||||
if (!id) {
|
||||
id = Util.getUID(NAME)
|
||||
$(config.target).attr('id', id)
|
||||
}
|
||||
config.target = `#${id}`
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
_getScrollTop() {
|
||||
return this._scrollElement === window ?
|
||||
this._scrollElement.scrollY : this._scrollElement.scrollTop
|
||||
|
Reference in New Issue
Block a user