<commit_before>/**
 * Stack-related functionality.
 *
 * @mixin
 * @namespace Bolt.stack
 *
 * @param {Object} bolt - The Bolt module.
 * @param {Object} $ - jQuery.
 */
(function (bolt, $) {
    'use strict';

    /**
     * Bolt.stack mixin container.
     *
     * @private
     * @type {Object}
     */
    var stack = {};


    /**
     * Initializes the mixin.
     *
     * @static
     * @function init
     * @memberof Bolt.stack
     */
    stack.init = function () {
        bolt.uploads.bindUpload('stack');

        // Initialze file browser modal.
        $('#modal-server-select').on(
            'show.bs.modal',
            function (event) {
                var modal = $(this),
                    button = $(event.relatedTarget),
                    remote = button.data('modal-source');

                modal
                    .find('.modal-dialog')
                    .load(remote + ' .modal-content', function (responseText, textStatus) {
                        if (textStatus === 'success' || textStatus === 'notmodified') {
                            bolt.actions.init();
                            modal.show();
                        }
                    });
            }
        );

    };

    /**
     * Add a file to the stack.
     *
     * @static
     * @function addToStack
     * @memberof Bolt.stack
     *
     * @param {string} filename - The name of the file to add
     * @param {object} element - The object that calls this function
     */
    stack.addToStack = function (filename, element) {
        var ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase(),
            type;

        if (ext === 'jpg' || ext === 'jpeg' || ext === 'png' || ext === 'gif') {
            type = 'image';
        } else {
            type = 'other';
        }

        // We don't need 'files/' in the path. Accept input with or without it, but strip it out here.
        filename = filename.replace(/files\//ig, '');

        $.ajax({
            url: bolt.conf('paths.async') + 'stack/add/' + filename,
            type: 'GET',
            success: function () {
                // Move all current items one down, and remove the last one.
                var stack = $('#stackholder div.stackitem'),
                    i,
                    ii,
                    item,
                    html;

                for (i = stack.length; i >= 1; i--) {
                    ii = i + 1;
                    item = $('#stackholder div.stackitem.item-' + i);
                    item.addClass('item-' + ii).removeClass('item-' + i);
                }
                if ($('#stackholder div.stackitem.item-8').is('*')) {
                    $('#stackholder div.stackitem.item-8').remove();
                }

                // If added via a button on the page, disable the button, as visual feedback.
                if (element !== null) {
                    $(element).addClass('disabled');
                }

                // Insert new item at the front.
                if (type === 'image') {
                    html = $('#protostack div.image').clone();
                    $(html).find('img').attr('src', bolt.conf('paths.bolt') + '../thumbs/100x100c/' +
                        encodeURI(filename));
                } else {
                    html = $('#protostack div.other').clone();
                    $(html).find('strong').html(ext.toUpperCase());
                    $(html).find('small').html(filename);
                }
                $('#stackholder').prepend(html);

                // If the "empty stack" notice was showing, remove it.
                $('.nostackitems').remove();

            },
            error: function () {
                console.log('Failed to add file to stack');
            }
        });
    };

    /**
     * Select file in modal file selector dialog.
     *
     * @static
     * @function selectFromPulldown
     * @memberof Bolt.stack
     *
     * @param {string} key - Id of the file selector
     * @param {string} path - Path to the selected file
     */
    stack.selectFromPulldown = function (key, path) {
        // For "normal" file and image fields.
        if ($('#field-' + key).is('*')) {
            $('#field-' + key).val(path).trigger('change');
        }

        // For Imagelist fields. Check if bolt.imagelist[key] is an object.
        if (typeof bolt.imagelist === 'object' && typeof bolt.imagelist[key] === 'object') {
            bolt.imagelist[key].add(path, path);
        }

        // For Filelist fields. Check if filelist[key] is an object.
        if (typeof bolt.filelist === 'object' && typeof bolt.filelist[key] === 'object') {
            bolt.filelist[key].add(path, path);
        }

        // Close the modal dialog, if this image/file was selected through one.
        $('#modal-server-select').modal('hide');

        // If we need to place it on the stack as well, do so.
        if (key === 'stack') {
            bolt.stack.addToStack(path);
        }

        // Make sure the dropdown menu is closed. (Using the "blunt axe" method)
        $('.in, .open').removeClass('in open');
    };

    /**
     * Changes folder in modal file selector dialog.
     *
     * @static
     * @function changeFolder
     * @memberof Bolt.stack
     *
     * @param {string} folderUrl - The URL command string to change the folder
     */
    stack.changeFolder = function (folderUrl) {
        $('#modal-server-select .modal-dialog').load(folderUrl + ' .modal-content', function () {
            bolt.actions.init();
        });
    };

    // Apply mixin container
    bolt.stack = stack;

})(Bolt || {}, jQuery);
<commit_msg>Put first load and folder change together<commit_after>/**
 * Stack-related functionality.
 *
 * @mixin
 * @namespace Bolt.stack
 *
 * @param {Object} bolt - The Bolt module.
 * @param {Object} $ - jQuery.
 */
(function (bolt, $) {
    'use strict';

    /**
     * Bolt.stack mixin container.
     *
     * @private
     * @type {Object}
     */
    var stack = {};


    /**
     * Initializes the mixin.
     *
     * @static
     * @function init
     * @memberof Bolt.stack
     */
    stack.init = function () {
        bolt.uploads.bindUpload('stack');

        // Initialze file browser modal.
        $('#modal-server-select').on(
            'show.bs.modal',
            function (event) {
                var url = $(event.relatedTarget).data('modal-source');

                browserLoad(url);
            }
        );
    };

    /**
     * Add a file to the stack.
     *
     * @static
     * @function addToStack
     * @memberof Bolt.stack
     *
     * @param {string} filename - The name of the file to add
     * @param {object} element - The object that calls this function
     */
    stack.addToStack = function (filename, element) {
        var ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase(),
            type;

        if (ext === 'jpg' || ext === 'jpeg' || ext === 'png' || ext === 'gif') {
            type = 'image';
        } else {
            type = 'other';
        }

        // We don't need 'files/' in the path. Accept input with or without it, but strip it out here.
        filename = filename.replace(/files\//ig, '');

        $.ajax({
            url: bolt.conf('paths.async') + 'stack/add/' + filename,
            type: 'GET',
            success: function () {
                // Move all current items one down, and remove the last one.
                var stack = $('#stackholder div.stackitem'),
                    i,
                    ii,
                    item,
                    html;

                for (i = stack.length; i >= 1; i--) {
                    ii = i + 1;
                    item = $('#stackholder div.stackitem.item-' + i);
                    item.addClass('item-' + ii).removeClass('item-' + i);
                }
                if ($('#stackholder div.stackitem.item-8').is('*')) {
                    $('#stackholder div.stackitem.item-8').remove();
                }

                // If added via a button on the page, disable the button, as visual feedback.
                if (element !== null) {
                    $(element).addClass('disabled');
                }

                // Insert new item at the front.
                if (type === 'image') {
                    html = $('#protostack div.image').clone();
                    $(html).find('img').attr('src', bolt.conf('paths.bolt') + '../thumbs/100x100c/' +
                        encodeURI(filename));
                } else {
                    html = $('#protostack div.other').clone();
                    $(html).find('strong').html(ext.toUpperCase());
                    $(html).find('small').html(filename);
                }
                $('#stackholder').prepend(html);

                // If the "empty stack" notice was showing, remove it.
                $('.nostackitems').remove();

            },
            error: function () {
                console.log('Failed to add file to stack');
            }
        });
    };

    /**
     * Select file in modal file selector dialog.
     *
     * @static
     * @function selectFromPulldown
     * @memberof Bolt.stack
     *
     * @param {string} key - Id of the file selector
     * @param {string} path - Path to the selected file
     */
    stack.selectFromPulldown = function (key, path) {
        // For "normal" file and image fields.
        if ($('#field-' + key).is('*')) {
            $('#field-' + key).val(path).trigger('change');
        }

        // For Imagelist fields. Check if bolt.imagelist[key] is an object.
        if (typeof bolt.imagelist === 'object' && typeof bolt.imagelist[key] === 'object') {
            bolt.imagelist[key].add(path, path);
        }

        // For Filelist fields. Check if filelist[key] is an object.
        if (typeof bolt.filelist === 'object' && typeof bolt.filelist[key] === 'object') {
            bolt.filelist[key].add(path, path);
        }

        // Close the modal dialog, if this image/file was selected through one.
        $('#modal-server-select').modal('hide');

        // If we need to place it on the stack as well, do so.
        if (key === 'stack') {
            bolt.stack.addToStack(path);
        }

        // Make sure the dropdown menu is closed. (Using the "blunt axe" method)
        $('.in, .open').removeClass('in open');
    };

    /**
     * Changes folder in modal file selector dialog.
     *
     * @static
     * @function changeFolder
     * @memberof Bolt.stack
     *
     * @param {string} folderUrl - The URL command string to change the folder
     */
    stack.changeFolder = function (folderUrl) {
        browserLoad(folderUrl);
    };

    /**
     * Changes folder in modal file selector dialog.
     *
     * @private
     * @function changeFolder
     * @memberof Bolt.stack
     *
     * @param {string} url - The URL to load into the file browser window.
     */
    function browserLoad(url) {
        $('#modal-server-select .modal-dialog').load(url + ' .modal-content', function (responseText, textStatus) {
            if (textStatus === 'success' || textStatus === 'notmodified') {
                bolt.actions.init();
                $('#modal-server-select').show();
            }
        });
    }

    // Apply mixin container
    bolt.stack = stack;

})(Bolt || {}, jQuery);

{'fraction_non_alphanumeric': 0.14769041984398282, 'fraction_numerical': 0.00192830221754755, 'mean_word_length': 1.5, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2615246', 'n_tokens_mistral': 3192, 'n_tokens_neox': 3043, 'n_words': 842}