// keep PASS_FAIL_SETS_COMPLETION_FOR_2004 false globally
// so failed/unknown do not automatically become completed
(function () {
function patchScormFlag() {
var patched = false;
try {
if (typeof parent.PASS_FAIL_SETS_COMPLETION_FOR_2004 !== "undefined") {
console.log(
"[SCORM patch] parent before:",
parent.PASS_FAIL_SETS_COMPLETION_FOR_2004
);
parent.PASS_FAIL_SETS_COMPLETION_FOR_2004 = false;
console.log(
"[SCORM patch] parent after:",
parent.PASS_FAIL_SETS_COMPLETION_FOR_2004
);
patched = true;
}
} catch (e) {
console.error("[SCORM patch] Could not patch parent", e);
}
try {
if (typeof top.PASS_FAIL_SETS_COMPLETION_FOR_2004 !== "undefined") {
console.log(
"[SCORM patch] top before:",
top.PASS_FAIL_SETS_COMPLETION_FOR_2004
);
top.PASS_FAIL_SETS_COMPLETION_FOR_2004 = false;
console.log(
"[SCORM patch] top after:",
top.PASS_FAIL_SETS_COMPLETION_FOR_2004
);
patched = true;
}
} catch (e) {
console.error("[SCORM patch] Could not patch top", e);
}
return patched;
}
if (!patchScormFlag()) {
var tries = 0;
var maxTries = 60;
var timer = setInterval(function () {
tries++;
if (patchScormFlag() || tries >= maxTries) {
clearInterval(timer);
}
}, 250);
}
})();
// patch SCORM2004_SetPassed only
// passed should also mark completion complete
// failed/unknown should remain incomplete
(function () {
function patchSetPassedOnly() {
var patched = false;
function applyPatch(scormWin, label) {
try {
if (
scormWin &&
typeof scormWin.SCORM2004_SetPassed === "function" &&
!scormWin.SCORM2004_SetPassed._patchedSetPassedComplete
) {
scormWin.SCORM2004_SetPassed = function () {
scormWin.WriteToDebug("In SCORM2004_SetPassed [patched]");
var blnResult;
scormWin.SCORM2004_ClearErrorInfo();
blnResult = scormWin.SCORM2004_CallSetValue(
"cmi.success_status",
scormWin.SCORM2004_PASSED
);
blnResult =
scormWin.SCORM2004_CallSetValue(
"cmi.completion_status",
scormWin.SCORM2004_COMPLETED
) && blnResult;
return blnResult;
};
scormWin.SCORM2004_SetPassed._patchedSetPassedComplete = true;
console.log("[SCORM patch] " + label + ".SCORM2004_SetPassed patched");
return true;
}
} catch (e) {
console.error("[SCORM patch] Could not patch " + label + ".SCORM2004_SetPassed", e);
}
return false;
}
patched = applyPatch(parent, "parent") || patched;
patched = applyPatch(top, "top") || patched;
return patched;
}
if (!patchSetPassedOnly()) {
var tries = 0;
var maxTries = 60;
var timer = setInterval(function () {
tries++;
if (patchSetPassedOnly() || tries >= maxTries) {
clearInterval(timer);
}
}, 250);
}
})();
// safely wrap onCourseComplete instead of replacing it outright
// suppress SetReachedEnd only when completionStatus = 1 and lessonStatus = failed
(function () {
function patchOnCourseComplete() {
try {
if (
typeof window.DKI === "undefined" ||
!window.DKI.SCORMDataStorage ||
!window.DKI.SCORMDataStorage.prototype ||
typeof window.DKI.SCORMDataStorage.prototype.onCourseComplete !== "function"
) {
return false;
}
var proto = window.DKI.SCORMDataStorage.prototype;
if (proto.onCourseComplete._patchedInterceptSetReachedEnd) {
return true;
}
var originalOnCourseComplete = proto.onCourseComplete;
proto.onCourseComplete = function () {
var self = this;
var originalProcess = this.scormInterface && this.scormInterface.process;
if (typeof originalProcess !== "function") {
return originalOnCourseComplete.apply(this, arguments);
}
this.scormInterface.process = function (action, args, callback) {
var suppressSetReachedEnd =
action === "SetReachedEnd" &&
playerBehaviour &&
playerBehaviour.completionStatus === 1 &&
self.lessonStatus === "failed";
if (suppressSetReachedEnd) {
console.log(
"[SCORM patch] Suppressed SetReachedEnd for completionStatus=1, lessonStatus=" +
self.lessonStatus
);
if (typeof callback === "function") {
try {
callback();
} catch (e) {}
}
return;
}
return originalProcess.apply(this, arguments);
};
try {
return originalOnCourseComplete.apply(this, arguments);
} finally {
this.scormInterface.process = originalProcess;
}
};
proto.onCourseComplete._patchedInterceptSetReachedEnd = true;
console.log("[SCORM patch] onCourseComplete wrapped successfully");
return true;
} catch (e) {
console.error("[SCORM patch] Failed to patch onCourseComplete", e);
return false;
}
}
if (!patchOnCourseComplete()) {
var tries = 0;
var maxTries = 120;
var timer = setInterval(function () {
tries++;
if (patchOnCourseComplete() || tries >= maxTries) {
clearInterval(timer);
}
}, 250);
}
})();
Confirm
Comments ( 0 )
Sign in to join the discussion.