<commit_before>

var scrollToOffset = 120;
var disableScrollFn = false;

$(document).ready(function (){
	$('nav li a').on('click', function(event){
		event.preventDefault();
		scrollToID( $(this).attr("href"), 300);
	});


    var sections = {}, navs = {};
    $('.section').each(function(){
        sections[this.id] = $(this).offset().top;
    });
    $('nav a').each(function(){
        navs[ $(this).attr('href').substring(1) ] = this.parentNode;
    });

    $(document).scroll(function(){
        if (disableScrollFn) { return; }
        var page_height = $(window).height();
        var pos = $(this).scrollTop();
        for (i in sections) {
            if ((pos + scrollToOffset >= sections[i]) && sections[i] < pos + page_height){
                $("nav li").removeClass('active');
                $(navs[i]).addClass('active');
            }
        }
    });

});




function scrollToID(id, speed){
	var targetOffset = $(id).offset().top - scrollToOffset;
    disableScrollFn = true;
    $("nav li").removeClass('active');
	$('html,body').animate({scrollTop: targetOffset}, speed, "linear", function(){
        disableScrollFn = false;
        console.log("animateion completed.");
    });
}
if (typeof console === "undefined") {
    console = {
        log: function() { }
    };
}<commit_msg>Make scrolling into a jQuery plugin called navScroller<commit_after>
(function( $ ) {

    var settings;
    var disableScrollFn = false;
    var navs = {}, sections = {};

    $.fn.navScroller = function(options) {
        settings = $.extend({
            scrollToOffset: 120,
            scrollSpeed: 300,
            activateParentNode: true,
        }, options );

        //attatch click listeners
    	this.on('click', function(event){
    		event.preventDefault();
            var navID = $(this).attr("href").substring(1);
            disableScrollFn = true;
            activateNav(navID);
        	$('html,body').animate({scrollTop: sections[navID] - settings.scrollToOffset},
                settings.scrollSpeed, "linear", function(){
                    disableScrollFn = false;
                }
            );
    	});

        //populate lookup of clicable elements and destination sections
        this.each(function(){
            var scrollID = $(this).attr('href').substring(1);
            navs[scrollID] = (settings.activateParentNode)? this.parentNode : this;
            sections[scrollID] = $(document.getElementById(scrollID)).offset().top;
            console.log("#"+scrollID + " nav:"+navs[scrollID] + " section:"+sections[scrollID]);
        });

        // setup scroll listener
        $(document).scroll(function(){
            if (disableScrollFn) { return; }
            var page_height = $(window).height();
            var pos = $(this).scrollTop();
            for (i in sections) {
                if ((pos + settings.scrollToOffset >= sections[i]) && sections[i] < pos + page_height){
                    console.log("#"+i + " pos:"+pos + " settings.scrollToOffset:" + settings.scrollToOffset);
                    activateNav(i);
                }
            }
        });
    };

    function activateNav(navID) {
        for (nav in navs) { $(navs[nav]).removeClass('active'); }
        $(navs[navID]).addClass('active');
    }
})( jQuery );


$(document).ready(function (){

    $('nav li a').navScroller();

});

{'fraction_non_alphanumeric': 0.17077517077517076, 'fraction_numerical': 0.004455004455004455, 'mean_word_length': 2.295499021526419, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6994671', 'n_tokens_mistral': 968, 'n_tokens_neox': 930, 'n_words': 189}