<commit_before>// TODO move fire event to personal namespace for functions

var ResponsiveNavbar = function () {
    
    // Some popular document elements that'll be used a lot.
    var collapser = document.getElementsByClassName('collapser');
    var ulList = document.getElementsByClassName('nav-links');
    var navbar_container = document.getElementById('navbar-container');
    
    // Hide navbar's scrollbar if there is any. If not padding-left will be 0px
    navbar_container.style.paddingLeft = (navbar_container.offsetWidth - navbar_container.clientWidth) + 'px';
    
    // Boolean variables
    var collapsed = false;
    var mobile_view = false;
    
    // Current open collapser.
    // If none is open, then this value will be null.
    var selected_nested = null;
    
    // Check if browser is already in mobile view.
    if (document.documentElement.clientWidth < 768) {
        mobile_view = true;
    }

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
    // 
    // NavBar elements eventlisteners
    // 1. navbar nested collapser: show/hide nested links inside collapser
    // 2. Navbar compact view "hamburger": show/hide navbar when it is in compact/mobile view
    //
    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

    // 1
    // Loops through all collapser and adds eventlistener to them.
    //
    // Prevents elements default action and stops propagation.
    //
    // Sets this object "selected_nested" variable.
    //
    // useCapture: false
    //
    for (let i = 0; i < collapser.length; i++) {
        collapser[i].addEventListener('click', function (event) {
            event.preventDefault();
            event.stopPropagation();

            // Get ul elements that contains nested links.
            // Collapser and said ul are both under same parent.
            var elem = this.parentElement.querySelector('.navbar-nested');

            // Hides links if they are already displayed ( have css style "display: inline" )
            // Also resets selected_nested 
            if (elem.style.display === 'inline') {
                elem.style.display = 'none';
                selected_nested = null;
            }
            // If links are not displayed, then display them.
            else {
                // If there is another collapser links visible then hides them.
                if(selected_nested != null){
                    let temp = selected_nested.parentElement.querySelector('.navbar-nested');
                    if (temp.style.display === 'inline') {
                        temp.style.display = 'none';
                        selected_nested = null;
                    }
                }
                // Display links.
                // Also save this as selected
                elem.style.display = 'inline';
                selected_nested = this;
            }
        }, false);
    }

    // 2
    // Compact view "hamburger" collapser
    //
    // Navbar links ( except brand/logo ) will be hidden in compact/mobile view.
    // This eventlistener will show/hide links inside navbar.
    //
    // Prevents default action and propagation from click.
    //
    //  Sets this object "collapsed" variable.
    //
    // useCapture: false
    //
    document.getElementById('navbar-collapser').addEventListener('click', function (event) {
        event.preventDefault();
        event.stopPropagation();
        // Loops through all link containers ( ul ) inside navbar
        // Change navbar links visibility depending on current status ( collapsed )
        if (collapsed) {
            for (let i = 0; i < ulList.length; i++) {
                ulList[i].style.display = 'none';
            }
            collapsed = false;
        }
        else {
            for (let i = 0; i < ulList.length; i++) {
                ulList[i].style.display = 'inline';
            }
            collapsed = true;
        }
        // Close collapsed nested link
        if (selected_nested != null) {
            eventFire(selected_nested, 'click');
        }
    }, false);

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
    // 
    // Browser element eventlisteners.
    // 1. window resize: for navbar compact view
    // 2. click on any DOM element: for closing navbar
    //
    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

    // 1
    //
    // Changes display.style for navbar links on entering and existing mobile views.
    //
    // Use eventlistener for window resize
    //
    // Css don't seems to override JavaScript changes. So this seems to be easiest way.
    // Use mobile_view so actions are only performed once after entering/existing.<commit_msg>more comments<commit_after>// TODO move fire event to personal namespace for functions

var ResponsiveNavbar = function () {
    
    // Some popular document elements that'll be used a lot.
    // There's a lot of eventlisteners so it's easier and lighter to assign them to variables at start
    var collapser = document.getElementsByClassName('collapser');
    var ulList = document.getElementsByClassName('nav-links');
    var navbar_container = document.getElementById('navbar-container');
    
    // Hide navbar's scrollbar if there is any. If not padding-left will be 0px
    // Collapsed compact/mobile navbar may require scrolling because all links may not fit inside height.
    // It may show scrollbar inside navbar element.
    // This will calculate difference and use padding to hide extra (which is scrollbars width)
    navbar_container.style.paddingLeft = (navbar_container.offsetWidth - navbar_container.clientWidth) + 'px';
    
    // Boolean variables for checking navbar status
    var collapsed = false;
    var mobile_view = false;
    
    // Current open collapser.
    // Collapser are used for nested links.
    // If none is open, then this value will be null.
    // Some eventlisteners will use this variable to fire click event to close collapser
    var selected_nested = null;
    
    // Check if browser is already in mobile view.
    if (document.documentElement.clientWidth < 768) {
        mobile_view = true;
    }

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
    // 
    // NavBar elements eventlisteners
    // 1. navbar nested collapser: show/hide nested links inside collapser
    // 2. Navbar compact view "hamburger": show/hide navbar when it is in compact/mobile view
    //
    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

    // 1
    // Loops through all collapser and adds eventlistener to them.
    // Function sets nested links status. x.style.display = 'inline' or 'none'
    //
    // Prevents elements default action and stops propagation.
    // There is eventlistener in document elements that will close navbar/collapser
    // if user clicked any DOM elements.
    //
    // Sets "selected_nested" variable.
    //
    // useCapture: false
    //
    for (let i = 0; i < collapser.length; i++) {
        collapser[i].addEventListener('click', function (event) {
            event.preventDefault();
            event.stopPropagation();

            // Get ul elements that contains nested links.
            // Collapser and said ul are both under same parent.
            var elem = this.parentElement.querySelector('.navbar-nested');

            // Hides links if they are already displayed ( have css style "display: inline" )
            // Also resets selected_nested 
            if (elem.style.display === 'inline') {
                elem.style.display = 'none';
                selected_nested = null;
            }
            // If links are not displayed, then display them.
            else {
                // If there is another collapser links visible then hides them.
                if(selected_nested != null){
                    let temp = selected_nested.parentElement.querySelector('.navbar-nested');
                    if (temp.style.display === 'inline') {
                        temp.style.display = 'none';
                        selected_nested = null;
                    }
                }
                // Display links.
                // Also save this as selected
                elem.style.display = 'inline';
                selected_nested = this;
            }
        }, false);
    }

    // 2
    //
    // Compact view "hamburger" click event.
    // Show and hides links inside navbar.
    //
    // Navbar links ( except brand/logo ) will be hidden in compact/mobile view.
    // This eventlistener will show/hide links inside navbar.
    //
    // Prevents default action and propagation from click.
    //
    //  Sets this object "collapsed" variable.
    //
    // useCapture: false
    //
    document.getElementById('navbar-collapser').addEventListener('click', function (event) {
        event.preventDefault();
        event.stopPropagation();
        // Loops through all link containers ( ul ) inside navbar
        // Change navbar links visibility depending on current status ( collapsed )
        if (collapsed) {
            for (let i = 0; i < ulList.length; i++) {
                ulList[i].style.display = 'none';
            }
            collapsed = false;
        }
        else {
            for (let i = 0; i < ulList.length; i++) {
                ulList[i].style.display = 'inline';
            }
            collapsed = true;
        }
        // Close collapsed nested link.
        // Easier to simulate click on them since collapsers eventlistener shows/hides itself.
        if (selected_nested != null) {
            eventFire(selected_nested, 'click');
        }
    }, false);

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
    // 
    // Browser element eventlisteners.
    // 1. window resize: for navbar compact view
    // 2. click on any DOM element: for closing navbar
    //
    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

    // 1
    //
    // Changes display.style for navbar links on entering and existing mobile views.
    //
    // Use eventlistener for window resize
    //
    // Css don't seems to override JavaScript changes. So this seems to be easiest way.
    // Use mobile_view so actions are only performed once after entering/existing.
{'fraction_non_alphanumeric': 0.13398260211800303, 'fraction_numerical': 0.00264750378214826, 'mean_word_length': 1.5129484438108813, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, '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': '1254759', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2709, 'n_words': 882}