<commit_before>/** @namespace */
var sg = sg || {};

/**
 * Main module for Gallery.
 * @param params Object passed from gallery.scala.html containing initial values pulled from the database on page
 *              load.
 * @returns {Main}
 * @constructor
 */
function Main (params) {
    let self = this;

    sg.scrollStatus = {
        stickySidebar: true,
        stickyModal: true
    };

    let headerSidebarOffset = undefined;

    function _initUI() {
        sg.ui = {};

        // Initializes filter components in side bar.
        sg.ui.cardFilter = {};
        sg.ui.cardFilter.wrapper = $(".sidebar");
        sg.ui.cardFilter.holder = $("#card-filter");
        sg.ui.cardFilter.tags = $("#tags");
        sg.ui.cardFilter.severity = $("#severity");

        // Initializes label select component in side bar.
        sg.ui.ribbonMenu = {};
        sg.ui.ribbonMenu.holder = $("#ribbon-menu-holder");
        sg.ui.ribbonMenu.select = $('#label-select');

        // TODO: potentially remove if we decide sorting is not desired for later versions.
        sg.ui.cardSortMenu = {};
        sg.ui.cardSortMenu.holder = $("#card-sort-menu-holder");
        sg.ui.cardSortMenu.sort = $('#card-sort-select');

        // Initialize card container component.
        sg.ui.cardContainer = {};
        sg.ui.cardContainer.holder = $("#image-card-container");
        sg.ui.cardContainer.prevPage = $("#prev-page");
        sg.ui.cardContainer.pageNumber = $("#page-number")
        sg.ui.cardContainer.nextPage = $("#next-page");

        // Keep track of the next/prev arrow container.
        sg.ui.pageControl = $(".page-control");

        // Keep track of navbar.
        sg.ui.navbar = $("#header")

        $('.gallery-modal').hide();

        // Calculate offset between bottom of navbar and sidebar.
        headerSidebarOffset = sg.ui.cardFilter.wrapper.offset().top - (sg.ui.navbar.offset().top + sg.ui.navbar.outerHeight());
    }

    function _init() {
        sg.rootDirectory = ('rootDirectory' in params) ? params.rootDirectory : '/';

        // Initialize functional components of UI elements.
        sg.ribbonMenu = new RibbonMenu(sg.ui.ribbonMenu);
        // sg.cardSortMenu = new CardSortMenu(sg.ui.cardSortMenu);
        sg.tagContainer = new CardFilter(sg.ui.cardFilter, sg.ribbonMenu);
        sg.cardContainer = new CardContainer(sg.ui.cardContainer);

        // Initialize data collection.
        sg.form = new Form(params.dataStoreUrl, params.beaconDataStoreUrl)
        sg.tracker = new Tracker();

        sg.util = {};

        // // Set initial sidebar stickiness
        // let initSidebarBottomOffset = sg.ui.cardFilter.wrapper.offset().top +
        //                               sg.ui.cardFilter.wrapper.outerHeight(true);
        // let initCardContainerBottomOffset = sg.ui.cardContainer.holder.offset().top +
        //                                     sg.ui.cardContainer.holder.outerHeight(true) - 10;
        // status.stickySidebar = initCardContainerBottomOffset < initSidebarBottomOffset;

        $(window).scroll(function () {
            // Make sure the page isn't loading.
            if (!$("#page-loading").is(":visible")) {
                let sidebarBottomOffset = sg.ui.cardFilter.wrapper.offset().top +
                                          sg.ui.cardFilter.wrapper.outerHeight(true);
                let cardContainerBottomOffset = sg.ui.cardContainer.holder.offset().top +
                                                sg.ui.cardContainer.holder.outerHeight(true) - 10;
                let pageControlTopOffset = sg.ui.pageControl.offset().top;
                let visibleWindowBottomOffset = $(window).scrollTop() + $(window).height();

                // Handle sidebar stickiness.
                if (sg.scrollStatus.stickySidebar) {
                    console.log("are we in here");
                    if (pageControlTopOffset < sidebarBottomOffset) {
                        console.log("triggered");
                        sidebarHeightBeforeRelative = sg.ui.cardFilter.wrapper.outerHeight(true);

                        // Adjust sidebar positioning.
                        sg.ui.cardFilter.wrapper.css('position', 'relative');

                        // The sg.ui.navbar.outerHeight(false) is necessary in order for the placement of the sidebar
                        // to be correct once it goes to being relatively positioned.
                        // TODO: investigate more closely as to why.
                        let navbarHeight = sg.ui.navbar.outerHeight(false);
                        let newTop = pageControlTopOffset - sidebarHeightBeforeRelative - navbarHeight;
                        console.log(newTop);
                        sg.ui.cardFilter.wrapper.css('top', newTop);

                        // Adjust card container margin.
                        sg.ui.cardContainer.holder.css('margin-left', '0px');
                        sg.scrollStatus.stickySidebar = false;
                    }
                } else {
                    if (!sg.scrollStatus.stickySidebar) {
                        currHeaderSidebarOffset = sg.ui.cardFilter.wrapper.offset().top -
                                                 (sg.ui.navbar.offset().top + sg.ui.navbar.outerHeight(false));
                        if (currHeaderSidebarOffset > headerSidebarOffset) {
                            // Adjust sidebar positioning.
                            sg.ui.cardFilter.wrapper.css('position', 'fixed');
                            sg.ui.cardFilter.wrapper.css('top', '');
        
                            // Adjust card container margin.
                            sg.ui.cardContainer.holder.css('margin-left', '235px'); // constant
                            sg.scrollStatus.stickySidebar = true;
                        }
                    }
                }<commit_msg>removes constant<commit_after>/** @namespace */
var sg = sg || {};

/**
 * Main module for Gallery.
 * @param params Object passed from gallery.scala.html containing initial values pulled from the database on page
 *              load.
 * @returns {Main}
 * @constructor
 */
function Main (params) {
    let self = this;

    sg.scrollStatus = {
        stickySidebar: true,
        stickyModal: true
    };

    let headerSidebarOffset = undefined;

    function _initUI() {
        sg.ui = {};

        // Initializes filter components in side bar.
        sg.ui.cardFilter = {};
        sg.ui.cardFilter.wrapper = $(".sidebar");
        sg.ui.cardFilter.holder = $("#card-filter");
        sg.ui.cardFilter.tags = $("#tags");
        sg.ui.cardFilter.severity = $("#severity");

        // Initializes label select component in side bar.
        sg.ui.ribbonMenu = {};
        sg.ui.ribbonMenu.holder = $("#ribbon-menu-holder");
        sg.ui.ribbonMenu.select = $('#label-select');

        // TODO: potentially remove if we decide sorting is not desired for later versions.
        sg.ui.cardSortMenu = {};
        sg.ui.cardSortMenu.holder = $("#card-sort-menu-holder");
        sg.ui.cardSortMenu.sort = $('#card-sort-select');

        // Initialize card container component.
        sg.ui.cardContainer = {};
        sg.ui.cardContainer.holder = $("#image-card-container");
        sg.ui.cardContainer.prevPage = $("#prev-page");
        sg.ui.cardContainer.pageNumber = $("#page-number")
        sg.ui.cardContainer.nextPage = $("#next-page");

        // Keep track of the next/prev arrow container.
        sg.ui.pageControl = $(".page-control");

        // Keep track of navbar.
        sg.ui.navbar = $("#header")

        // Keep track of loading GIF.
        sg.pageLoading = $('#page-loading');

        $('.gallery-modal').hide();

        // Calculate offset between bottom of navbar and sidebar.
        headerSidebarOffset = sg.ui.cardFilter.wrapper.offset().top - (sg.ui.navbar.offset().top + sg.ui.navbar.outerHeight());
    }

    function _init() {
        sg.rootDirectory = ('rootDirectory' in params) ? params.rootDirectory : '/';

        // Initialize functional components of UI elements.
        sg.ribbonMenu = new RibbonMenu(sg.ui.ribbonMenu);
        // sg.cardSortMenu = new CardSortMenu(sg.ui.cardSortMenu);
        sg.tagContainer = new CardFilter(sg.ui.cardFilter, sg.ribbonMenu);
        sg.cardContainer = new CardContainer(sg.ui.cardContainer);

        // Initialize data collection.
        sg.form = new Form(params.dataStoreUrl, params.beaconDataStoreUrl)
        sg.tracker = new Tracker();

        sg.util = {};

        let sidebarWidth = sg.ui.cardFilter.wrapper.css('width');

        // // Set initial sidebar stickiness
        // let initSidebarBottomOffset = sg.ui.cardFilter.wrapper.offset().top +
        //                               sg.ui.cardFilter.wrapper.outerHeight(true);
        // let initCardContainerBottomOffset = sg.ui.cardContainer.holder.offset().top +
        //                                     sg.ui.cardContainer.holder.outerHeight(true) - 10;
        // status.stickySidebar = initCardContainerBottomOffset < initSidebarBottomOffset;

        $(window).scroll(function () {
            // Make sure the page isn't loading.
            if (!sg.pageLoading.is(":visible")) {
                let sidebarBottomOffset = sg.ui.cardFilter.wrapper.offset().top +
                                          sg.ui.cardFilter.wrapper.outerHeight(true);
                let cardContainerBottomOffset = sg.ui.cardContainer.holder.offset().top +
                                                sg.ui.cardContainer.holder.outerHeight(true) - 10;
                let pageControlTopOffset = sg.ui.pageControl.offset().top;
                let visibleWindowBottomOffset = $(window).scrollTop() + $(window).height();

                // Handle sidebar stickiness.
                if (sg.scrollStatus.stickySidebar) {
                    console.log("are we in here");
                    if (pageControlTopOffset < sidebarBottomOffset) {
                        console.log("triggered");
                        sidebarHeightBeforeRelative = sg.ui.cardFilter.wrapper.outerHeight(true);

                        // Adjust sidebar positioning.
                        sg.ui.cardFilter.wrapper.css('position', 'relative');

                        // Compute the new location for the top of the sidebar, just above the paging arrows.
                        let navbarHeight = sg.ui.navbar.outerHeight(false);
                        let newTop = pageControlTopOffset - sidebarHeightBeforeRelative - navbarHeight;
                        console.log(newTop);
                        sg.ui.cardFilter.wrapper.css('top', newTop);

                        // Adjust card container margin.
                        sg.ui.cardContainer.holder.css('margin-left', '0px');
                        sg.scrollStatus.stickySidebar = false;
                    }
                } else {
                    if (!sg.scrollStatus.stickySidebar) {
                        currHeaderSidebarOffset = sg.ui.cardFilter.wrapper.offset().top -
                                                 (sg.ui.navbar.offset().top + sg.ui.navbar.outerHeight(false));
                        if (currHeaderSidebarOffset > headerSidebarOffset) {
                            // Adjust sidebar positioning.
                            sg.ui.cardFilter.wrapper.css('position', 'fixed');
                            sg.ui.cardFilter.wrapper.css('top', '');
        
                            // Adjust card container margin.
                            sg.ui.cardContainer.holder.css('margin-left', sidebarWidth);
                            sg.scrollStatus.stickySidebar = true;
                        }
                    }
                }
{'fraction_non_alphanumeric': 0.12049319727891157, 'fraction_numerical': 0.0011054421768707484, 'mean_word_length': 1.677823315118397, 'pattern_counts': {'":': 2, '<': 7, '<?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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504541', 'n_tokens_mistral': 3171, 'n_tokens_neox': 2880, 'n_words': 600}