diff --git a/js/dist/modal.js b/js/dist/modal.js index 25292b275..80a493777 100644 --- a/js/dist/modal.js +++ b/js/dist/modal.js @@ -31,6 +31,7 @@ var Modal = (function ($) { var Default = { backdrop: true, keyboard: true, + focus: true, show: true }; @@ -206,14 +207,14 @@ var Modal = (function ($) { $(this._element).addClass(ClassName.IN); - this._enforceFocus(); + if (this._config.focus) this._enforceFocus(); var shownEvent = $.Event(Event.SHOWN, { relatedTarget: relatedTarget }); var transitionComplete = function transitionComplete() { - _this2._element.focus(); + if (_this2._config.focus) _this2._element.focus(); $(_this2._element).trigger(shownEvent); }; diff --git a/js/dist/modal.js.map b/js/dist/modal.js.map index bbdbb1d45..247fbab7d 100644 Binary files a/js/dist/modal.js.map and b/js/dist/modal.js.map differ diff --git a/js/dist/scrollspy.js b/js/dist/scrollspy.js index 69fc579ed..47774a95b 100644 --- a/js/dist/scrollspy.js +++ b/js/dist/scrollspy.js @@ -28,7 +28,8 @@ var ScrollSpy = (function ($) { var Default = { offset: 10, - method: 'auto' + method: 'auto', + target: '' }; var Event = { @@ -45,8 +46,9 @@ var ScrollSpy = (function ($) { var Selector = { DATA_SPY: '[data-spy="scroll"]', ACTIVE: '.active', + LI: 'li', LI_DROPDOWN: 'li.dropdown', - LI: 'li' + NAV_ANCHORS: '.nav li > a' }; var OffsetMethod = { @@ -66,8 +68,8 @@ var ScrollSpy = (function ($) { 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; @@ -137,10 +139,26 @@ var ScrollSpy = (function ($) { this._scrollHeight = null; } }, { - key: '_getScrollTop', + key: '_getConfig', // private + value: function _getConfig(config) { + config = $.extend({}, Default, config); + + if (typeof config.target !== 'string') { + var id = $(config.target).attr('id'); + if (!id) { + id = Util.getUID(NAME); + $(config.target).attr('id', id); + } + config.target = '#' + id; + } + + return config; + } + }, { + key: '_getScrollTop', value: function _getScrollTop() { return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop; } diff --git a/js/dist/scrollspy.js.map b/js/dist/scrollspy.js.map index 98292c7fd..3f2a3c41f 100644 Binary files a/js/dist/scrollspy.js.map and b/js/dist/scrollspy.js.map differ 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 diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index bf963b3ab..a4407ece9 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -77,6 +77,51 @@ $(function () { $scrollspy.scrollTop(350) }) + QUnit.test('should only switch "active" class on current target specified w element', function (assert) { + assert.expect(1) + var done = assert.async() + + var sectionHTML = '
' + + 'Ad leggings keytar, brunch id art party dolor labore.' + + '
' + + '' + + 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + + '
' + + '