diff --git a/.DS_Store b/.DS_Store index be5e202..cad951e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ce416f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +.DS_Store +*.zip diff --git a/README.md b/README.md index eaa4dcf..6269fcd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # TODO -- Make sure we warn if score not in bounds. - Display current score on page. - display pass/fail onscreen. - calculate total time spent `session_time`. diff --git a/css/style.css b/css/style.css index 269949b..f89a1b7 100644 --- a/css/style.css +++ b/css/style.css @@ -1,5 +1,16 @@ -h1 { +h1, h2, h3, p { font-family: Arial, Helvetica, sans-serif; color: darkgray; +} + +.fullscreen { + position: fixed; + left: 0; + top: 0; + height: 100%; + width: 0; + z-index: 1; + overflow-x: hidden; /* Disable horizontal scroll */ + transition: 0.5s; } \ No newline at end of file diff --git a/imsmanifest.xml b/imsmanifest.xml index 3aa0c98..e2cb51a 100755 --- a/imsmanifest.xml +++ b/imsmanifest.xml @@ -37,6 +37,7 @@ intra-SCO navigation. + diff --git a/index.html b/index.html index c2874dd..0d9c5fc 100644 --- a/index.html +++ b/index.html @@ -14,10 +14,18 @@ -

Simple SCORM Template

-

your name here...

- - - +
+

Simple SCORM Template

+
+
+

your name here...

+

+

+
+ + + +
+
diff --git a/js/scormfunctions.js b/js/scormfunctions.js index 21c03c9..ecd72f7 100755 --- a/js/scormfunctions.js +++ b/js/scormfunctions.js @@ -16,89 +16,6 @@ some basic SCORM error handling. //Include the standard ADL-supplied API discovery algorithm -// list of writable SCORM data values: - -const scormData = { - cmi: { - core: { - student_id: { - readable: true, - description: 'student username', - datatype: 'string' - }, - student_name: { - readable: true, - description: 'student name', - datatype: 'string' - }, - lesson_location: { - readable: true, - writable: true, - description: 'bookmark', - datatype: 'string' - }, - credit: { - readable: true, - description: 'bookmark', - datatype: 'string', - options: [ - 'credit', - 'no-credit' - ] - }, - lesson_status: { - readable: true, - writable: true, - description: 'bookmark', - datatype: 'string', - options: [ - 'passed', - 'completed', - 'failed', - 'incomplete', - 'browsed', - 'not attempted' - ] - }, - entry: { - readable: true, - description: 'Asserts whether the learner has previously accessed the SCO', - datatype: 'string', - options: [ - 'ab-initio', - 'resume', - '' - ] - }, - score: { - raw: { - readable: true, - writable: true, - description: 'the performance of the learner', - datatype: 'number' - }, - max: { - readable: true, - writable: true, - description: 'Maximum value in the range for the raw score', - datatype: 'number' - }, - min: { - readable: true, - writable: true, - description: 'Minimum value in the range for the raw score', - datatype: 'number' - } - }, - total_time: { - readable: true, - description: 'Sum of all of the learner’s session times accumulated in the current learner attempt', - datatype: 'CMITimespan' - } - } - } -} - /////////////////////////////////////////// //Begin ADL-provided API discovery algorithm /////////////////////////////////////////// @@ -129,7 +46,7 @@ function findAPI(win) { } /** - * open the API and return it. + * open the API and return */ function getAPI() { // start by looking for the API in the current window diff --git a/js/script.js b/js/script.js index eca9224..6b855ce 100644 --- a/js/script.js +++ b/js/script.js @@ -1,4 +1,7 @@ +const MIN_SCORE = 0 +let MAX_SCORE = 100 + document.addEventListener('DOMContentLoaded', event => { console.log('DOM CONTENT LOADED') document.querySelector('button#update').addEventListener('click', event => { @@ -8,6 +11,7 @@ document.addEventListener('DOMContentLoaded', event => { }) document.querySelector('button#end').addEventListener('click', event => { console.log('END BUTTON CLICKED') + document.querySelector('section').hidden = true endGame(parseInt(document.querySelector('input').value)) ScormProcessFinish() }) @@ -16,18 +20,26 @@ document.addEventListener('DOMContentLoaded', event => { function updateScore(score) { score = parseInt(score) console.log(`score: ${score}`) - ScormProcessSetValue('cmi.core.score.raw', parseInt(score)) + const percent = (score / MAX_SCORE) * 100 + if(!isNaN(score) && score >= MIN_SCORE && score <= MAX_SCORE) { // is the score a number in a valid range + ScormProcessSetValue('cmi.core.score.raw', percent) + } else { + console.warn(`invalid score (${score}): needs to be a number between ${MIN_SCORE} and ${MAX_SCORE}`) + } + return percent } function endGame(score) { - updateScore(score) + const percent = updateScore(score) + document.querySelector('h2').innerText = `${percent}%` // set the status const mastery = parseInt(ScormProcessGetValue('cmi.student_data.mastery_score')) console.log(`mastery: (${mastery})`) if(!isNaN(mastery)) { // NaN if mastery score not provided by the API - const status = parseInt(score) >= mastery ? 'passed' : 'failed' // if mastery score then pass/fail + const status = percent >= mastery ? 'passed' : 'failed' // if mastery score then pass/fail console.log(`status: (${status})`) ScormProcessSetValue('cmi.core.lesson_status', status) + document.querySelector('h3').innerText = `status: ${status.toUpperCase()}` } else { console.log('status is: (completed)') ScormProcessSetValue('cmi.core.lesson_status', 'completed') // if no mastery then completed @@ -47,8 +59,11 @@ window.addEventListener('load', event => { document.querySelector('p').innerText = name const username = ScormProcessGetValue('cmi.core.student_id') console.log(`student ID: ${username}`) - ScormProcessSetValue('cmi.core.score.min', 0) - ScormProcessSetValue('cmi.core.score.max', 100) + const maxScore = parseInt(ScormProcessGetValue('cmi.core.score.max')) // does the LMS provide a max score? + console.log(`moodle max score: (${maxScore})`) + ScormProcessSetValue('cmi.core.score.min', MIN_SCORE) + MAX_SCORE = !isNaN(maxScore) ? maxScore : MAX_SCORE + ScormProcessSetValue('cmi.core.score.max', MAX_SCORE) }) window.addEventListener('beforeunload', event => { diff --git a/scormData.json b/scormData.json new file mode 100644 index 0000000..e3ebc98 --- /dev/null +++ b/scormData.json @@ -0,0 +1,81 @@ + +{ + "cmi": { + "core": { + "student_id": { + "readable": true, + "description": "student username", + "datatype": "string" + }, + "student_name": { + "readable": true, + "description": "student name", + "datatype": "string" + }, + "lesson_location": { + "readable": true, + "writable": true, + "description": "bookmark", + "datatype": "string" + }, + "credit": { + "readable": true, + "description": "bookmark", + "datatype": "string", + "options": [ + "credit", + "no-credit" + ] + }, + "lesson_status": { + "readable": true, + "writable": true, + "description": "bookmark", + "datatype": "string", + "options": [ + "passed", + "completed", + "failed", + "incomplete", + "browsed", + "not attempted" + ] + }, + "entry": { + "readable": true, + "description": "Asserts whether the learner has previously accessed the SCO", + "datatype": "string", + "options": [ + "ab-initio", + "resume", + "" + ] + }, + "score": { + "raw": { + "readable": true, + "writable": true, + "description": "the performance of the learner", + "datatype": "number" + }, + "max": { + "readable": true, + "writable": true, + "description": "Maximum value in the range for the raw score", + "datatype": "number" + }, + "min": { + "readable": true, + "writable": true, + "description": "Minimum value in the range for the raw score", + "datatype": "number" + } + }, + "total_time": { + "readable": true, + "description": "Sum of all of the learner’s session times accumulated in the current learner attempt", + "datatype": "CMITimespan" + } + } + } +} diff --git a/template 1.9.zip b/template 1.9.zip deleted file mode 100644 index 5c6549b..0000000 Binary files a/template 1.9.zip and /dev/null differ