<commit_before>/* Copyright 2012, hast. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 */

var navbar = function() {
    var state, template = null, height = 130;

    var toggle = function() {
        $('#navbar-bottom').slideToggle(100);
        if (state.visible) {
            $('#content').animate({'padding-top': 70}, 100);
            $('#pull').removeClass("courses-focus");
            $('#pull').addClass("courses");
            state.visible = false;
            $.cookies.set('navbar', state);
        } else {
            $('#content').animate({'padding-top': 84 + height}, 100);
            $('#pull').removeClass("courses");
            $('#pull').addClass("courses-focus");
            state.visible = true;
            $.cookies.set('navbar', state);
        }

        if (typeof viewer_instance !== "undefined")
            viewer_instance.refresh();
    };

    var refresh_padding = function() {
        height = $('#navbar-bottom').height() + 10;
        if (state.visible) {
            $('#pull').removeClass("courses");
            $('#pull').addClass("courses-focus");
            $('#content').css('padding-top', 84 + height);
            if (typeof viewer_instance !== "undefined")
                viewer_instance.refresh();
        } else
            $('#content').css('padding-top', 70);
    };

    var draw = function() {
        $('#navbar-bottom').html(template(state));
        $('.navbar-category').click(load_event);
        refresh_padding();
    };

    var load = function(cat_id) {
        $.getJSON("/json/node/" + cat_id, function(data) {
            state.loaded.push(data);
            console.log(state);
            $.cookies.set('navbar', state);
            draw();
        });
    };

    var load_event = function(event) {
        var list = event.target.parentNode;

        for (var i = 0; i < state.loaded.length; ++i)
            if (state.loaded[i].id == list.getAttribute("data-id"))
                break;

        state.loaded.splice(i + 1, state.loaded.length - i - 1);
        $.cookies.set('navbar', state);
        var nodeid = event.target.getAttribute("data-id");
        if (event.target.getAttribute('data-type') == 'Course')
          window.location = '/zoidberg/course/v/'+nodeid;
        else
          load(nodeid);
    };

    var set_state = function() {
        var source = $.cookies.get('navbar');
        if (source == null) {
            // initial state
            state = {
                loaded: [],
                visible: false,
            };
            load(1);
        } else {
            // read from cookie
            state = source;
            draw();
            if (state.visible == true) {
                $('#navbar-bottom').css('display', 'block');
                $('#pullout').html('up');
                $('#content').css('padding-top', 84 + height);
            }
        }
    };

    $(document).ready(function() {
        $('#navbar-top').click(toggle);
        $('#navbar-search').click(function() {return false;});
        $(window).resize(refresh_padding);
        template = Handlebars.compile(fragments["navbar-list"]);
        set_state();
    });

    return {
        is_down: function() {<commit_msg>[enh] toogle navbar only when clicking on course, not the whole menu<commit_after>/* Copyright 2012, hast. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 */

var navbar = function() {
    var state, template = null, height = 130;

    var toggle = function() {
        $('#navbar-bottom').slideToggle(100);
        if (state.visible) {
            $('#content').animate({'padding-top': 70}, 100);
            $('#pull').removeClass("courses-focus");
            $('#pull').addClass("courses");
            state.visible = false;
            $.cookies.set('navbar', state);
        } else {
            $('#content').animate({'padding-top': 84 + height}, 100);
            $('#pull').removeClass("courses");
            $('#pull').addClass("courses-focus");
            state.visible = true;
            $.cookies.set('navbar', state);
        }

        if (typeof viewer_instance !== "undefined")
            viewer_instance.refresh();
    };

    var refresh_padding = function() {
        height = $('#navbar-bottom').height() + 10;
        if (state.visible) {
            $('#pull').removeClass("courses");
            $('#pull').addClass("courses-focus");
            $('#content').css('padding-top', 84 + height);
            if (typeof viewer_instance !== "undefined")
                viewer_instance.refresh();
        } else
            $('#content').css('padding-top', 70);
    };

    var draw = function() {
        $('#navbar-bottom').html(template(state));
        $('.navbar-category').click(load_event);
        refresh_padding();
    };

    var load = function(cat_id) {
        $.getJSON("/json/node/" + cat_id, function(data) {
            state.loaded.push(data);
            console.log(state);
            $.cookies.set('navbar', state);
            draw();
        });
    };

    var load_event = function(event) {
        var list = event.target.parentNode;

        for (var i = 0; i < state.loaded.length; ++i)
            if (state.loaded[i].id == list.getAttribute("data-id"))
                break;

        state.loaded.splice(i + 1, state.loaded.length - i - 1);
        $.cookies.set('navbar', state);
        var nodeid = event.target.getAttribute("data-id");
        if (event.target.getAttribute('data-type') == 'Course')
          window.location = '/zoidberg/course/v/'+nodeid;
        else
          load(nodeid);
    };

    var set_state = function() {
        var source = $.cookies.get('navbar');
        if (source == null) {
            // initial state
            state = {
                loaded: [],
                visible: false,
            };
            load(1);
        } else {
            // read from cookie
            state = source;
            draw();
            if (state.visible == true) {
                $('#navbar-bottom').css('display', 'block');
                $('#pullout').html('up');
                $('#content').css('padding-top', 84 + height);
            }
        }
    };

    $(document).ready(function() {
        $('#pull').click(toggle);
        $('#navbar-search').click(function() {return false;});
        $(window).resize(refresh_padding);
        template = Handlebars.compile(fragments["navbar-list"]);
        set_state();
    });

    return {
        is_down: function() {
{'fraction_non_alphanumeric': 0.1692771949992815, 'fraction_numerical': 0.009484121281793361, 'mean_word_length': 1.9036295369211513, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3186681', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1873, 'n_words': 421}