diff options
| author | fat <[email protected]> | 2015-05-13 13:43:56 -0700 |
|---|---|---|
| committer | fat <[email protected]> | 2015-05-13 13:43:56 -0700 |
| commit | b0d142334f0d15e63577b28e2d7045c2199dcd6a (patch) | |
| tree | 6fe7abb420ee0ea4bc4cc100a8410f300967b570 /js/src | |
| parent | 7ef0e52fd042da2fdf107a3347abab3486a67790 (diff) | |
| download | bootstrap-b0d142334f0d15e63577b28e2d7045c2199dcd6a.tar.xz bootstrap-b0d142334f0d15e63577b28e2d7045c2199dcd6a.zip | |
fix #15301
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/modal.js | 2 | ||||
| -rw-r--r-- | js/src/scrollspy.js | 25 |
2 files changed, 22 insertions, 5 deletions
diff --git a/js/src/modal.js b/js/src/modal.js index 88a3c8950..084c4ec3a 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -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 diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 3f4a145a1..bb639f91b 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -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 |
