Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SCORM #367

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _sources/lectures/TWP52_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ Review
+ OptionMenu()



.. raw:: html
:file: ../../scorm_package/chapter1.html

.. disqus::
:shortname: pyzombis
Expand Down
45 changes: 45 additions & 0 deletions _static/APIWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SCORM API Wrapper
var findAPITries = 0;
var API = null;

function findAPI(win) {
while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
findAPITries++;
if (findAPITries > 7) {
return null;
}
win = win.parent;
}
return win.API;
}

function getAPI() {
var theAPI = findAPI(window);
if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {
theAPI = findAPI(window.opener);
}
if (theAPI == null) {
alert("Unable to find an API adapter");
}
return theAPI;
}

function initializeAPI() {
API = getAPI();
if (API != null) {
API.LMSInitialize("");
}
}

function terminateAPI() {
if (API != null) {
API.LMSFinish("");
}
}

function setProgress(progress) {
if (API != null) {
API.LMSSetValue("cmi.core.lesson_status", progress);
API.LMSCommit("");
}
}
40 changes: 40 additions & 0 deletions _static/SCORMFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SCORM Functions
function loadPage() {
initializeAPI();
console.log("SCORM API initialized.");
}

function unloadPage() {
terminateAPI();
console.log("SCORM API terminated.");
}

function loadChapter(chapter) {
loadPage();

var completionStatus = API.LMSGetValue("cmi.core.lesson_status");

if (completionStatus === "completed") {
document.getElementById("completion-status").innerText = "This chapter has been completed.";
document.getElementById("complete-button").style.display = "none";
} else {
document.getElementById("completion-status").innerText = "This chapter has not been completed.";
document.getElementById("reset-button").style.display = "none";
}
}

function completeChapter(chapter) {
setProgress("completed");
alert(chapter + " completed! Progress recorded.");
document.getElementById("completion-status").innerText = "This chapter has been completed.";
document.getElementById("complete-button").style.display = "none";
document.getElementById("reset-button").style.display = "block";
}

function resetChapter(chapter) {
setProgress("incomplete");
alert(chapter + " reset to incomplete.");
document.getElementById("completion-status").innerText = "This chapter has not been completed.";
document.getElementById("complete-button").style.display = "block";
document.getElementById("reset-button").style.display = "none";
}
2 changes: 2 additions & 0 deletions _templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@
{% endraw %}
{% endif %}

<script src="../scorm_package/scripts/scorm_functions.js"></script>

{% endblock %}

{# Silence the sidebar's, relbar's #}
Expand Down
16 changes: 16 additions & 0 deletions scorm_package/chapter1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 1</title>
<script src="../_static/APIWrapper.js"></script>
<script src="../_static/SCORMFunctions.js"></script>
</head>
<body onload="loadChapter('chapter1')" onunload="unloadPage()">
<h1>Chapter 1: Introduction</h1>
<p id="completion-status">Checking completion status...</p>
<button id="complete-button" onclick="completeChapter('chapter1')">Mark this Chapter as Completed</button>
<button id="reset-button" onclick="resetChapter('chapter1')">Reset Progress</button>
</body>
</html>
15 changes: 15 additions & 0 deletions scorm_package/chapter2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 2</title>
<script src="../_static/APIWrapper.js"></script>
<script src="../_static/SCORMFunctions.js"></script>
</head>
<body onload="loadPage()" onunload="unloadPage()">
<h1>Chapter 2: Uff</h1>
<p>Complete this chapter by clicking the button below.</p>
<button onclick="completeChapter('chapter2')">Complete Chapter 2</button>
</body>
</html>
38 changes: 38 additions & 0 deletions scorm_package/imsmanifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="com.example.scormminimal" version="1.2"
xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd">
<metadata>
<schema>ADL SCORM</schema>
<schemaversion>1.2</schemaversion>
<adlcp:location>metadata.xml</adlcp:location>
</metadata>
<organizations default="org">
<organization identifier="org">
<title>Your Course Title</title>
<item identifier="item1" identifierref="resource1">
<title>Chapter 1</title>
</item>
<item identifier="item2" identifierref="resource2">
<title>Chapter 2</title>
</item>
<!-- Add more items for additional chapters -->
</organization>
</organizations>
<resources>
<resource identifier="resource1" type="webcontent" adlcp:scormtype="sco" href="chapter1.html">
<file href="chapter1.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
</resource>
<resource identifier="resource2" type="webcontent" adlcp:scormtype="sco" href="chapter2.html">
<file href="chapter2.html"/>
<file href="../_static/SCORMFunctions.js"/>
<file href="../_static/APIWrapper.js"/>
</resource>
<!-- Add more resources for additional chapters -->
</resources>
</manifest>
Binary file added scorm_package/scorm_package.zip
Binary file not shown.
Loading