{"size": 2513, "ext": "js", "max_stars_repo_path": "django/ctflex/static/ctflex/js/game.js", "max_stars_repo_name": "milesmcc/pactf-2018", "max_stars_repo_stars_event_min_datetime": "2016-02-29T00:30:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-18T17:47:54.000Z", "max_issues_repo_path": "django/ctflex/static/ctflex/js/game.js", "max_issues_repo_name": "milesmcc/pactf-2018", "max_issues_repo_issues_event_min_datetime": "2018-06-21T21:55:33.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-25T12:49:59.000Z", "max_forks_repo_path": "django/ctflex/static/ctflex/js/game.js", "max_forks_repo_name": "milesmcc/pactf-2018", "max_forks_repo_forks_event_min_datetime": "2016-04-01T14:57:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-01T03:37:21.000Z"}
{"max_stars_count": 10, "max_issues_count": 1, "max_forks_count": 8, "avg_line_length": 36.9558823529, "max_line_length": 171, "alphanum_fraction": 0.5029844807}
jQuery(document).ready(function () {


    Array.prototype.forEach.call(jQuery(".problem"), function (prob) {

        jQuery(".problem-header", prob).on('click', function (event) {
            if (!$(event.target).closest('.header-link').length) {
                jQuery(".problem-body", prob).toggle('show');
            }
        });

        // Hint visibility toggling
        jQuery(".hint-button", prob).on('click', function (event) {
            jQuery('.hint-content', prob).toggle('show');
        });
    });

});


// Submit function for flag submission forms
function submit_flag(problem_id) {

    // Without the try, if there's an error, the page will reload because of non-AJAX form submission
    try {

        var data = jQuery("#" + problem_id.toString() + " .problem-form").serialize();

        $.ajax({
            url: "/api/submit_flag/" + problem_id + "/",
            type: "POST",
            data: data,

            // XXX(Yatharth): Review
            success: function (response) {
                if (response.status <= 0) {
                    jQuery("#" + problem_id + " .problem-body").toggle('show');
                    jQuery("#" + problem_id + " .problem-header").html(function (index, html) {
                        return html.replace(/Unsolved/, 'Solved');
                    });
                    jQuery("#" + problem_id + " .problem-form").html(function (index, html) {
                        return "<p>Your team has already solved this problem!</p>";
                    })
                }

                if (response.status === 0) {
                    jQuery("#navbar-score").text(function (i, value) {
                        return parseInt(value) + parseInt(jQuery("#" + problem_id + " .problem-points").text());
                    });
                }

                var prefix = response.status === 0 ? "Success! " : response.status === 1 ? "Incorrect! " : "";
                var style = response.status === -1 ? "info" : response.status === 0 ? "success" : "error";
                jQuery.notify(prefix + response.message, style);
            },

            error: function (xhr, msg, err) {
                jQuery.notify("There was an error (" + xhr.status + ") processing your request. Try refreshing the page. If that doesn't work, please email us!", "error");
            }
        });

    }
    catch (e) {
        jQuery.notify("Error contacting the PACTF server. Please wait and try again.", "warn");
        console.debug(e);
    }
}
