feat: add embedded quiz modal functionality

Implemented support for triggering and closing an embedded quiz modal based on URL parameters. Refactored the URL parameter retrieval function and added conditional modal handling after AJAX success. Simplified feedback link handling and added modal management functions. This enhancement improves the user experience by enabling embedded quiz handling within modal dialogs
This commit is contained in:
Kumi 2024-07-02 17:43:06 +02:00
parent c3dff2394c
commit ffb3945e19
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 35 additions and 8 deletions

View file

@ -26,8 +26,7 @@ function getFeedbackLinks() {
}
});
// Return the 1-indexed list of href attributes
return feedbackLinks.map((href, index) => ({ index: index + 1, href }));
return feedbackLinks;
}
var currentScript = document.currentScript;
@ -136,6 +135,30 @@ loadScript(
nextActivity = nextContent;
window.top.nextContent = nextContent;
function openQuizModal(number) {
// Get the feedback link
var href = getFeedbackLinks()[number - 1];
href = href.replace("view", "complete");
// Go to embed mode
href = href + "&embed=1&modal=1";
// Open in #regular-modal-iframe
$("#regular-modal-iframe").attr("src", href);
// Show the modal
$("#regularModal").modal("show");
}
function closeQuizModal() {
$("#regularModal").modal("hide");
$("#regular-modal-iframe").attr("src", "about:blank");
}
window.top.openQuizModal = openQuizModal;
window.top.openModal = openQuizModal;
window.top.closeQuizModal = closeQuizModal;
$(currentScript)
.parent()
.append(
@ -147,7 +170,6 @@ loadScript(
var button = $("#contentButton-" + scriptId);
button.click(function () {
console.log("Button clicked!");
showContent(
contentUrl,
$(currentScript).closest("li.section").attr("id")