<commit_before>// some javascript functions that need to live somewhere
$(document).ready(function() {
    $("#searchbox").change(function(evt) {
        var query = $(this).val().replace(/^ *| *$/, '');
        if (/^[0-9]+$/.test(query)) {
            var href = 'team_feed.php?team_id=' + query;
            window.location.assign(href);
        } else if (/^[A-Z]$/i.test(query)) {
            var href = 'problem.php?problem_id=' + query;
            window.location.assign(href);
        } else {
            $.ajax({url: "search.php?query=" + query}).done(function(response) {
                data = JSON.parse(response);
                if (data.length == 0) {
                    $("#searchbox_chooser").text("I couldn't find anything about that query. Please enter a team #, problem letter, school name, or country 3-letter abbreviation.");
                } else if (data.length == 1) {
                    window.location.assign(data[0].url);
                } else {
                    var links = "I found several teams that match:<br>";
                    for (var idx in data) {
                        links += "<a href='" + data[idx].url + "'>" + data[idx].school_name + "</a><br>";
                    }
                    $("#searchbox_chooser").html(links);
                }
            });
        }
    });

    $("#add_entry_container .add_entry_form").submit(function(evt) {
        evt.preventDefault();
        var query_str = "date=" + new Date().toString();
        $(this).find("input[type=text]").each(function(idx, item) {
            if (query_str) { query_str += "&"; }
            query_str += escape($(item).attr("name")) + "=" + escape($(item).val());
        });
        console.log('query_str = ' + query_str);
        $.ajax({url: "insert_entry.php?" + query_str }).done(function(response) {
            alert("Got this response on insert: " + response);
        });

        return false;
    });
});

var get_json_synchronous = (function(url) {
    var response;
    $.ajax({
        'async': false,
        'global': false,
        'url': url,
        'dataType': 'json',
        'success': function(data) { response = data; },
        'error': function(err) {
            console.log('error in get_json_synchronous:');
            console.log(err);
        }
    })
    return response;
});
<commit_msg>modularized search query behavior<commit_after>// some javascript functions that need to live somewhere
$(document).ready(function() {
    $("#searchbox").change(function(evt) {
        var query = $(this).val().replace(/^ *| *$/, '');
        return search_query(query);
    });

    $("#add_entry_container .add_entry_form").submit(function(evt) {
        evt.preventDefault();
        var query_str = "date=" + new Date().toString();
        $(this).find("input[type=text]").each(function(idx, item) {
            if (query_str) { query_str += "&"; }
            query_str += escape($(item).attr("name")) + "=" + escape($(item).val());
        });
        console.log('query_str = ' + query_str);
        $.ajax({url: "insert_entry.php?" + query_str }).done(function(response) {
            alert("Got this response on insert: " + response);
        });

        return false;
    });
});

function get_json_synchronous(url) {
    var response;
    $.ajax({
        'async': false,
        'global': false,
        'url': url,
        'dataType': 'json',
        'success': function(data) { response = data; },
        'error': function(err) {
            console.log('error in get_json_synchronous:');
            console.log(err);
        }
    })
    return response;
}

function search_query(query, type) {
    if (type == 'team' || /^[0-9]+$/.test(query)) {
        var href = 'team.php?team_id=' + query;
        window.location.assign(href);
    } else if (type == 'problem' || /^[A-Z]$/i.test(query)) {
        var href = 'problem.php?problem_id=' + query;
        window.location.assign(href);
    } else {
        var type_query = "";
        if (type) {
            type_query = "&type=" + type;
        }
        $.ajax({url: "search.php?query=" + query + type_query}).done(function(response) {
            data = JSON.parse(response);
            if (data.length == 0) {
                $("#searchbox_chooser").text("I couldn't find anything about that query ('" + query + "'). Please enter a team #, problem letter, school name, or country 3-letter abbreviation.");
            } else if (data.length == 1) {
                window.location.assign(data[0].url);
            } else {
                var links = "<p>I found " + data.length + " teams that match:<br>";
                for (var idx in data) {
                    links += "<div class='search_query_result'><a href='" + data[idx].url + "'>" + data[idx].school_name + "</a></div>";
                }
                $("#searchbox_chooser").html(links);
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.17839707078925957, 'fraction_numerical': 0.0024410089503661514, 'mean_word_length': 2.0165644171779142, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5666578', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1437, 'n_words': 299}