info@54: /* ======================================================================== info@54: * Bootstrap: scrollspy.js v3.0.3 info@54: * http://getbootstrap.com/javascript/#scrollspy info@54: * ======================================================================== info@54: * Copyright 2013 Twitter, Inc. info@54: * info@54: * Licensed under the Apache License, Version 2.0 (the "License"); info@54: * you may not use this file except in compliance with the License. info@54: * You may obtain a copy of the License at info@54: * info@54: * http://www.apache.org/licenses/LICENSE-2.0 info@54: * info@54: * Unless required by applicable law or agreed to in writing, software info@54: * distributed under the License is distributed on an "AS IS" BASIS, info@54: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. info@54: * See the License for the specific language governing permissions and info@54: * limitations under the License. info@54: * ======================================================================== */ info@54: info@54: info@54: +function ($) { "use strict"; info@54: info@54: // SCROLLSPY CLASS DEFINITION info@54: // ========================== info@54: info@54: function ScrollSpy(element, options) { info@54: var href info@54: var process = $.proxy(this.process, this) info@54: info@54: this.$element = $(element).is('body') ? $(window) : $(element) info@54: this.$body = $('body') info@54: this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process) info@54: this.options = $.extend({}, ScrollSpy.DEFAULTS, options) info@54: this.selector = (this.options.target info@54: || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 info@54: || '') + ' .nav li > a' info@54: this.offsets = $([]) info@54: this.targets = $([]) info@54: this.activeTarget = null info@54: info@54: this.refresh() info@54: this.process() info@54: } info@54: info@54: ScrollSpy.DEFAULTS = { info@54: offset: 10 info@54: } info@54: info@54: ScrollSpy.prototype.refresh = function () { info@54: var offsetMethod = this.$element[0] == window ? 'offset' : 'position' info@54: info@54: this.offsets = $([]) info@54: this.targets = $([]) info@54: info@54: var self = this info@54: var $targets = this.$body info@54: .find(this.selector) info@54: .map(function () { info@54: var $el = $(this) info@54: var href = $el.data('target') || $el.attr('href') info@54: var $href = /^#\w/.test(href) && $(href) info@54: info@54: return ($href info@54: && $href.length info@54: && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null info@54: }) info@54: .sort(function (a, b) { return a[0] - b[0] }) info@54: .each(function () { info@54: self.offsets.push(this[0]) info@54: self.targets.push(this[1]) info@54: }) info@54: } info@54: info@54: ScrollSpy.prototype.process = function () { info@54: var scrollTop = this.$scrollElement.scrollTop() + this.options.offset info@54: var scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight info@54: var maxScroll = scrollHeight - this.$scrollElement.height() info@54: var offsets = this.offsets info@54: var targets = this.targets info@54: var activeTarget = this.activeTarget info@54: var i info@54: info@54: if (scrollTop >= maxScroll) { info@54: return activeTarget != (i = targets.last()[0]) && this.activate(i) info@54: } info@54: info@54: for (i = offsets.length; i--;) { info@54: activeTarget != targets[i] info@54: && scrollTop >= offsets[i] info@54: && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) info@54: && this.activate( targets[i] ) info@54: } info@54: } info@54: info@54: ScrollSpy.prototype.activate = function (target) { info@54: this.activeTarget = target info@54: info@54: $(this.selector) info@54: .parents('.active') info@54: .removeClass('active') info@54: info@54: var selector = this.selector info@54: + '[data-target="' + target + '"],' info@54: + this.selector + '[href="' + target + '"]' info@54: info@54: var active = $(selector) info@54: .parents('li') info@54: .addClass('active') info@54: info@54: if (active.parent('.dropdown-menu').length) { info@54: active = active info@54: .closest('li.dropdown') info@54: .addClass('active') info@54: } info@54: info@54: active.trigger('activate.bs.scrollspy') info@54: } info@54: info@54: info@54: // SCROLLSPY PLUGIN DEFINITION info@54: // =========================== info@54: info@54: var old = $.fn.scrollspy info@54: info@54: $.fn.scrollspy = function (option) { info@54: return this.each(function () { info@54: var $this = $(this) info@54: var data = $this.data('bs.scrollspy') info@54: var options = typeof option == 'object' && option info@54: info@54: if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) info@54: if (typeof option == 'string') data[option]() info@54: }) info@54: } info@54: info@54: $.fn.scrollspy.Constructor = ScrollSpy info@54: info@54: info@54: // SCROLLSPY NO CONFLICT info@54: // ===================== info@54: info@54: $.fn.scrollspy.noConflict = function () { info@54: $.fn.scrollspy = old info@54: return this info@54: } info@54: info@54: info@54: // SCROLLSPY DATA-API info@54: // ================== info@54: info@54: $(window).on('load', function () { info@54: $('[data-spy="scroll"]').each(function () { info@54: var $spy = $(this) info@54: $spy.scrollspy($spy.data()) info@54: }) info@54: }) info@54: info@54: }(jQuery);