diff --git a/global.js b/global.js index 259a95f..54c5780 100644 --- a/global.js +++ b/global.js @@ -53,6 +53,8 @@ document.addEventListener("DOMContentLoaded", function () { .then(() => { console.log("Bootstrap loaded successfully"); $(document).ready(function () { + $(".btn-secondary:contains('Back')").hide() + var embedded = getUrlParameter("embed"); var inModal = getUrlParameter("modal"); @@ -94,18 +96,43 @@ document.addEventListener("DOMContentLoaded", function () { encodeURIComponent(submitButton.val()); } + var sesskey = form.find('input[name=sesskey]').val(); + var attempt = form.find('input[name=attempt]').val(); + + console.log(sesskey); + console.log(attempt); + // Perform the AJAX request $.ajax({ url: form.attr("action"), // Use the form's action attribute type: form.attr("method"), // Use the form's method attribute data: formData, success: function (response) { - // Close the modal if `modal=1` is set - if (inModal === "1") { - window.top.closeQuizModal(); + if (form.attr("action").includes("/quiz/")) { + var finalize = "/mod/quiz/processattempt.php"; + var data = { + attempt: attempt, + finishattempt: 1, + sesskey: sesskey, + }; + $.post(finalize, data, function (response) { + console.log(response); + // Close the modal if `modal=1` is set + if (inModal === "1") { + window.top.closeQuizModal(); + } else { + // Else call the nextContent function + window.top.nextContent(); + } + }); } else { - // Else call the nextContent function - window.top.nextContent(); + // Close the modal if `modal=1` is set + if (inModal === "1") { + window.top.closeQuizModal(); + } else { + // Else call the nextContent function + window.top.nextContent(); + } } }, error: function (xhr, status, error) {