<commit_before>$(function() {
    $("body").append('<div id="modal_background"></div>');
    $("body").append('<div id="second_modal_background"></div>');
    $("body").append('<div id="third_modal_background"></div>');
});

function do_show_modal(modal_selector, background_selector, z_index, submit_handler) {
    var modal_background = $(background_selector);
    modal_background.css({'display': 'block',
                          'opacity': 0});
    modal_background.fadeTo(200, 0.5);

    var modal_div = $(modal_selector);
    if (typeof submit_handler != 'undefined' && submit_handler) {
        var form = modal_div.find("form");
        form.off("submit");
        form.on("submit", submit_handler);
    }

    var modal_width = modal_div.outerWidth();
    modal_div.removeClass("hidden");
    modal_div.css({ 
        'display': 'block',
        'position': 'fixed',
        'opacity': 0,
        'z-index': z_index,
        'left' : 50 + '%',
        'margin-left': -(modal_width/2) + "px"
    });
    modal_div.fadeTo(200, 1);
}

function do_close_modal(modal_selector, background_selector) {<commit_msg>Add ESC key handling for modal dialogs<commit_after>$(function() {
    $("body").append('<div id="modal_background"></div>');
    $("body").append('<div id="second_modal_background"></div>');
    $("body").append('<div id="third_modal_background"></div>');
    $(document).keyup(function(e) {
            do_close_modal(g_modal_dialogs[g_modal_dialogs.length - 1],
                           ['#modal_background',
                            '#second_modal_background',
                            '#third_modal_background'][g_modal_dialogs.length - 1]);
        }
    });
});

// A stack of selectors for the currently-open modal dialog(s), if any.
var g_modal_dialogs = []

function do_show_modal(modal_selector, background_selector, z_index, submit_handler) {
    var modal_background = $(background_selector);
    modal_background.css({'display': 'block',
                          'opacity': 0});
    modal_background.fadeTo(200, 0.5);

    var modal_div = $(modal_selector);
    if (typeof submit_handler != 'undefined' && submit_handler) {
        var form = modal_div.find("form");
        form.off("submit");
        form.on("submit", submit_handler);
    }

    g_modal_dialogs.push(modal_selector);

    var modal_width = modal_div.outerWidth();
    modal_div.removeClass("hidden");
    modal_div.css({ 
        'display': 'block',
        'position': 'fixed',
        'opacity': 0,
        'z-index': z_index,
        'left' : 50 + '%',
        'margin-left': -(modal_width/2) + "px"
    });
    modal_div.fadeTo(200, 1);
}

function do_close_modal(modal_selector, background_selector) {
    g_modal_dialogs.pop();
{'fraction_non_alphanumeric': 0.16733503463361282, 'fraction_numerical': 0.01093693036820999, 'mean_word_length': 3.0531757754800593, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7349652', 'n_tokens_mistral': 872, 'n_tokens_neox': 842, 'n_words': 144}