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-05-29 16:41:20 +0300
committerGleb Mazovetskiy <glex.spb@gmail.com>2017-05-29 16:41:20 +0300
commit096ade49a5ceff46c2db7f1b2aa5399853a2cb4a (patch)
tree7d11585f02203cde800143b4f2758105c29e34ac /assets/javascripts/bootstrap/scrollspy.js
parent9b92e0095994e5f26be8ce4a910e3701d277b6a0 (diff)
rake update[v4-dev]
Diffstat (limited to 'assets/javascripts/bootstrap/scrollspy.js')
-rw-r--r--assets/javascripts/bootstrap/scrollspy.js29
1 files changed, 16 insertions, 13 deletions
diff --git a/assets/javascripts/bootstrap/scrollspy.js b/assets/javascripts/bootstrap/scrollspy.js
index e2ee2e3..a332f96 100644
--- a/assets/javascripts/bootstrap/scrollspy.js
+++ b/assets/javascripts/bootstrap/scrollspy.js
@@ -47,18 +47,15 @@ var ScrollSpy = function ($) {
var ClassName = {
DROPDOWN_ITEM: 'dropdown-item',
DROPDOWN_MENU: 'dropdown-menu',
- NAV_LINK: 'nav-link',
- NAV: 'nav',
ACTIVE: 'active'
};
var Selector = {
DATA_SPY: '[data-spy="scroll"]',
ACTIVE: '.active',
- LIST_ITEM: '.list-item',
- LI: 'li',
- LI_DROPDOWN: 'li.dropdown',
+ NAV_LIST_GROUP: '.nav, .list-group',
NAV_LINKS: '.nav-link',
+ LIST_ITEMS: '.list-group-item',
DROPDOWN: '.dropdown',
DROPDOWN_ITEMS: '.dropdown-item',
DROPDOWN_TOGGLE: '.dropdown-toggle'
@@ -84,7 +81,7 @@ var ScrollSpy = function ($) {
this._element = element;
this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = this._getConfig(config);
- this._selector = this._config.target + ' ' + Selector.NAV_LINKS + ',' + (this._config.target + ' ' + Selector.DROPDOWN_ITEMS);
+ this._selector = this._config.target + ' ' + Selector.NAV_LINKS + ',' + (this._config.target + ' ' + Selector.LIST_ITEMS + ',') + (this._config.target + ' ' + Selector.DROPDOWN_ITEMS);
this._offsets = [];
this._targets = [];
this._activeTarget = null;
@@ -126,9 +123,12 @@ var ScrollSpy = function ($) {
target = $(targetSelector)[0];
}
- if (target && (target.offsetWidth || target.offsetHeight)) {
- // todo (fat): remove sketch reliance on jQuery position/offset
- return [$(target)[offsetMethod]().top + offsetBase, targetSelector];
+ 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) {
@@ -183,7 +183,7 @@ var ScrollSpy = function ($) {
};
ScrollSpy.prototype._getOffsetHeight = function _getOffsetHeight() {
- return this._scrollElement === window ? window.innerHeight : this._scrollElement.offsetHeight;
+ return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height;
};
ScrollSpy.prototype._process = function _process() {
@@ -235,9 +235,11 @@ var ScrollSpy = function ($) {
$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);
+ // 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);
}
$(this._scrollElement).trigger(Event.ACTIVATE, {
@@ -315,3 +317,4 @@ var ScrollSpy = function ($) {
return ScrollSpy;
}(jQuery);
+//# sourceMappingURL=scrollspy.js.map \ No newline at end of file