1/* 2 * NavPoints 3 * https://github.com/Ins-V/navpoints 4 * 5 * Author: Vitaliy Gusarev 6 * 7 * Licensed under the MIT license. 8 */ 9;(function($) { 10 var settings = { 11 speed: 300, 12 offset: 0, 13 currentClass: 'active', 14 updateHash: false, 15 classToParent: false 16 } 17 18 var NavPoints = { 19 init: function(options, navbar) { 20 settings = $.extend(settings, options); 21 this.$navbar = $(navbar); 22 this.$items = this.$navbar.find('a:not(.externals)'); 23 this.$window = $(window); 24 this.hashNow = undefined; 25 26 this.$items.on('click', this.clicked); 27 this.$window.on('scroll', $.proxy(this.scrollPage, this)); 28 this.$window.on('resize', $.proxy(this.scrollPage, this)); 29 }, 30 clicked: function(e) { 31 var hash = $(this).attr('href'); 32 if(hash !== '#' && /^#/.test(hash)) { 33 e.preventDefault(); 34 var position = $(hash).offset().top - settings.offset; 35 36 $('html, body').animate({ 37 scrollTop: position 38 }, settings.speed); 39 } 40 }, 41 scrollPage: function() { 42 var self = this, 43 sections = [], 44 result = undefined; 45 self.$items.each(function() { 46 var hash = $(this).attr('href'); 47 if(hash !== '#' && /^#/.test(hash)) { 48 var section = $(hash); 49 if (section.length) sections.push(section); 50 } 51 }); 52 53 for (var i = 0; i < sections.length; i++) { 54 var section = sections[i], 55 sectionHeight = section.height(), 56 sectionTop = section.offset().top, 57 windowTop = self.$window.scrollTop(), 58 windoHeight = self.$window.height(); 59 60 if (windowTop <= sectionTop && (sectionHeight + sectionTop) < (windowTop + windoHeight)) { 61 result = sections[i].attr('id'); 62 break; 63 } 64 } 65 66 if (result) { 67 if (settings.updateHash) { 68 var hash = '#' + result; 69 if (self.hashNow != hash) { 70 self.hashNow = hash; 71 history.pushState({}, '', hash); 72 } 73 } 74 75 if (settings.classToParent) { 76 self.$items.parent().removeClass(settings.currentClass); 77 $('a[href="#' + result + '"]').parent().addClass(settings.currentClass); 78 } 79 else { 80 self.$items.removeClass(settings.currentClass); 81 $('a[href="#' + result + '"]').addClass(settings.currentClass); 82 } 83 } 84 } 85 } 86 87 $.fn.navpoints = function(options) { 88 this.each(function() { 89 var navpoints = Object.create(NavPoints); 90 navpoints.init(options, this); 91 }); 92 } 93})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.