aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-08-20 13:28:33 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-08-20 13:28:33 +0200
commit85b8597aeb14c59d4a890a034a2a551adbf56008 (patch)
tree4b52ea13b1ad1e0ba34dc77dcef4afa94f145350
parent63ade5e237bdfc2296e5de243cf2747991ad72a3 (diff)
downloadunterricht-85b8597aeb14c59d4a890a034a2a551adbf56008.tar.gz
unterricht-85b8597aeb14c59d4a890a034a2a551adbf56008.zip
planet: add script to autoembed SCORM packages in an iframe
-rw-r--r--Info/9/3/Planet/templates/h5p-autoembed.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/Info/9/3/Planet/templates/h5p-autoembed.js b/Info/9/3/Planet/templates/h5p-autoembed.js
index 1dd51e42..8c41e6e5 100644
--- a/Info/9/3/Planet/templates/h5p-autoembed.js
+++ b/Info/9/3/Planet/templates/h5p-autoembed.js
@@ -25,10 +25,43 @@ for (const div of autoEmbedLinksDivs) {
div.parentNode.replaceChild(iframe, div);
}
-if(loadAutoResizerJs) {
+if (loadAutoResizerJs) {
let head = document.getElementsByTagName('head')[0];
let js = document.createElement("script");
js.type = "text/javascript";
js.src="https://lernplattform.bycs.de/mod/hvp/library/js/h5p-resizer.js";
head.appendChild(js);
}
+
+async function embedScorm() {
+ for (const div of document.querySelectorAll(".scorm-autoembed")) {
+ const autoEmbedLink = div.querySelector("a.autolink");
+ const autoEmbedUrl = new URL(autoEmbedLink.href);
+
+ const scormActivityRes = await fetch(autoEmbedUrl);
+ const scormActivityDoc = new DOMParser().parseFromString(await scormActivityRes.text(), "text/html");
+
+ const s = document.createElement("script");
+ s.text = scormActivityDoc.scripts[4].text;
+ s.setAttribute("type", "text/javascript");
+ document.body.appendChild(s);
+
+ const iframe = document.createElement('iframe');
+ // Concatenate the URL to prevent Moodle's auto link feature to mess with the url
+ iframe.src = `/mod/scorm/player.php?a=${scormplayerdata.scorm}&currentorg=${scormplayerdata.currentorg}&scoid=${scormplayerdata.sco}&sesskey=${M.cfg.sesskey}&display=popup&mode=normal`
+ iframe.frameborder = div.frameborder ? div.frameborder : 0;
+ iframe.allowfullscreen = div.allowfullscreen ? div.allowfullscreen : "allowfullscreen";
+ iframe.title = autoEmbedLink.title;
+ if (div.style.width) {
+ iframe.width = div.style.width;
+ }
+ if (div.style.height) {
+ iframe.height = div.style.height;
+ }
+
+ // Replace the div with the new iframe
+ div.parentNode.replaceChild(iframe, div);
+ }
+}
+
+embedScorm();