diff options
Diffstat (limited to 'assets/javascripts/bootstrap/scrollspy.js')
-rw-r--r-- | assets/javascripts/bootstrap/scrollspy.js | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/assets/javascripts/bootstrap/scrollspy.js b/assets/javascripts/bootstrap/scrollspy.js index d5e4588..e2ee2e3 100644 --- a/assets/javascripts/bootstrap/scrollspy.js +++ b/assets/javascripts/bootstrap/scrollspy.js @@ -6,7 +6,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.5): scrollspy.js + * Bootstrap (v4.0.0-alpha.6): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ @@ -20,7 +20,7 @@ var ScrollSpy = function ($) { */ var NAME = 'scrollspy'; - var VERSION = '4.0.0-alpha.5'; + var VERSION = '4.0.0-alpha.6'; var DATA_KEY = 'bs.scrollspy'; var EVENT_KEY = '.' + DATA_KEY; var DATA_API_KEY = '.data-api'; @@ -77,6 +77,8 @@ var ScrollSpy = function ($) { var ScrollSpy = function () { function ScrollSpy(element, config) { + var _this = this; + _classCallCheck(this, ScrollSpy); this._element = element; @@ -88,7 +90,9 @@ var ScrollSpy = function ($) { this._activeTarget = null; this._scrollHeight = 0; - $(this._scrollElement).on(Event.SCROLL, $.proxy(this._process, this)); + $(this._scrollElement).on(Event.SCROLL, function (event) { + return _this._process(event); + }); this.refresh(); this._process(); @@ -99,7 +103,7 @@ var ScrollSpy = function ($) { // public ScrollSpy.prototype.refresh = function refresh() { - var _this = this; + var _this2 = this; var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET; @@ -132,8 +136,8 @@ var ScrollSpy = function ($) { }).sort(function (a, b) { return a[0] - b[0]; }).forEach(function (item) { - _this._offsets.push(item[0]); - _this._targets.push(item[1]); + _this2._offsets.push(item[0]); + _this2._targets.push(item[1]); }); }; @@ -171,17 +175,21 @@ var ScrollSpy = function ($) { }; ScrollSpy.prototype._getScrollTop = function _getScrollTop() { - return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop; + return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop; }; ScrollSpy.prototype._getScrollHeight = function _getScrollHeight() { return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); }; + ScrollSpy.prototype._getOffsetHeight = function _getOffsetHeight() { + return this._scrollElement === window ? window.innerHeight : this._scrollElement.offsetHeight; + }; + ScrollSpy.prototype._process = function _process() { var scrollTop = this._getScrollTop() + this._config.offset; var scrollHeight = this._getScrollHeight(); - var maxScroll = this._config.offset + scrollHeight - this._scrollElement.offsetHeight; + var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight(); if (this._scrollHeight !== scrollHeight) { this.refresh(); @@ -193,9 +201,10 @@ var ScrollSpy = function ($) { if (this._activeTarget !== target) { this._activate(target); } + return; } - if (this._activeTarget && scrollTop < this._offsets[0]) { + if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) { this._activeTarget = null; this._clear(); return; @@ -228,7 +237,7 @@ var ScrollSpy = function ($) { } else { // todo (fat) this is kinda sus... // recursively add actives to tested nav-links - $link.parents(Selector.LI).find(Selector.NAV_LINKS).addClass(ClassName.ACTIVE); + $link.parents(Selector.LI).find('> ' + Selector.NAV_LINKS).addClass(ClassName.ACTIVE); } $(this._scrollElement).trigger(Event.ACTIVATE, { @@ -245,7 +254,7 @@ var ScrollSpy = function ($) { ScrollSpy._jQueryInterface = function _jQueryInterface(config) { return this.each(function () { var data = $(this).data(DATA_KEY); - var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config || null; + var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config; if (!data) { data = new ScrollSpy(this, _config); |