<commit_before>var config = {};

var state = {
    taskIndex: 0,
    taskInputs: [],
    taskOutputs: [],
    assignmentId: gup("assignmentId"),
    workerId: gup("workerId"),
};

/* HELPERS */
function saveTaskData() {
    state.taskOutputs[state.taskIndex] = custom.collectData();
}

function updateTask() {
    custom.showTask(state.taskInputs[state.taskIndex], state.taskOutputs[state.taskIndex]);
    $("#progress-bar").progress("set progress", state.taskIndex + 1);
    if (state.taskIndex == config.meta.numSubtasks - 1) {
        $("#next-button").addClass("disabled");
        $("#prev-button").removeClass("disabled");
        $("#submit-button").removeClass("disabled");
        $("#final-task-fields").css("display", "block");
    } else if (state.taskIndex == 0) {
        $("#next-button").removeClass("disabled");
        $("#prev-button").addClass("disabled");
        $("#submit-button").addClass("disabled");
        $("#final-task-fields").css("display", "none");
    } else {
        $("#next-button").removeClass("disabled");
        $("#prev-button").removeClass("disabled");
        $("#submit-button").addClass("disabled");
        $("#final-task-fields").css("display", "none");
    }
}

function nextTask() {
    if (state.taskIndex < config.meta.numSubtasks - 1) {
        saveTaskData();
        if (custom.validateTask(state.taskOutputs[state.taskIndex])) {
            state.taskIndex++;
            updateTask();
            clearMessage();
        } else {
            generateMessage("negative", "Please complete the current task!");
        }
    }
}

function prevTask() {
    if (state.taskIndex > 0) {
        saveTaskData();
        state.taskIndex--;
        updateTask();
    }
}

function toggleInstructions() {
    if ($("#experiment").css("display") == "none") {
        $("#experiment").css("display", "flex");
        $("#instructions").css("display", "none");
        updateTask();
    } else {
        $("#experiment").css("display", "none");
        $("#instructions").css("display", "flex");
    }
}

function clearMessage() {
    $("#message-field").html("");
}

function generateMessage(cls, header) {
    clearMessage();
    var messageStr = "<div class='ui message " + cls + "'>";
    messageStr += "<i class='close icon'></i>";
    messageStr += "<div class='header'>" + header + "</div></div>";

    var newMessage = $(messageStr);
    $("#message-field").append(newMessage);
    newMessage.click(function() {
        $(this).closest(".message").transition("fade");
    });
}

function submitHIT() {
    saveTaskData();
    clearMessage();
    $("#submit-button").addClass("loading");<commit_msg>bug fixes<commit_after>var config = {};

var state = {
    taskIndex: 0,
    taskInputs: [],
    taskOutputs: [],
    assignmentId: gup("assignmentId"),
    workerId: gup("workerId"),
};

/* HELPERS */
function saveTaskData() {
    state.taskOutputs[state.taskIndex] = custom.collectData();
}

function updateTask() {
    custom.showTask(state.taskInputs[state.taskIndex], state.taskOutputs[state.taskIndex]);
    $("#progress-bar").progress("set progress", state.taskIndex + 1);
    if (state.taskIndex == config.meta.numSubtasks - 1) {
        $("#next-button").addClass("disabled");
        if (state.taskIndex != 0) {
            $("#prev-button").removeClass("disabled");
        } else {
            $("#prev-button").addClass("disabled");
        }
        $("#submit-button").removeClass("disabled");
        $("#final-task-fields").css("display", "block");
    } else if (state.taskIndex == 0) {
        $("#next-button").removeClass("disabled");
        $("#prev-button").addClass("disabled");
        $("#submit-button").addClass("disabled");
        $("#final-task-fields").css("display", "none");
    } else {
        $("#next-button").removeClass("disabled");
        $("#prev-button").removeClass("disabled");
        $("#submit-button").addClass("disabled");
        $("#final-task-fields").css("display", "none");
    }
}

function nextTask() {
    if (state.taskIndex < config.meta.numSubtasks - 1) {
        saveTaskData();
        if (custom.validateTask(state.taskOutputs[state.taskIndex])) {
            state.taskIndex++;
            updateTask();
            clearMessage();
        } else {
            generateMessage("negative", "Please complete the current task!");
        }
    }
}

function prevTask() {
    if (state.taskIndex > 0) {
        saveTaskData();
        state.taskIndex--;
        updateTask();
    }
}

function toggleInstructions() {
    if ($("#experiment").css("display") == "none") {
        $("#experiment").css("display", "flex");
        $("#instructions").css("display", "none");
        updateTask();
    } else {
        saveTaskData();
        $("#experiment").css("display", "none");
        $("#instructions").css("display", "flex");
    }
}

function clearMessage() {
    $("#message-field").html("");
}

function generateMessage(cls, header) {
    clearMessage();
    var messageStr = "<div class='ui message " + cls + "'>";
    messageStr += "<i class='close icon'></i>";
    messageStr += "<div class='header'>" + header + "</div></div>";

    var newMessage = $(messageStr);
    $("#message-field").append(newMessage);
    newMessage.click(function() {
        $(this).closest(".message").transition("fade");
    });
}

function submitHIT() {
    saveTaskData();
    clearMessage();
    $("#submit-button").addClass("loading");
{'fraction_non_alphanumeric': 0.20970409851130306, 'fraction_numerical': 0.0023892666789193163, 'mean_word_length': 3.031111111111111, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7174168', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1587, 'n_words': 254}