Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap-rubygem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Mazovetskiy <glex.spb@gmail.com>2017-09-11 17:23:33 +0300
committerGleb Mazovetskiy <glex.spb@gmail.com>2017-09-11 17:23:33 +0300
commiteb2e1a606e2c3324e7c511ba07c5ba0195801b00 (patch)
tree37c6441979f159dc13e6021fdc5322a42f374099 /assets/javascripts/bootstrap/scrollspy.js
parentb12fdcd48c26cee905c3365626247f452fb941f2 (diff)
rake update[v4-dev]
Diffstat (limited to 'assets/javascripts/bootstrap/scrollspy.js')
-rw-r--r--assets/javascripts/bootstrap/scrollspy.js313
1 files changed, 165 insertions, 148 deletions
diff --git a/assets/javascripts/bootstrap/scrollspy.js b/assets/javascripts/bootstrap/scrollspy.js
index 7eaaeb3..18bdfce 100644
--- a/assets/javascripts/bootstrap/scrollspy.js
+++ b/assets/javascripts/bootstrap/scrollspy.js
@@ -1,3 +1,5 @@
+'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; }; }();
@@ -11,7 +13,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
* --------------------------------------------------------------------------
*/
-var ScrollSpy = function ($) {
+var ScrollSpy = function () {
/**
* ------------------------------------------------------------------------
@@ -64,14 +66,14 @@ var ScrollSpy = function ($) {
var OffsetMethod = {
OFFSET: 'offset',
POSITION: 'position'
+ };
- /**
- * ------------------------------------------------------------------------
- * Class Definition
- * ------------------------------------------------------------------------
- */
+ /**
+ * ------------------------------------------------------------------------
+ * Class Definition
+ * ------------------------------------------------------------------------
+ */
- };
var ScrollSpy = function () {
function ScrollSpy(element, config) {
var _this = this;
@@ -97,182 +99,197 @@ var ScrollSpy = function ($) {
// getters
- // public
+ _createClass(ScrollSpy, [{
+ key: 'refresh',
- ScrollSpy.prototype.refresh = function refresh() {
- var _this2 = this;
- var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET;
+ // public
- var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method;
+ value: function refresh() {
+ var _this2 = this;
- var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0;
+ var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET;
- this._offsets = [];
- this._targets = [];
-
- this._scrollHeight = this._getScrollHeight();
+ var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method;
- var targets = $.makeArray($(this._selector));
+ var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0;
- targets.map(function (element) {
- var target = void 0;
- var targetSelector = Util.getSelectorFromElement(element);
+ this._offsets = [];
+ this._targets = [];
- if (targetSelector) {
- target = $(targetSelector)[0];
- }
+ this._scrollHeight = this._getScrollHeight();
- if (target) {
- var targetBCR = target.getBoundingClientRect();
- if (targetBCR.width || targetBCR.height) {
- // 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) {
- _this2._offsets.push(item[0]);
- _this2._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;
- };
+ var targets = $.makeArray($(this._selector));
- // private
+ targets.map(function (element) {
+ var target = void 0;
+ var targetSelector = Util.getSelectorFromElement(element);
- ScrollSpy.prototype._getConfig = function _getConfig(config) {
- config = $.extend({}, Default, config);
+ if (targetSelector) {
+ target = $(targetSelector)[0];
+ }
- 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 (target) {
+ var targetBCR = target.getBoundingClientRect();
+ if (targetBCR.width || targetBCR.height) {
+ // 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) {
+ _this2._offsets.push(item[0]);
+ _this2._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;
}
- Util.typeCheckConfig(NAME, config, DefaultType);
-
- return config;
- };
-
- ScrollSpy.prototype._getScrollTop = function _getScrollTop() {
- 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);
- };
+ // private
- ScrollSpy.prototype._getOffsetHeight = function _getOffsetHeight() {
- return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height;
- };
+ }, {
+ 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;
+ }
- ScrollSpy.prototype._process = function _process() {
- var scrollTop = this._getScrollTop() + this._config.offset;
- var scrollHeight = this._getScrollHeight();
- var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight();
+ Util.typeCheckConfig(NAME, config, DefaultType);
- if (this._scrollHeight !== scrollHeight) {
- this.refresh();
+ return config;
}
-
- if (scrollTop >= maxScroll) {
- var target = this._targets[this._targets.length - 1];
-
- if (this._activeTarget !== target) {
- this._activate(target);
- }
- return;
+ }, {
+ key: '_getScrollTop',
+ value: function _getScrollTop() {
+ return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop;
}
-
- if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
- this._activeTarget = null;
- this._clear();
- return;
+ }, {
+ key: '_getScrollHeight',
+ value: function _getScrollHeight() {
+ return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
+ }
+ }, {
+ key: '_getOffsetHeight',
+ value: function _getOffsetHeight() {
+ return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height;
}
+ }, {
+ key: '_process',
+ value: function _process() {
+ var scrollTop = this._getScrollTop() + this._config.offset;
+ var scrollHeight = this._getScrollHeight();
+ var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight();
+
+ if (this._scrollHeight !== scrollHeight) {
+ this.refresh();
+ }
- 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 (scrollTop >= maxScroll) {
+ var target = this._targets[this._targets.length - 1];
- if (isActiveTarget) {
- this._activate(this._targets[i]);
+ if (this._activeTarget !== target) {
+ this._activate(target);
+ }
+ return;
}
- }
- };
-
- ScrollSpy.prototype._activate = function _activate(target) {
- this._activeTarget = target;
- this._clear();
+ if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
+ this._activeTarget = null;
+ this._clear();
+ return;
+ }
- var queries = this._selector.split(',');
- queries = queries.map(function (selector) {
- return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]');
- });
+ for (var i = this._offsets.length; i--;) {
+ var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]);
- var $link = $(queries.join(','));
-
- if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
- $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
- $link.addClass(ClassName.ACTIVE);
- } else {
- // Set triggered link as active
- $link.addClass(ClassName.ACTIVE);
- // Set triggered links parents as active
- // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
- $link.parents(Selector.NAV_LIST_GROUP).prev(Selector.NAV_LINKS + ', ' + Selector.LIST_ITEMS).addClass(ClassName.ACTIVE);
+ if (isActiveTarget) {
+ this._activate(this._targets[i]);
+ }
+ }
}
+ }, {
+ key: '_activate',
+ value: function _activate(target) {
+ this._activeTarget = target;
- $(this._scrollElement).trigger(Event.ACTIVATE, {
- relatedTarget: target
- });
- };
+ this._clear();
- ScrollSpy.prototype._clear = function _clear() {
- $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
- };
+ var queries = this._selector.split(',');
+ // eslint-disable-next-line arrow-body-style
+ queries = queries.map(function (selector) {
+ return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]');
+ });
+
+ var $link = $(queries.join(','));
+
+ if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
+ $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
+ $link.addClass(ClassName.ACTIVE);
+ } else {
+ // Set triggered link as active
+ $link.addClass(ClassName.ACTIVE);
+ // Set triggered links parents as active
+ // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
+ $link.parents(Selector.NAV_LIST_GROUP).prev(Selector.NAV_LINKS + ', ' + Selector.LIST_ITEMS).addClass(ClassName.ACTIVE);
+ }
- // static
+ $(this._scrollElement).trigger(Event.ACTIVATE, {
+ relatedTarget: target
+ });
+ }
+ }, {
+ key: '_clear',
+ value: function _clear() {
+ $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
+ }
- 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;
+ // static
- if (!data) {
- data = new ScrollSpy(this, _config);
- $(this).data(DATA_KEY, data);
- }
+ }], [{
+ key: '_jQueryInterface',
+ value: function _jQueryInterface(config) {
+ return this.each(function () {
+ var data = $(this).data(DATA_KEY);
+ var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config;
- if (typeof config === 'string') {
- if (data[config] === undefined) {
- throw new Error('No method named "' + config + '"');
+ if (!data) {
+ data = new ScrollSpy(this, _config);
+ $(this).data(DATA_KEY, data);
}
- data[config]();
- }
- });
- };
- _createClass(ScrollSpy, null, [{
+ if (typeof config === 'string') {
+ if (typeof data[config] === 'undefined') {
+ throw new Error('No method named "' + config + '"');
+ }
+ data[config]();
+ }
+ });
+ }
+ }, {
key: 'VERSION',
get: function get() {
return VERSION;