From 796afeca74856a5ed14651a9601d6fbe30e2a4d6 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 31 Jan 2022 16:32:46 +0100 Subject: [PATCH] wait #5045 --- resources/elearningmedia/js/app.js | 49 ++++++++++++++++++++++-- resources/elearningmedia/js/bootstrap.js | 2 - resources/elearningmedia/sass/app.sass | 6 +++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/resources/elearningmedia/js/app.js b/resources/elearningmedia/js/app.js index fdd7ed497..3b3cb729c 100644 --- a/resources/elearningmedia/js/app.js +++ b/resources/elearningmedia/js/app.js @@ -1,14 +1,57 @@ require('./bootstrap'); +import {SCORM} from 'pipwerks-scorm-api-wrapper'; +import Plyr from 'plyr'; + +window.openTime = Date.now(); + document.addEventListener("DOMContentLoaded", function () { - const player = new Plyr('#player'); + window.player = new Plyr('#player'); + SCORM.init(); + SCORM.set('cmi.exit', 'suspend'); + if (SCORM.get('cmi.completion_status') !== 'completed') { + SCORM.set('cmi.completion_status', 'incomplete'); + } + + var pc = (parseInt(progressComplete) / 100); var interval = setInterval(function () { - if (player.duration > 0 && currentTime > (player.duration * (progressComplete / 100))) { - SCORM.set('cmi.core.lesson_status', 'completed'); + if (player.duration > 0 && player.currentTime > (player.duration * pc)) { + SCORM.set('cmi.completion_status', 'completed'); + SCORM.set('cmi.success_status', 'passed'); SCORM.save(); clearInterval(interval); } }, 1000); }); + +function setSessionTime() { + var endTime = Date.now(); + SCORM.set('cmi.session_time', scormSecondsToTimeInterval((endTime.getTime() - window.openTime.getTime()) / 1000)); +} + +function scormSecondsToTimeInterval(diff) { + var diff = Math.round(diff); + var h = Math.floor(diff / 3600); + diff = diff % 3600; + var m = Math.floor(diff / 60); + var s = diff % 60; + return 'PT' + h + 'H' + m + 'M' + s + 'S'; +} + +function finishScorm(quit) { + if (quit === undefined) { + quit = true; + } + + setSessionTime(); + SCORM.save(); + if (quit) { + SCORM.quit(); + } +} + +window.addEventListener('unload', function (event) { + finishScorm(); +}); diff --git a/resources/elearningmedia/js/bootstrap.js b/resources/elearningmedia/js/bootstrap.js index 07c2c6df1..2e6b51198 100644 --- a/resources/elearningmedia/js/bootstrap.js +++ b/resources/elearningmedia/js/bootstrap.js @@ -8,5 +8,3 @@ window._ = require('lodash'); window.axios = require('axios'); window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; -import {SCORM} from 'pipwerks-scorm-api-wrapper'; -import Plyr from 'plyr'; diff --git a/resources/elearningmedia/sass/app.sass b/resources/elearningmedia/sass/app.sass index 01d2dc146..06a91aec7 100644 --- a/resources/elearningmedia/sass/app.sass +++ b/resources/elearningmedia/sass/app.sass @@ -11,6 +11,12 @@ html,body height: 100% overflow: hidden +body + font-family: Arial, Helvetica, sans-serif + video, audio width: 100% height: 100% + +.plyr + height: 100% -- 2.39.5