@didask/scol-r 2.8.0 → 2.9.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  export interface HTMLGeneratorProps {
2
2
  dataSource: string;
3
3
  libPath?: string;
4
+ hashIdentifiers?: boolean;
4
5
  }
5
6
  export declare function HTMLGenerator(props: HTMLGeneratorProps): string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HTMLGenerator = void 0;
4
4
  function HTMLGenerator(props) {
5
- var dataSource = props.dataSource, _a = props.libPath, libPath = _a === void 0 ? "lib" : _a;
6
- return "<!DOCTYPE html>\n <html>\n <head>\n <title>SCO local endpoint</title>\n <meta charset=\"UTF-8\"/>\n <script>var exports = {};</script>\n <script type=\"text/javascript\" src=\"".concat(libPath, "/SCORMAdapter.js\"></script>\n <script type=\"text/javascript\" src=\"").concat(libPath, "/MessageHandler.js\"></script>\n <script type=\"text/javascript\" src=\"").concat(libPath, "/loadContent.js\"></script>\n <style type=\"text/css\">\n html, body { margin: 0; padding:0; overflow:hidden; width: 100%; height: 100%; }\n body {\n font-size: 20px;\n font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n color: #1d1046;\n }\n #wrapper { display: flex; flex-direction: column; height: 100%; }\n .container { width: 80%; max-width: 1200px; padding: 15px; margin: auto; }\n #wrapper .header {\n padding-top: 20px; padding-bottom: 20px;\n background-color: #f3f4f5;\n }\n #wrapper .messages { flex-grow: 1; padding-top: 20px; padding-bottom: 20px; }\n #wrapper .messages p { color: red; }\n #title-error-messages { color: #1d1046; }\n #wrapper .footer {\n background-color: #1d1046; color: white;\n padding-top: 10px; padding-bottom: 10px;\n }\n #wrapper .footer a { color: white; }\n\n iframe { overflow: hidden; height: 100%; width: 100%; }\n iframe + #wrapper { display: none; }\n #runtime-error {\n position: fixed;\n left: 20px; bottom: 20px; padding: 15px;\n background-color: #f44a3d; color: white;\n font-size: 16px;\n }\n #runtime-error h6, #runtime-error p { margin: 0 0 10px;}\n #runtime-error p:last-child { margin: 0;}\n #runtime-error:empty { display: none; }\n </style>\n </head>\n <!-- Set the body's data-source attribute to the SCO's remote endpoint. -->\n <body onload=\"loadContent();\" data-source=\"").concat(dataSource, "\">\n <div id=\"wrapper\">\n <div class=\"header\"><div class=\"container\">\n <h1 id=\"title\">Your content is loading...</h1>\n <p id=\"subtitle\">Please wait, or if your content doesn't appear, try closing and opening this window again.</p>\n </div></div>\n <div class=\"messages container\">\n <h2 id=\"title-error-messages\">If the initialization fails, error messages will appear below:</h2>\n </div>\n <div class=\"footer\"><div class=\"container\" id=\"footer-content\">\n This content is loaded via <a href=\"https://github.com/Didask/scol-r\" target=\"_blank\">SCOL-R</a>, a cross-domain SCORM connector created by <a href=\"https://www.didask.com\" target=\"_blank\">Didask</a>.\n </div></div>\n </div>\n <div id=\"runtime-error\"></div>\n </body>\n </html>");
5
+ var dataSource = props.dataSource, _a = props.libPath, libPath = _a === void 0 ? "lib" : _a, _b = props.hashIdentifiers, hashIdentifiers = _b === void 0 ? false : _b;
6
+ return "<!DOCTYPE html>\n <html>\n <head>\n <title>SCO local endpoint</title>\n <meta charset=\"UTF-8\"/>\n <script>var exports = {};</script>\n <script type=\"text/javascript\" src=\"".concat(libPath, "/hashString.js\"></script>\n <script type=\"text/javascript\" src=\"").concat(libPath, "/SCORMAdapter.js\"></script>\n <script type=\"text/javascript\" src=\"").concat(libPath, "/MessageHandler.js\"></script>\n <script type=\"text/javascript\" src=\"").concat(libPath, "/loadContent.js\"></script>\n <style type=\"text/css\">\n html, body { margin: 0; padding:0; overflow:hidden; width: 100%; height: 100%; }\n body {\n font-size: 20px;\n font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n color: #1d1046;\n }\n #wrapper { display: flex; flex-direction: column; height: 100%; }\n .container { width: 80%; max-width: 1200px; padding: 15px; margin: auto; }\n #wrapper .header {\n padding-top: 20px; padding-bottom: 20px;\n background-color: #f3f4f5;\n }\n #wrapper .messages { flex-grow: 1; padding-top: 20px; padding-bottom: 20px; }\n #wrapper .messages p { color: red; }\n #title-error-messages { color: #1d1046; }\n #wrapper .footer {\n background-color: #1d1046; color: white;\n padding-top: 10px; padding-bottom: 10px;\n }\n #wrapper .footer a { color: white; }\n\n iframe { overflow: hidden; height: 100%; width: 100%; }\n iframe + #wrapper { display: none; }\n #runtime-error {\n position: fixed;\n left: 20px; bottom: 20px; padding: 15px;\n background-color: #f44a3d; color: white;\n font-size: 16px;\n }\n #runtime-error h6, #runtime-error p { margin: 0 0 10px;}\n #runtime-error p:last-child { margin: 0;}\n #runtime-error:empty { display: none; }\n </style>\n </head>\n <!-- Set the body's data-source attribute to the SCO's remote endpoint. -->\n <body onload=\"loadContent({hashIdentifiers: ").concat(hashIdentifiers, "});\" data-source=\"").concat(dataSource, "\">\n <div id=\"wrapper\">\n <div class=\"header\"><div class=\"container\">\n <h1 id=\"title\">Your content is loading...</h1>\n <p id=\"subtitle\">Please wait, or if your content doesn't appear, try closing and opening this window again.</p>\n </div></div>\n <div class=\"messages container\">\n <h2 id=\"title-error-messages\">If the initialization fails, error messages will appear below:</h2>\n </div>\n <div class=\"footer\"><div class=\"container\" id=\"footer-content\">\n This content is loaded via <a href=\"https://github.com/Didask/scol-r\" target=\"_blank\">SCOL-R</a>, a cross-domain SCORM connector created by <a href=\"https://www.didask.com\" target=\"_blank\">Didask</a>.\n </div></div>\n </div>\n <div id=\"runtime-error\"></div>\n </body>\n </html>");
7
7
  }
8
8
  exports.HTMLGenerator = HTMLGenerator;
@@ -0,0 +1 @@
1
+ export declare function hashString(string: string): Promise<string>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.hashString = void 0;
40
+ function hashString(string) {
41
+ return __awaiter(this, void 0, void 0, function () {
42
+ var utf8, hashBuffer;
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0:
46
+ utf8 = new TextEncoder().encode(string);
47
+ return [4 /*yield*/, crypto.subtle.digest("SHA-256", utf8)];
48
+ case 1:
49
+ hashBuffer = _a.sent();
50
+ return [2 /*return*/, Array.from(new Uint8Array(hashBuffer))
51
+ .map(function (bytes) { return bytes.toString(16).padStart(2, "0"); })
52
+ .join("")];
53
+ }
54
+ });
55
+ });
56
+ }
57
+ exports.hashString = hashString;
@@ -1 +1,3 @@
1
- export function loadContent(): void;
1
+ export function loadContent({ hashIdentifiers }?: {
2
+ hashIdentifiers?: boolean | undefined;
3
+ }): Promise<void>;
@@ -1,139 +1,195 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.loadContent = void 0;
4
- function loadContent() {
5
- var messages = {
6
- en: {
7
- pageTitle: "Your content is loading...",
8
- pageSubtitle: "Please wait, or if your content doesn't appear, try closing and opening this window again.",
9
- pageErrorMessagesTitle: "If the initialization fails, error messages will appear below:",
10
- pageFooter: 'This content is loaded via <a href="https://github.com/Didask/scol-r" target="_blank">SCOL-R</a>, a cross-domain SCORM connector created by <a href="https://www.didask.com" target="_blank">Didask</a>.',
11
- apiNotFound: "<p>We were not able to contact your LMS: please close this window and try again later.</p>",
12
- couldNotInitialize: "<p>We were not able to initialize the connection with your LMS: please close this window and try again later.</p>",
13
- learnerIdMissing: "<p>We could not get your learner ID from the LMS: please close this window and try again later.</p>",
14
- sourceUrlMissing: "<p>We could find the address of the remote resource: it looks like this module is invalid, please contact your LMS administrator.</p>",
15
- runtimeErrorTitle: "An error occurred:",
16
- commitFailed: "The intermediate recording could not succeed. Please close the window and try again later, or contact your administrator if the problem keeps occurring.",
17
- },
18
- fr: {
19
- pageTitle: "Votre contenu est en cours de chargement...",
20
- pageSubtitle: "Merci de patienter&nbsp;; si votre contenu ne se charge pas, veuillez essayer de fermer et d'ouvrir cette fenêtre à nouveau.",
21
- pageErrorMessagesTitle: "Si l'initialisation échoue, les messages d'erreur apparaîtront ci-dessous&nbsp;:",
22
- pageFooter: 'Ce contenu est chargé via <a href="https://github.com/Didask/scol-r" target="_blank">SCOL-R</a>, un connecteur SCORM cross-domaine créé par <a href="https://www.didask.com" target="_blank">Didask</a>.',
23
- apiNotFound: "<p>Nous n'avons pas pu contacter votre LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
24
- couldNotInitialize: "<p>Nous n'avons pas pu initialiser la connection avec votre LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
25
- learnerIdMissing: "<p>Nous n'avons pas pu obtenir votre identifiant depuis le LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
26
- sourceUrlMissing: "<p>Nous n'avons pas pu trouver l'adresse de la ressource distante&nbsp;: il semble que ce module est invalide, veuillez contacter l'administrateur de votre LMS.</p>",
27
- runtimeErrorTitle: "Une erreur s'est produite&nbsp;:",
28
- commitFailed: "La sauvegarde automatique intermédiaire n’a pu aboutir. Si cette erreur se produit fréquemment veuillez fermer votre contenu et retenter plus tard ou contacter votre administrateur.",
29
- },
30
- };
31
- var localizeMessage = function (message) {
32
- var locale = navigator.language || navigator.userLanguage;
33
- if (locale)
34
- locale = locale.split(/[_-]/)[0];
35
- if (!messages.hasOwnProperty(locale))
36
- locale = "en";
37
- var localizedMessages = messages[locale];
38
- return localizedMessages.hasOwnProperty(message)
39
- ? localizedMessages[message]
40
- : message;
41
- };
42
- document.getElementById("title").innerHTML = localizeMessage("pageTitle");
43
- document.getElementById("subtitle").innerHTML =
44
- localizeMessage("pageSubtitle");
45
- document.getElementById("footer-content").innerHTML =
46
- localizeMessage("pageFooter");
47
- document.getElementById("title-error-messages").innerHTML = localizeMessage("pageErrorMessagesTitle");
48
- var displayInitError = function (message) {
49
- var messagesContainer = document.getElementsByClassName("messages");
50
- var newMessage = document.createElement("p");
51
- var localizedMessage = localizeMessage(message);
52
- newMessage.innerHTML = localizedMessage;
53
- messagesContainer.length && messagesContainer[0].appendChild(newMessage);
54
- console.error(localizedMessage);
55
- };
56
- var displayRuntimeError = function () {
57
- var errorContainer = document.getElementById("runtime-error");
58
- if (!(arguments && arguments.length)) {
59
- errorContainer.innerHTML = "";
60
- return;
61
- }
62
- errorContainer.innerHTML =
63
- "<h6>" + localizeMessage("runtimeErrorTitle") + "</h6>";
64
- for (var i = 0; i < arguments.length; i++) {
65
- if (!arguments[i])
66
- continue;
67
- var thisError = document.createElement("p");
68
- thisError.innerHTML = localizeMessage(arguments[i]);
69
- errorContainer.appendChild(thisError);
70
- }
71
- // Remove the messages after 6 seconds
72
- setTimeout(function () {
73
- errorContainer.innerHTML = "";
74
- }, 6000);
75
- };
76
- var ADAPTER = new SCORMAdapter(displayRuntimeError);
77
- if (!ADAPTER.foundAPI) {
78
- displayInitError("apiNotFound");
79
- return;
80
- }
81
- if (!ADAPTER.LMSInitialize()) {
82
- displayInitError("couldNotInitialize");
83
- return;
84
- }
85
- var lessonStatus = ADAPTER.getLessonStatus();
86
- if (lessonStatus === "not attempted") {
87
- ADAPTER.setLessonStatus("incomplete");
88
- }
89
- var sourceUrl = document.body.getAttribute("data-source");
90
- if (!sourceUrl) {
91
- displayInitError("sourceUrlMissing");
92
- return;
93
- }
94
- var sourceUrlParser = document.createElement("a");
95
- sourceUrlParser.href = sourceUrl;
96
- var learnerId = ADAPTER.getLearnerId();
97
- var learnerName = ADAPTER.getLearnerName();
98
- if (learnerId == null) {
99
- displayInitError("learnerIdMissing");
100
- return;
101
- }
102
- sourceUrlParser.search +=
103
- (sourceUrlParser.search.startsWith("?") ? "&" : "?") +
104
- "scorm" +
105
- "&learner_id=".concat(learnerId) +
106
- "&learner_name=".concat(learnerName) +
107
- "&lms_origin=".concat(encodeURIComponent(location.origin));
108
- var iframe = document.createElement("iframe");
109
- iframe.setAttribute("src", sourceUrlParser.href);
110
- iframe.setAttribute("frameborder", "0");
111
- iframe.setAttribute("height", "100%");
112
- iframe.setAttribute("width", "100%");
113
- document.body.insertBefore(iframe, document.getElementById("wrapper"));
114
- var sessionStart = new Date();
115
- var host = sourceUrlParser.host;
116
- // The `host` variable may or may not contain the port number depending on the browser.
117
- // We remove it if it wasnt' explicitly set.
118
- if (host.indexOf(":") > -1 &&
119
- sourceUrl.indexOf(host) !== sourceUrlParser.protocol.length + 2) {
120
- host = host.slice(0, host.indexOf(":"));
121
- }
122
- var sourceOrigin = sourceUrlParser.protocol + "//" + host;
123
- new MessageReceiver(window, sourceOrigin, ADAPTER);
124
- var sessionStart = new Date().getTime();
125
- /*
126
- * In case the beforeunload event is not triggered, we still want to send the session time to the LMS.
127
- * This is why we send the session time every 10 seconds.
128
- */
129
- setInterval(function () {
130
- var now = new Date().getTime();
131
- ADAPTER.setSessionTime(now - sessionStart);
132
- }, 10000);
133
- window.addEventListener("beforeunload", function (e) {
134
- var sessionEnd = new Date().getTime();
135
- ADAPTER.setSessionTime(sessionEnd - sessionStart);
136
- ADAPTER.LMSTerminate();
40
+ function loadContent(_a) {
41
+ var _b = _a === void 0 ? {} : _a, _c = _b.hashIdentifiers, hashIdentifiers = _c === void 0 ? false : _c;
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var messages, localizeMessage, displayInitError, displayRuntimeError, ADAPTER, lessonStatus, sourceUrl, sourceUrlParser, learnerId, learnerName, iframe, sessionStart, host, sourceOrigin, sessionStart;
44
+ return __generator(this, function (_d) {
45
+ switch (_d.label) {
46
+ case 0:
47
+ messages = {
48
+ en: {
49
+ pageTitle: "Your content is loading...",
50
+ pageSubtitle: "Please wait, or if your content doesn't appear, try closing and opening this window again.",
51
+ pageErrorMessagesTitle: "If the initialization fails, error messages will appear below:",
52
+ pageFooter: 'This content is loaded via <a href="https://github.com/Didask/scol-r" target="_blank">SCOL-R</a>, a cross-domain SCORM connector created by <a href="https://www.didask.com" target="_blank">Didask</a>.',
53
+ apiNotFound: "<p>We were not able to contact your LMS: please close this window and try again later.</p>",
54
+ couldNotInitialize: "<p>We were not able to initialize the connection with your LMS: please close this window and try again later.</p>",
55
+ learnerIdMissing: "<p>We could not get your learner ID from the LMS: please close this window and try again later.</p>",
56
+ sourceUrlMissing: "<p>We could find the address of the remote resource: it looks like this module is invalid, please contact your LMS administrator.</p>",
57
+ runtimeErrorTitle: "An error occurred:",
58
+ commitFailed: "The intermediate recording could not succeed. Please close the window and try again later, or contact your administrator if the problem keeps occurring.",
59
+ },
60
+ fr: {
61
+ pageTitle: "Votre contenu est en cours de chargement...",
62
+ pageSubtitle: "Merci de patienter&nbsp;; si votre contenu ne se charge pas, veuillez essayer de fermer et d'ouvrir cette fenêtre à nouveau.",
63
+ pageErrorMessagesTitle: "Si l'initialisation échoue, les messages d'erreur apparaîtront ci-dessous&nbsp;:",
64
+ pageFooter: 'Ce contenu est chargé via <a href="https://github.com/Didask/scol-r" target="_blank">SCOL-R</a>, un connecteur SCORM cross-domaine créé par <a href="https://www.didask.com" target="_blank">Didask</a>.',
65
+ apiNotFound: "<p>Nous n'avons pas pu contacter votre LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
66
+ couldNotInitialize: "<p>Nous n'avons pas pu initialiser la connection avec votre LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
67
+ learnerIdMissing: "<p>Nous n'avons pas pu obtenir votre identifiant depuis le LMS&nbsp;: veuillez fermer cette fenêtre et réessayer plus tard.</p>",
68
+ sourceUrlMissing: "<p>Nous n'avons pas pu trouver l'adresse de la ressource distante&nbsp;: il semble que ce module est invalide, veuillez contacter l'administrateur de votre LMS.</p>",
69
+ runtimeErrorTitle: "Une erreur s'est produite&nbsp;:",
70
+ commitFailed: "La sauvegarde automatique intermédiaire n’a pu aboutir. Si cette erreur se produit fréquemment veuillez fermer votre contenu et retenter plus tard ou contacter votre administrateur.",
71
+ },
72
+ };
73
+ localizeMessage = function (message) {
74
+ var locale = navigator.language || navigator.userLanguage;
75
+ if (locale)
76
+ locale = locale.split(/[_-]/)[0];
77
+ if (!messages.hasOwnProperty(locale))
78
+ locale = "en";
79
+ var localizedMessages = messages[locale];
80
+ return localizedMessages.hasOwnProperty(message)
81
+ ? localizedMessages[message]
82
+ : message;
83
+ };
84
+ document.getElementById("title").innerHTML = localizeMessage("pageTitle");
85
+ document.getElementById("subtitle").innerHTML =
86
+ localizeMessage("pageSubtitle");
87
+ document.getElementById("footer-content").innerHTML =
88
+ localizeMessage("pageFooter");
89
+ document.getElementById("title-error-messages").innerHTML = localizeMessage("pageErrorMessagesTitle");
90
+ displayInitError = function (message) {
91
+ var messagesContainer = document.getElementsByClassName("messages");
92
+ var newMessage = document.createElement("p");
93
+ var localizedMessage = localizeMessage(message);
94
+ newMessage.innerHTML = localizedMessage;
95
+ messagesContainer.length && messagesContainer[0].appendChild(newMessage);
96
+ console.error(localizedMessage);
97
+ };
98
+ displayRuntimeError = function () {
99
+ var errorContainer = document.getElementById("runtime-error");
100
+ if (!(arguments && arguments.length)) {
101
+ errorContainer.innerHTML = "";
102
+ return;
103
+ }
104
+ errorContainer.innerHTML =
105
+ "<h6>" + localizeMessage("runtimeErrorTitle") + "</h6>";
106
+ for (var i = 0; i < arguments.length; i++) {
107
+ if (!arguments[i])
108
+ continue;
109
+ var thisError = document.createElement("p");
110
+ thisError.innerHTML = localizeMessage(arguments[i]);
111
+ errorContainer.appendChild(thisError);
112
+ }
113
+ // Remove the messages after 6 seconds
114
+ setTimeout(function () {
115
+ errorContainer.innerHTML = "";
116
+ }, 6000);
117
+ };
118
+ ADAPTER = new SCORMAdapter(displayRuntimeError);
119
+ if (!ADAPTER.foundAPI) {
120
+ displayInitError("apiNotFound");
121
+ return [2 /*return*/];
122
+ }
123
+ if (!ADAPTER.LMSInitialize()) {
124
+ displayInitError("couldNotInitialize");
125
+ return [2 /*return*/];
126
+ }
127
+ lessonStatus = ADAPTER.getLessonStatus();
128
+ if (lessonStatus === "not attempted") {
129
+ ADAPTER.setLessonStatus("incomplete");
130
+ }
131
+ sourceUrl = document.body.getAttribute("data-source");
132
+ if (!sourceUrl) {
133
+ displayInitError("sourceUrlMissing");
134
+ return [2 /*return*/];
135
+ }
136
+ sourceUrlParser = document.createElement("a");
137
+ sourceUrlParser.href = sourceUrl;
138
+ learnerId = ADAPTER.getLearnerId();
139
+ learnerName = ADAPTER.getLearnerName();
140
+ if (learnerId == null) {
141
+ displayInitError("learnerIdMissing");
142
+ return [2 /*return*/];
143
+ }
144
+ if (!hashIdentifiers) return [3 /*break*/, 3];
145
+ return [4 /*yield*/, hashString(learnerId)];
146
+ case 1:
147
+ learnerId = _d.sent();
148
+ return [4 /*yield*/, hashString(learnerName)];
149
+ case 2:
150
+ learnerName = _d.sent();
151
+ _d.label = 3;
152
+ case 3:
153
+ sourceUrlParser.search +=
154
+ (sourceUrlParser.search.startsWith("?") ? "&" : "?") +
155
+ "scorm" +
156
+ "&learner_id=".concat(learnerId) +
157
+ "&learner_name=".concat(learnerName) +
158
+ "&lms_origin=".concat(encodeURIComponent(location.origin)) +
159
+ "&are_identifiers_hashed=".concat(hashIdentifiers);
160
+ iframe = document.createElement("iframe");
161
+ iframe.setAttribute("src", sourceUrlParser.href);
162
+ iframe.setAttribute("frameborder", "0");
163
+ iframe.setAttribute("height", "100%");
164
+ iframe.setAttribute("width", "100%");
165
+ document.body.insertBefore(iframe, document.getElementById("wrapper"));
166
+ sessionStart = new Date();
167
+ host = sourceUrlParser.host;
168
+ // The `host` variable may or may not contain the port number depending on the browser.
169
+ // We remove it if it wasnt' explicitly set.
170
+ if (host.indexOf(":") > -1 &&
171
+ sourceUrl.indexOf(host) !== sourceUrlParser.protocol.length + 2) {
172
+ host = host.slice(0, host.indexOf(":"));
173
+ }
174
+ sourceOrigin = sourceUrlParser.protocol + "//" + host;
175
+ new MessageReceiver(window, sourceOrigin, ADAPTER);
176
+ sessionStart = new Date().getTime();
177
+ /*
178
+ * In case the beforeunload event is not triggered, we still want to send the session time to the LMS.
179
+ * This is why we send the session time every 10 seconds.
180
+ */
181
+ setInterval(function () {
182
+ var now = new Date().getTime();
183
+ ADAPTER.setSessionTime(now - sessionStart);
184
+ }, 10000);
185
+ window.addEventListener("beforeunload", function (e) {
186
+ var sessionEnd = new Date().getTime();
187
+ ADAPTER.setSessionTime(sessionEnd - sessionStart);
188
+ ADAPTER.LMSTerminate();
189
+ });
190
+ return [2 /*return*/];
191
+ }
192
+ });
137
193
  });
138
194
  }
139
195
  exports.loadContent = loadContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "2.8.0",
3
+ "version": "2.9.0-beta.1",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",