Skip to content

Commit

Permalink
New: Improve use of scorm_test_harness.html (fixes adaptlearning#247) (
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-steele authored Nov 28, 2022
1 parent 8949675 commit 479c2d1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ Determines the 'exit state' (`cmi.core.exit` in SCORM 1.2, `cmi.exit` in SCORM 2
##### \_exitStateIfComplete (string):
Determines the 'exit state' (`cmi.core.exit` in SCORM 1.2, `cmi.exit` in SCORM 2004) to set when the course has been completed. The default behaviour will cause the exit state to be set to an empty string for SCORM 1.2 courses, or `"normal"` for SCORM 2004 courses. The default behaviour should be left in place unless you are confident you know what you are doing! Note: if you are using SCORM 2004, you can set this to `"suspend"` to prevent the LMS from clearing all progress tracking when a previously-completed course is re-launched by the learner.

#### \_showCookieLmsResetButton (boolean):
Determines whether a reset button will be available to relaunch the course and optionally clear tracking data (scorm_test_harness.html only). The default is `false`.

<div float align=right><a href="#top">Back to Top</a></div>

## Notes
Expand Down
3 changes: 2 additions & 1 deletion example.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"_commitOnVisibilityChangeHidden": true,
"_exitStateIfIncomplete": "auto",
"_exitStateIfComplete": "auto"
}
},
"_showCookieLmsResetButton": false
}

// to be added to course/en/course.json (note: you only need to add the ones you want to change/translate)
Expand Down
9 changes: 9 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@
"help": "What exit status to use if the course is complete."
}
}
},
"_showCookieLmsResetButton": {
"type": "boolean",
"required": false,
"default": false,
"title": "Show reset button (scorm_test_harness.html only)",
"inputType": "Checkbox",
"validators": [],
"help": "If enabled, a reset button will be available to relaunch the course and optionally clear tracking data (scorm_test_harness.html only)."
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions required/offline_API_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ var GenericAPI = {

createResetButton: function() {
$('body').append($('<style id="spoor-clear-button">.spoor-reset-button { position:fixed; right:0px; bottom:0px; } </style>'));
var $button = $('<button class="spoor-reset-button">Reset</button>');
var $button = $('<button class="spoor-reset-button btn-text">Reset</button>');
$('body').append($button);
$button.on('click', function() {
this.reset();
alert('SCORM tracking cookie has been deleted!');
window.location.reload();
$button.on('click', function(e) {
if (!e.shiftKey) {
this.reset();
alert('SCORM tracking cookie has been deleted! Tip: shift-click reset to preserve cookie.');
}
window.location = window.location.pathname;
}.bind(this));
},

Expand All @@ -72,7 +74,11 @@ var GenericAPI = {
window.API = {

LMSInitialize: function() {
// if (window.ISCOOKIELMS !== false) this.createResetButton();
const Adapt = require('core/js/adapt');

if (window.ISCOOKIELMS !== false && Adapt?.config?.get('_spoor')?._showCookieLmsResetButton) {
this.createResetButton();
}
if (!this.fetch()) {
this.data['cmi.core.lesson_status'] = 'not attempted';
this.data['cmi.suspend_data'] = '';
Expand Down Expand Up @@ -122,7 +128,11 @@ window.API = {
window.API_1484_11 = {

Initialize: function() {
// if (window.ISCOOKIELMS !== false) this.createResetButton();
const Adapt = require('core/js/adapt');

if (window.ISCOOKIELMS !== false && Adapt?.config?.get('_spoor')?._showCookieLmsResetButton) {
this.createResetButton();
}
if (!this.fetch()) {
this.data['cmi.completion_status'] = 'not attempted';
this.data['cmi.suspend_data'] = '';
Expand Down
6 changes: 6 additions & 0 deletions schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
"_backboneForms": "Select"
}
}
},
"_showCookieLmsResetButton": {
"type": "boolean",
"title": "Show reset button (scorm_test_harness.html only)",
"description": "If enabled, a reset button will be available to relaunch the course and optionally clear tracking data (scorm_test_harness.html only).",
"default": false
}
}
}
Expand Down

0 comments on commit 479c2d1

Please sign in to comment.