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