2024-07-05 09:13:58 +00:00
|
|
|
(function () {
|
|
|
|
function loadScript(url, integrity, crossorigin) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const script = document.createElement("script");
|
|
|
|
script.src = url;
|
|
|
|
script.integrity = integrity;
|
|
|
|
script.crossOrigin = crossorigin;
|
|
|
|
script.onload = () => resolve(script);
|
|
|
|
script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
|
|
|
|
document.head.appendChild(script);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFeedbackLinks() {
|
|
|
|
const links = document.querySelectorAll("a.stretched-link");
|
|
|
|
const feedbackLinks = [];
|
|
|
|
links.forEach((link) => {
|
|
|
|
const href = link.getAttribute("href");
|
|
|
|
if (href) {
|
|
|
|
if (href.includes("/feedback/")) {
|
|
|
|
feedbackLinks.push(href);
|
|
|
|
} else if (href.includes("/quiz/")) {
|
|
|
|
feedbackLinks.push(href);
|
|
|
|
}
|
2024-07-04 12:31:27 +00:00
|
|
|
}
|
2024-07-05 09:13:58 +00:00
|
|
|
});
|
|
|
|
return feedbackLinks;
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-07-05 09:13:58 +00:00
|
|
|
var currentScript = document.currentScript;
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-06 09:09:44 +00:00
|
|
|
let openNextFlag = false;
|
|
|
|
|
2024-08-05 10:10:33 +00:00
|
|
|
function waitForGlobalVariable(variableName) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
const checkVariable = setInterval(() => {
|
|
|
|
if (window[variableName]) {
|
|
|
|
clearInterval(checkVariable);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
waitForGlobalVariable("$")
|
2024-07-05 09:13:58 +00:00
|
|
|
.then(() => {
|
2024-09-23 07:00:01 +00:00
|
|
|
waitForGlobalVariable("bootstrap")
|
|
|
|
.then(() => {
|
|
|
|
console.log("Bootstrap loaded successfully");
|
2024-08-05 10:10:33 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
var myModal = $("#fullScreenModal");
|
2024-08-05 10:10:33 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
myModal[0].addEventListener("shown.bs.modal", function () {
|
|
|
|
const modalIframe = window.$("#modal-iframe");
|
2024-08-05 10:10:33 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
modalIframe.css("width", "100%");
|
|
|
|
modalIframe.css("height", "100%");
|
|
|
|
modalIframe.css("border", "none");
|
2024-09-23 06:28:35 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
// Add event handler to iframe load events
|
|
|
|
modalIframe[0].addEventListener("load", function () {
|
|
|
|
const newLocation = modalIframe[0].contentWindow.location.href;
|
2024-09-23 06:28:35 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
// If the iframe now contains a course page, open it in the parent window
|
|
|
|
if (newLocation.includes("/course/view.php?id=")) {
|
|
|
|
window.top.location.href = newLocation;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2024-08-05 10:10:33 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
var scriptId = "script-" + Math.random().toString(36).substring(2, 9);
|
|
|
|
currentScript.id = scriptId;
|
2024-07-05 09:13:58 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
var contentUrl = "/mod/exp360/view_content.php?id=" + $(currentScript).attr("data-activity-id");
|
2024-07-05 09:13:58 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
function openInModal(url, block) {
|
|
|
|
$("#modal-iframe").attr("src", url);
|
|
|
|
if (block) {
|
|
|
|
$("#fullScreenModal").attr("data-block", block);
|
|
|
|
} else {
|
|
|
|
$("#fullScreenModal").removeAttr("data-block");
|
|
|
|
}
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
function showContent(url, block) {
|
|
|
|
bootstrap.Modal.getOrCreateInstance(
|
|
|
|
document.getElementById("fullScreenModal")
|
|
|
|
).show();
|
|
|
|
if (url) {
|
|
|
|
openInModal(url, block);
|
|
|
|
}
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
function hideContent() {
|
|
|
|
bootstrap.Modal.getOrCreateInstance(
|
|
|
|
document.getElementById("fullScreenModal")
|
|
|
|
).hide();
|
|
|
|
openInModal("about:blank");
|
|
|
|
}
|
2024-07-04 12:31:27 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
async function nextContent() {
|
|
|
|
var modal = $("#fullScreenModal");
|
|
|
|
var currentLi = $("#" + modal.attr("data-block"));
|
2024-07-04 12:31:27 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
var nextLi = currentLi.next("li.section");
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
var aLink = nextLi.find("a.stretched-link");
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
if (aLink.length > 0) {
|
|
|
|
let hrefValue = aLink.attr("href");
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
if (hrefValue.includes("feedback")) {
|
|
|
|
hrefValue = hrefValue.replace("view", "complete");
|
|
|
|
hrefValue = hrefValue + "&embed=1";
|
|
|
|
} else if (hrefValue.includes("/quiz/")) {
|
|
|
|
hrefValue = hrefValue.replace("view", "attempt");
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
try {
|
|
|
|
const response = await fetch(hrefValue);
|
|
|
|
hrefValue = response.url;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error fetching the URL:', error);
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
hrefValue = hrefValue + "&embed=1";
|
|
|
|
}
|
2024-07-04 12:31:27 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
return openInModal(hrefValue, nextLi.attr("id"));
|
|
|
|
} else {
|
|
|
|
var button = nextLi.find("button.btn-primary");
|
2024-07-04 12:31:27 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
if (button.length > 0) {
|
|
|
|
return button.click();
|
|
|
|
}
|
|
|
|
}
|
2024-07-04 12:31:27 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
hideContent();
|
|
|
|
}
|
2024-07-02 15:43:06 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
function openUrlInQuizModal(href) {
|
|
|
|
$("#regular-modal-iframe").attr("src", href);
|
|
|
|
$("#regularModal").modal("show");
|
|
|
|
}
|
2024-07-08 08:28:46 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
// Function to open a quiz modal
|
|
|
|
async function openQuizModal(number, openNext = true) {
|
|
|
|
openNextFlag = openNext; // Store the flag in the global variable
|
|
|
|
|
|
|
|
let href = getFeedbackLinks()[number - 1];
|
|
|
|
const quizLink = $(`a.stretched-link[href="${href}"]`).closest("li.section");
|
|
|
|
|
|
|
|
if (href.includes("/feedback/")) {
|
|
|
|
href = href.replace("view", "complete");
|
|
|
|
} else if (href.includes("/quiz/")) {
|
|
|
|
href = href.replace("view", "attempt");
|
|
|
|
try {
|
|
|
|
const response = await fetch(href);
|
|
|
|
href = response.url;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error fetching the URL:', error);
|
|
|
|
}
|
|
|
|
}
|
2024-09-06 09:09:44 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
href = href + "&embed=1&modal=1";
|
|
|
|
openUrlInQuizModal(href);
|
2024-07-02 15:43:06 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
if (openNext) {
|
|
|
|
// Set the data-block attribute to the block containing the current quiz
|
|
|
|
$("#fullScreenModal").attr("data-block", quizLink.attr("id"));
|
|
|
|
}
|
2024-07-05 09:13:58 +00:00
|
|
|
}
|
2024-07-02 15:43:06 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
// Function to close the quiz modal
|
|
|
|
function closeQuizModal() {
|
|
|
|
$("#regularModal").modal("hide");
|
|
|
|
$("#regular-modal-iframe").attr("src", "about:blank");
|
2024-09-06 09:09:44 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
if (openNextFlag) {
|
|
|
|
nextContent(); // Open the next activity
|
|
|
|
}
|
|
|
|
}
|
2024-07-02 14:20:55 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
function goToCourse(id) {
|
|
|
|
window.top.location.href = "/course/view.php?id=" + id;
|
|
|
|
}
|
2024-09-23 06:50:58 +00:00
|
|
|
|
2024-09-23 07:00:01 +00:00
|
|
|
// Attach global functions to window.top
|
|
|
|
window.top.nextContent = nextContent;
|
|
|
|
window.top.openQuizModal = openQuizModal;
|
|
|
|
window.top.openModal = openQuizModal;
|
|
|
|
window.top.closeQuizModal = closeQuizModal;
|
|
|
|
window.top.goToQuiz = window.top.nextContent;
|
|
|
|
window.top.goToCourse = goToCourse;
|
|
|
|
|
|
|
|
var contentName = $(currentScript).attr("data-activity-name");
|
|
|
|
|
|
|
|
$(currentScript)
|
|
|
|
.parent()
|
|
|
|
.append(
|
|
|
|
`<button id="contentButton-` +
|
|
|
|
scriptId +
|
|
|
|
`" class="btn btn-primary" type="button">` +
|
|
|
|
contentName +
|
|
|
|
`</button>`
|
|
|
|
);
|
|
|
|
|
|
|
|
var button = $("#contentButton-" + scriptId);
|
|
|
|
button.click(function () {
|
|
|
|
showContent(
|
|
|
|
contentUrl,
|
|
|
|
$(currentScript).closest("li.section").attr("id")
|
|
|
|
);
|
|
|
|
});
|
2024-09-23 07:17:45 +00:00
|
|
|
|
2024-09-23 07:46:47 +00:00
|
|
|
const editMode = $(".inplaceeditable").length > 0;
|
|
|
|
|
2024-09-23 07:48:12 +00:00
|
|
|
if (!editMode) {
|
2024-09-23 07:46:47 +00:00
|
|
|
var sections = $('.course-section');
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
sections.each(function (index) {
|
|
|
|
if (!found && $(this).find('script[data-activity-id]').length > 0) {
|
|
|
|
// Set found to true when the first matching section is found
|
|
|
|
found = true;
|
|
|
|
} else if (found) {
|
|
|
|
// Hide all .section elements after the found one
|
|
|
|
$(this).css('visibility', 'hidden');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-09-23 07:00:01 +00:00
|
|
|
})
|
2024-07-05 09:13:58 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-08-05 10:10:33 +00:00
|
|
|
console.error(error.message);
|
2024-07-02 14:20:55 +00:00
|
|
|
});
|
2024-07-05 09:13:58 +00:00
|
|
|
})();
|