diff options
author | Sam Light <samlight1994@gmail.com> | 2022-09-05 12:29:33 +0100 |
---|---|---|
committer | Sam Light <samlight1994@gmail.com> | 2022-09-05 12:29:33 +0100 |
commit | b9de84a6160788a226582f0a23dadb62e55ccab5 (patch) | |
tree | c3556eb0d140e7825700a0252220e223b2b0b474 /resources | |
parent | 7c93841d147572f5c87c088ff4f599663ce4bac7 (diff) |
Added build system for the js
Diffstat (limited to 'resources')
-rw-r--r-- | resources/js/scorm_player.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/resources/js/scorm_player.js b/resources/js/scorm_player.js new file mode 100644 index 0000000..3ea82fc --- /dev/null +++ b/resources/js/scorm_player.js @@ -0,0 +1,45 @@ +import Cookies from 'js-cookie'; +import 'fetch-ie8'; +import 'scorm-again'; + +const Scorm2004API = window.Scorm2004API; + +function setupApi(data) { + const api = new Scorm2004API({ + lmsCommitUrl: data.commit_url, + xhrHeaders: { + 'X-XSRF-TOKEN': Cookies.get('XSRF-TOKEN'), + } + }); + + api.loadFromJSON(data.tracking.cmi); + + window.API_1484_11 = api; +} + +function loadIframe(entry) { + const players = document.getElementsByClassName('scorm-player'); + for(const player of players) { + player.src = entry; + } +} + +function handleScoData(data) { + setupApi(data); + loadIframe(data.entry_url); +} + +function loadScoData() { + fetch(window.scorm_api_data.routes.load, { + method: 'GET', + headers: { + Accept: 'application/json', + } + }).then((response) => { + if(response.status === 200) + return response.json(); + return {}; + }).then(handleScoData); +} + +document.addEventListener('DOMContentLoaded', loadScoData); |