Skip to content

Instantly share code, notes, and snippets.

@marcellamaki
Created September 12, 2024 15:11
Show Gist options
  • Save marcellamaki/b349270eedea392e3622f9bafed04821 to your computer and use it in GitHub Desktop.
Save marcellamaki/b349270eedea392e3622f9bafed04821 to your computer and use it in GitHub Desktop.
Sample SCORM content
/scorm-package
/api/
SCORM_API.js. // make sure this file is nested in the folder for this to work!
index.html
imsmanifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="com.example.scorm1.2.test"
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
http://www.imsglobal.org/xsd/imscp_rootv1p1p2.xsd
http://www.adlnet.org/xsd/adlcp_rootv1p2
http://www.adlnet.org/xsd/adlcp_rootv1p2.xsd">
<organizations default="org1">
<organization identifier="org1">
<title>SCORM 1.2 Test Course</title>
<item identifier="item1" identifierref="resource1">
<title>SCORM 1.2 Test Module</title>
</item>
</organization>
</organizations>
<resources>
<resource identifier="resource1" type="webcontent" href="index.html" adlcp:scormtype="sco">
<file href="index.html"/>
<file href="api/SCORM_API.js"/>
</resource>
</resources>
</manifest>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SCORM 1.2 Test</title>
<script src="api/SCORM_API.js"></script>
<script>
let scorm = null;
window.onload = function () {
scorm = new ScormAPI();
scorm.initialize(); // Initialize the SCORM API when the page loads
};
window.onbeforeunload = function () {
scorm.terminate(); // Terminate the SCORM session before the page unloads
};
function completeCourse() {
scorm.setLessonStatus('completed'); // Mark the course as completed
scorm.commit(); // Commit data to the LMS
alert('Course Completed!');
}
</script>
</head>
<body>
<h1>Welcome to SCORM 1.2 Content</h1>
<button onclick="completeCourse()">Complete Course</button>
</body>
</html>
function ScormAPI() {
this.api = null;
this.initialize = function () {
this.api = this.getAPI();
if (this.api) {
return this.api.LMSInitialize("");
}
return false;
};
this.terminate = function () {
if (this.api) {
return this.api.LMSFinish("");
}
return false;
};
this.setLessonStatus = function (status) {
if (this.api) {
return this.api.LMSSetValue("cmi.core.lesson_status", status);
}
return false;
};
this.commit = function () {
if (this.api) {
return this.api.LMSCommit("");
}
return false;
};
this.getAPI = function () {
var win = window;
while (win.API == null && win.parent != null && win.parent != win) {
win = win.parent;
}
return win.API;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment