Skip to content

Commit

Permalink
Merge branch 'master' into issue/299
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-mediakitchen committed Dec 11, 2023
2 parents 4245ceb + be40c0f commit 1b7684a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapt-contrib-spoor",
"version": "5.9.0",
"version": "5.9.3",
"framework": ">=5.31.31",
"homepage": "https://github.com/adaptlearning/adapt-contrib-spoor",
"bugs": "https://github.com/adaptlearning/adapt-contrib-spoor/issues",
Expand Down
5 changes: 3 additions & 2 deletions js/adapt-stateful-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class StatefulSession extends Backbone.Controller {
if (shouldCommitOnVisibilityChange) {
document.addEventListener('visibilitychange', this.onVisibilityChange);
}
$(window).on('beforeunload unload', this.endSession);
$(window).on('beforeunload unload pagehide', this.endSession);
}

async saveSessionState() {
Expand Down Expand Up @@ -204,6 +204,7 @@ export default class StatefulSession extends Backbone.Controller {

onQuestionRecordInteraction(questionView) {
if (!this._shouldRecordInteractions) return;
if (!this.scorm.isSupported('cmi.interactions._count')) return;
// View functions are deprecated: getResponseType, getResponse, isCorrect, getLatency
const questionModel = questionView.model;
const responseType = (questionModel.getResponseType ? questionModel.getResponseType() : questionView.getResponseType());
Expand Down Expand Up @@ -261,7 +262,7 @@ export default class StatefulSession extends Backbone.Controller {
}

removeEventListeners() {
$(window).off('beforeunload unload', this.endSession);
$(window).off('beforeunload unload pagehide', this.endSession);
document.removeEventListener('visibilitychange', this.onVisibilityChange);
this.stopListening();
}
Expand Down
84 changes: 41 additions & 43 deletions js/scorm/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,63 +517,61 @@ class ScormWrapper {
async handleInitializeError() {
if (!Data.isReady) await Data.whenReady();
Adapt.trigger('tracking:initializeError');
// defer error to allow other plugins which may be handling errors to execute
_.defer(() => this.handleError(new ScormError(CLIENT_COULD_NOT_CONNECT)));
this.handleError(new ScormError(CLIENT_COULD_NOT_CONNECT));
}

handleConnectionError(callback = null) {
async handleConnectionError(callback = null) {
if (!Data.isReady) await Data.whenReady();
Adapt.trigger('tracking:connectionError', callback);
this.handleError(new ScormError(CLIENT_NOT_CONNECTED));
}

handleDataError(error) {
async handleDataError(error) {
if (!Data.isReady) await Data.whenReady();
Adapt.trigger('tracking:dataError');
this.handleError(error);
}

handleFinishError(error) {
async handleFinishError(error) {
if (!Data.isReady) await Data.whenReady();
Adapt.trigger('tracking:terminationError');
this.handleError(error);
}

handleError(error) {
if ('value' in error.data) {
// because some browsers (e.g. Firefox) don't like displaying very long strings in the window.confirm dialog
if (error.data.value.length && error.data.value.length > 80) error.data.value = error.data.value.slice(0, 80) + '...';
// if the value being set is an empty string, ensure it displays in the error as ''
if (error.data.value === '') error.data.value = '\'\'';
}

if (!Adapt.course) return;

const config = Adapt.course.get('_spoor');
const defaultMessages = ScormError.defaultMessages;
const configMessages = config?.['_messages'] || {};
const messages = Object.assign({}, defaultMessages, configMessages);
const message = Handlebars.compile(messages[error.name])(error.data);

switch (error.name) {
case CLIENT_COULD_NOT_CONNECT:
// don't show if error notification already handled by other plugins
if (!Notify.isOpen) {
// prevent course load execution
Wait.begin();
router.hideLoading();

Notify.popup({
_isCancellable: false,
title: messages.title,
body: message
});
}
}

this.logger.error(message);

if (!this.suppressErrors && (!this.logOutputWin || this.logOutputWin.closed) && confirm(`${messages.title}:\n\n${message}\n\n${messages.pressOk}`)) {
this.showDebugWindow();
}

async handleError(error) {
if (!Data.isReady) await Data.whenReady();
// defer error to allow other plugins which may be handling errors to execute first
_.defer(() => {
if ('value' in error.data) {
// because some browsers (e.g. Firefox) don't like displaying very long strings in the window.confirm dialog
if (error.data.value.length && error.data.value.length > 80) error.data.value = error.data.value.slice(0, 80) + '...';
// if the value being set is an empty string, ensure it displays in the error as ''
if (error.data.value === '') error.data.value = '\'\'';
}
const config = Adapt.course.get('_spoor');
const defaultMessages = ScormError.defaultMessages;
const configMessages = config?.['_messages'] || {};
const messages = Object.assign({}, defaultMessages, configMessages);
const message = Handlebars.compile(messages[error.name])(error.data);
switch (error.name) {
case CLIENT_COULD_NOT_CONNECT:
// don't show if error notification already handled by other plugins
if (!Notify.isOpen) {
// prevent course load execution
Wait.begin();
router.hideLoading();
Notify.popup({
_isCancellable: false,
title: messages.title,
body: message
});
}
}
this.logger.error(message);
if (!this.suppressErrors && (!this.logOutputWin || this.logOutputWin.closed) && confirm(`${messages.title}:\n\n${message}\n\n${messages.pressOk}`)) {
this.showDebugWindow();
}
});
}

recordScore(cmiPrefix, score, minScore = 0, maxScore = 100, isPercentageBased = true) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapt-contrib-spoor",
"version": "5.9.0",
"version": "5.9.3",
"framework": ">=5.31.31",
"homepage": "https://github.com/adaptlearning/adapt-contrib-spoor",
"bugs": "https://github.com/adaptlearning/adapt-contrib-spoor/issues",
Expand Down
2 changes: 1 addition & 1 deletion required/log_output.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</script>
</head>

<body onload="onLoad();" onunload="onUnload();">
<body onload="onLoad();" onunload="onUnload();" onpagehide="onUnload();">
<div id="logDiv"></div>
</body>

Expand Down

0 comments on commit 1b7684a

Please sign in to comment.