diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-05-19 16:08:36 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-05-19 16:08:36 +0200 |
| commit | f46cbece1281ded261744393178fa37c75d7705f (patch) | |
| tree | 1445e5f482734df676273cd119624fbd74ce3eeb /Info/9/3/Planet/templates/h5p-autoembed.js | |
| parent | e0a4268f6ebd572db2ad2b9949e9939097725056 (diff) | |
| download | unterricht-f46cbece1281ded261744393178fa37c75d7705f.tar.gz unterricht-f46cbece1281ded261744393178fa37c75d7705f.zip | |
planet: auto embed H5P activities into the pages
Diffstat (limited to 'Info/9/3/Planet/templates/h5p-autoembed.js')
| -rw-r--r-- | Info/9/3/Planet/templates/h5p-autoembed.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Info/9/3/Planet/templates/h5p-autoembed.js b/Info/9/3/Planet/templates/h5p-autoembed.js new file mode 100644 index 00000000..a6d89874 --- /dev/null +++ b/Info/9/3/Planet/templates/h5p-autoembed.js @@ -0,0 +1,34 @@ +const autoEmbedLinksDivs = document.querySelectorAll(".h5p-autoembed"); +let loadAutoResizerJs = false; +for (div of autoEmbedLinksDivs) { + const autoEmbedLink = div.querySelector("a.autolink"); + const autoEmbedUrl = new URL(autoEmbedLink.href); + const autoEmbedId = autoEmbedUrl.searchParams.get("id"); + const iframe = document.createElement('iframe'); + // Concatenate the URL to prevent Moodle's auto link feature to mess with the url + iframe.src = "https://" + "lernplattform.bycs.de/mod/hvp/embed.php?id=" + autoEmbedId; + iframe.frameborder = div.frameborder ? div.frameborder : 0; + iframe.allowfullscreen = div.allowfullscreen ? div.allowfullscreen : "allowfullscreen"; + iframe.title = autoEmbedLink.title; + if (div.width) { + iframe.width = div.width; + } else { + loadAutoResizerJs = true; + } + if (div.height) { + iframe.height = div.height; + } else { + loadAutoResizerJs = true; + } + + // Replace the div with the new iframe + div.parentNode.replaceChild(iframe, div); +} + +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); +} |
