app/assets/javascripts/twitter/bootstrap/scrollspy.js in less-rails-bootstrap-3.0.6 vs app/assets/javascripts/twitter/bootstrap/scrollspy.js in less-rails-bootstrap-3.1.0.0

- old
+ new

@@ -1,26 +1,16 @@ /* ======================================================================== - * Bootstrap: scrollspy.js v3.0.3 + * Bootstrap: scrollspy.js v3.1.0 * http://getbootstrap.com/javascript/#scrollspy * ======================================================================== - * Copyright 2013 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ -+function ($) { "use strict"; ++function ($) { + 'use strict'; // SCROLLSPY CLASS DEFINITION // ========================== function ScrollSpy(element, options) { @@ -56,14 +46,15 @@ var $targets = this.$body .find(this.selector) .map(function () { var $el = $(this) var href = $el.data('target') || $el.attr('href') - var $href = /^#\w/.test(href) && $(href) + var $href = /^#./.test(href) && $(href) return ($href && $href.length + && $href.is(':visible') && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { self.offsets.push(this[0]) @@ -82,10 +73,14 @@ if (scrollTop >= maxScroll) { return activeTarget != (i = targets.last()[0]) && this.activate(i) } + if (activeTarget && scrollTop <= offsets[0]) { + return activeTarget != (i = targets[0]) && this.activate(i) + } + for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) && this.activate( targets[i] ) @@ -94,21 +89,21 @@ ScrollSpy.prototype.activate = function (target) { this.activeTarget = target $(this.selector) - .parents('.active') + .parentsUntil(this.options.target, '.active') .removeClass('active') - var selector = this.selector - + '[data-target="' + target + '"],' - + this.selector + '[href="' + target + '"]' + var selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' var active = $(selector) .parents('li') .addClass('active') - if (active.parent('.dropdown-menu').length) { + if (active.parent('.dropdown-menu').length) { active = active .closest('li.dropdown') .addClass('active') }