diff options
Diffstat (limited to 'assets/javascripts/bootstrap/scrollspy.js')
-rw-r--r-- | assets/javascripts/bootstrap/scrollspy.js | 302 |
1 files changed, 145 insertions, 157 deletions
diff --git a/assets/javascripts/bootstrap/scrollspy.js b/assets/javascripts/bootstrap/scrollspy.js index 1dd9361..d5e4588 100644 --- a/assets/javascripts/bootstrap/scrollspy.js +++ b/assets/javascripts/bootstrap/scrollspy.js @@ -1,17 +1,17 @@ -'use strict'; +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.4): scrollspy.js + * Bootstrap (v4.0.0-alpha.5): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -var ScrollSpy = (function ($) { +var ScrollSpy = function ($) { /** * ------------------------------------------------------------------------ @@ -20,7 +20,7 @@ var ScrollSpy = (function ($) { */ var NAME = 'scrollspy'; - var VERSION = '4.0.0-alpha.4'; + var VERSION = '4.0.0-alpha.5'; var DATA_KEY = 'bs.scrollspy'; var EVENT_KEY = '.' + DATA_KEY; var DATA_API_KEY = '.data-api'; @@ -75,7 +75,7 @@ var ScrollSpy = (function ($) { * ------------------------------------------------------------------------ */ - var ScrollSpy = (function () { + var ScrollSpy = function () { function ScrollSpy(element, config) { _classCallCheck(this, ScrollSpy); @@ -94,192 +94,174 @@ var ScrollSpy = (function ($) { this._process(); } - /** - * ------------------------------------------------------------------------ - * Data Api implementation - * ------------------------------------------------------------------------ - */ - // getters - _createClass(ScrollSpy, [{ - key: 'refresh', + // public - // public + ScrollSpy.prototype.refresh = function refresh() { + var _this = this; - value: function refresh() { - var _this = this; + var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET; - var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET; + var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method; - var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method; + var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0; - var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0; + this._offsets = []; + this._targets = []; - this._offsets = []; - this._targets = []; + this._scrollHeight = this._getScrollHeight(); - this._scrollHeight = this._getScrollHeight(); + var targets = $.makeArray($(this._selector)); - var targets = $.makeArray($(this._selector)); + targets.map(function (element) { + var target = void 0; + var targetSelector = Util.getSelectorFromElement(element); - targets.map(function (element) { - var target = undefined; - var targetSelector = Util.getSelectorFromElement(element); + if (targetSelector) { + target = $(targetSelector)[0]; + } - if (targetSelector) { - target = $(targetSelector)[0]; - } + if (target && (target.offsetWidth || target.offsetHeight)) { + // todo (fat): remove sketch reliance on jQuery position/offset + return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; + } + return null; + }).filter(function (item) { + return item; + }).sort(function (a, b) { + return a[0] - b[0]; + }).forEach(function (item) { + _this._offsets.push(item[0]); + _this._targets.push(item[1]); + }); + }; + + ScrollSpy.prototype.dispose = function dispose() { + $.removeData(this._element, DATA_KEY); + $(this._scrollElement).off(EVENT_KEY); + + this._element = null; + this._scrollElement = null; + this._config = null; + this._selector = null; + this._offsets = null; + this._targets = null; + this._activeTarget = null; + this._scrollHeight = null; + }; - if (target && (target.offsetWidth || target.offsetHeight)) { - // todo (fat): remove sketch reliance on jQuery position/offset - return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; - } - return null; - }).filter(function (item) { - return item; - }).sort(function (a, b) { - return a[0] - b[0]; - }).forEach(function (item) { - _this._offsets.push(item[0]); - _this._targets.push(item[1]); - }); - } - }, { - key: 'dispose', - value: function dispose() { - $.removeData(this._element, DATA_KEY); - $(this._scrollElement).off(EVENT_KEY); - - this._element = null; - this._scrollElement = null; - this._config = null; - this._selector = null; - this._offsets = null; - this._targets = null; - this._activeTarget = null; - this._scrollHeight = null; - } + // private - // private + ScrollSpy.prototype._getConfig = function _getConfig(config) { + config = $.extend({}, Default, config); - }, { - key: '_getConfig', - 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; + 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; + } - Util.typeCheckConfig(NAME, config, DefaultType); + Util.typeCheckConfig(NAME, config, DefaultType); - return config; - } - }, { - key: '_getScrollTop', - value: function _getScrollTop() { - return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop; - } - }, { - key: '_getScrollHeight', - value: function _getScrollHeight() { - return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); + return config; + }; + + ScrollSpy.prototype._getScrollTop = function _getScrollTop() { + return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop; + }; + + ScrollSpy.prototype._getScrollHeight = function _getScrollHeight() { + return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); + }; + + 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; + + if (this._scrollHeight !== scrollHeight) { + this.refresh(); } - }, { - key: '_process', - value: function _process() { - var scrollTop = this._getScrollTop() + this._config.offset; - var scrollHeight = this._getScrollHeight(); - var maxScroll = this._config.offset + scrollHeight - this._scrollElement.offsetHeight; - - if (this._scrollHeight !== scrollHeight) { - this.refresh(); - } - if (scrollTop >= maxScroll) { - var target = this._targets[this._targets.length - 1]; + if (scrollTop >= maxScroll) { + var target = this._targets[this._targets.length - 1]; - if (this._activeTarget !== target) { - this._activate(target); - } + if (this._activeTarget !== target) { + this._activate(target); } + } - if (this._activeTarget && scrollTop < this._offsets[0]) { - this._activeTarget = null; - this._clear(); - return; - } + if (this._activeTarget && scrollTop < this._offsets[0]) { + this._activeTarget = null; + this._clear(); + return; + } - for (var i = this._offsets.length; i--;) { - var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (this._offsets[i + 1] === undefined || scrollTop < this._offsets[i + 1]); + for (var i = this._offsets.length; i--;) { + var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (this._offsets[i + 1] === undefined || scrollTop < this._offsets[i + 1]); - if (isActiveTarget) { - this._activate(this._targets[i]); - } + if (isActiveTarget) { + this._activate(this._targets[i]); } } - }, { - key: '_activate', - value: function _activate(target) { - this._activeTarget = target; + }; - this._clear(); + ScrollSpy.prototype._activate = function _activate(target) { + this._activeTarget = target; - var queries = this._selector.split(','); - queries = queries.map(function (selector) { - return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]'); - }); + this._clear(); - var $link = $(queries.join(',')); + var queries = this._selector.split(','); + queries = queries.map(function (selector) { + return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]'); + }); - if ($link.hasClass(ClassName.DROPDOWN_ITEM)) { - $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE); - $link.addClass(ClassName.ACTIVE); - } 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); - } + var $link = $(queries.join(',')); - $(this._scrollElement).trigger(Event.ACTIVATE, { - relatedTarget: target - }); - } - }, { - key: '_clear', - value: function _clear() { - $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE); + if ($link.hasClass(ClassName.DROPDOWN_ITEM)) { + $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE); + $link.addClass(ClassName.ACTIVE); + } 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); } - // static + $(this._scrollElement).trigger(Event.ACTIVATE, { + relatedTarget: target + }); + }; - }], [{ - key: '_jQueryInterface', - value: function _jQueryInterface(config) { - return this.each(function () { - var data = $(this).data(DATA_KEY); - var _config = typeof config === 'object' && config || null; + ScrollSpy.prototype._clear = function _clear() { + $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE); + }; - if (!data) { - data = new ScrollSpy(this, _config); - $(this).data(DATA_KEY, data); - } + // static - if (typeof config === 'string') { - if (data[config] === undefined) { - throw new Error('No method named "' + config + '"'); - } - data[config](); + 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; + + if (!data) { + data = new ScrollSpy(this, _config); + $(this).data(DATA_KEY, data); + } + + if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error('No method named "' + config + '"'); } - }); - } - }, { + data[config](); + } + }); + }; + + _createClass(ScrollSpy, null, [{ key: 'VERSION', get: function get() { return VERSION; @@ -292,7 +274,13 @@ var ScrollSpy = (function ($) { }]); return ScrollSpy; - })(); + }(); + + /** + * ------------------------------------------------------------------------ + * Data Api implementation + * ------------------------------------------------------------------------ + */ $(window).on(Event.LOAD_DATA_API, function () { var scrollSpys = $.makeArray($(Selector.DATA_SPY)); @@ -317,4 +305,4 @@ var ScrollSpy = (function ($) { }; return ScrollSpy; -})(jQuery); +}(jQuery); |