+++ /dev/null
-import $ from "jquery";
-import gsap from "gsap";
-import {CubeSCORM} from '../../scorm/scorm';
-
-window.cubeSCORM = new CubeSCORM();
-window.$ = window.jQuery = $;
-
-(function (global) {
- $(function () {
- var data;
- var score;
- var questionStatus = {};
- var testMode, quizMode, showReview, threshold, instantReview, logAttempts, displayScore, countQuestions,
- passedAction, failedAction,
- logQuestions;
-
- function initApp() {
- if (cubeSCORM.SCORM_INITED) {
- return;
- }
-
- let disable = false;
- try {
- if (window.parent !== undefined && window.parent.fluidbook !== undefined) {
- disable = true;
- }
- } catch (e) {
-
- }
-
- cubeSCORM.initScorm(disable);
- init(cubeSCORM.getScormLocation({q: 1}));
- }
-
- $(window).on('resize', resize);
-
- initContents();
-
- function resize() {
- // Window size that reserve enough space for all questions and avoid scroll jumps
- var maxHeight = 0;
- $(".question").each(function () {
- var hide = false;
- if (!$(this).is(':visible')) {
- hide = true;
- $(this).show();
- }
- maxHeight = Math.max(maxHeight, $(this).outerHeight());
- if (hide) {
- $(this).hide();
- }
- });
- if ($("#resultsscreen:visible").length == 1) {
- maxHeight = Math.max(maxHeight, $("#resultsscreen:visible").outerHeight());
- }
- $("main").css('minHeight', Math.max(maxHeight + 100, $(window).outerHeight() - $('header').outerHeight() - 70));
-
- // Header
- var ww = $(window).outerWidth();
- var h1 = $("header .headerholder .titleHolder h1");
- h1.css('width', '100%');
- h1.css('font-size', '');
- if (ww > 640) {
- var fz = 32;
- var h1h = h1.outerHeight() - 40;
- while (h1h > 32) {
- fz--;
- h1.css('font-size', fz);
- h1h = h1.outerHeight() - 40;
- }
- }
-
- // Badge position
- try {
- var left = (ww - 220) / 2;
- var answersBox = $(".question:visible .answers").get(0).getBoundingClientRect();
- var top = answersBox.top + (answersBox.height - 200) / 2;
- $("#badge").css({top: top, left: left});
- } catch (e) {
-
- }
- }
-
- function getTranslation(key) {
- return DATA.translations[key];
- }
-
- function resizeContainer() {
- try {
- if (parent.window.fluidbook !== undefined) {
- parent.window.fluidbook.links.resizeIframe($(document).outerHeight());
- }
- if (parent.window.resize !== undefined) {
- parent.window.resize();
- }
- } catch (e) {
-
- }
- }
-
- function initContents() {
- if (DATA.css !== '') {
- $("head").append('<style type="text/css">' + DATA.css + '</style>');
- }
- $("header .headerholder .titleHolder").append('<h1>' + DATA.title + '</h1>');
- $("header .headerholder .titleHolder h1").css('width', '99%');
- $("title").text(DATA.title);
-
- document.documentElement.style.setProperty('--main-color', DATA.mainColor);
- document.documentElement.style.setProperty('--header-overlay', DATA.overlay);
- document.documentElement.style.setProperty('--ok-color', DATA.okColor);
- document.documentElement.style.setProperty('--nok-color', DATA.nokColor);
- document.documentElement.style.setProperty('--review-background', DATA.reviewBackground);
- $('head').append('<style>:root{--main-color:' + DATA.mainColor + ';}</style>');
-
- showReview = DATA.review;
- threshold = 0;
- instantReview = DATA.instantReview;
- logAttempts = DATA.logattempts;
- displayScore = DATA.display_score;
- testMode = DATA.type === 'test';
- quizMode = DATA.type === 'quiz';
-
- threshold = DATA.threshold;
- if (threshold > 1) {
- threshold /= 100;
- }
-
- // Create quiz container
- var results = '<div class="results">';
- results += '</div>';
-
- var correction = $('<div id="correction"><h2>' + getTranslation('reviewAnswer') + '</h2></div>');
-
- var qn = 1;
- countQuestions = 0;
- // Create questions
- $.each(DATA.questions, function (k, question) {
- if (question.count_for_score) {
- countQuestions++;
- }
- var multipleClass = question.multiple ? ' multiple' : '';
- var questionHtml = '<section class="question' + multipleClass + '" data-count="' + (question.count_for_score ? '1' : '0') + '" data-q="' + qn + '" data-min-score="' + question.min_score + '" data-type="' + question.type + '">';
- questionHtml += '<div class="label"><h3>' + sprintf(getTranslation('question'), qn) + '</h3> ' + question.question + '</div>';
- questionHtml += '<div class="answers"></div>';
- if (question.multiple) {
- questionHtml += '<a href="#" class="button validatemulti">' + getTranslation('validateAnswer') + '</a>';
- } else if (question.type !== 'multiple') {
- questionHtml += '<a href="#" class="button validatemulti">' + getTranslation('validateAnswerSingular') + '</a>';
- }
- questionHtml += '</section>';
-
- var questionCorrection = question.explaination;
- if (questionCorrection === '') {
- var c = [];
- $.each(question.answers, function (kk, answer) {
- if (answer.correct == 1) {
- c.push(answer.answer);
- }
- });
- questionCorrection = c.join('<br>');
- }
-
- var c = '<div class="correction" data-i="' + qn + '"><div class="badge"></div><h4>' + sprintf(getTranslation('question'), qn) + ' ' + question.question + '</h4><p>' + questionCorrection + '</p></div>';
- $(correction).append(c);
-
- var q = $(questionHtml);
- var required = question.required === 1 ? 'required' : '';
-
- // Append answers
- var holder = $('<div class="holder"></div>');
- if (question.type === 'multiple') {
- var an = 0;
- var correctCount = 0;
-
- $.each(question.answers, function (aa, answer) {
- var a = $('<div class="answer-holder"><div class="answer" data-a="' + an + '">' + answer.answer + '</div></div>');
- // Set correct tag
- var correct = answer.correct == 1 ? 1 : 0;
- correctCount += correct;
- $(a).find('.answer').attr('data-correct', correct);
- $(holder).append($(a));
- an++;
- });
- } else if (question.type === 'text' || question.type === "email") {
- $(holder).append('<input ' + required + ' type="' + question.type + '" name="answer" class="focusme" placeholder="' + question.placeholder + '" />')
- } else if (question.type === 'textarea') {
- $(holder).append('<textarea ' + required + ' name="answer" class="focusme" placeholder="' + question.placeholder + '"></textarea>')
- } else if (question.type === 'country') {
- var select = '<div class="select-holder"><select name="answer" class="focusme"><option value="">--</option>';
- $.each(DATA.countriesList, function (code, name) {
- select += '<option value="' + code + '">' + name + '</option>';
- });
- select += '</select></div>';
- $(holder).append(select);
- }
-
- $(q).find('.answers').append($(holder));
-
- $("main").append(q);
-
- qn++;
- });
-
- var results;
- if (testMode) {
- results = testResults();
- } else {
- results = quizResults(correction);
- }
-
- $("main").append(results);
-
- $(document).on('quizinit', function (event, state) {
- init(state);
- });
-
- initApp();
-
- resizeContainer();
- resize();
- }
-
- function quizResults(correction) {
- var defaultMessage = DATA.defaultMessage !== '' ? DATA.defaultMessage : 'You have finished the quiz!';
- var passedMessage = DATA.passedMessage !== '' ? DATA.passedMessage : defaultMessage;
- var failedMessage = DATA.failedMessage !== '' ? DATA.failedMessage : defaultMessage;
-
- passedAction = DATA.passedAction !== '' ? DATA.passedAction : null;
- failedAction = DATA.failedAction !== '' ? DATA.failedAction : null;
-
- var results = '<section id="resultsscreen">';
- results += '<div id="results">';
- results += '<h2 class="defaultMessage">' + defaultMessage + '</h2>';
- results += '<h2 class="passedMessage">' + passedMessage + '</h2>';
- results += '<h2 class="failedMessage">' + failedMessage + '</h2>';
- if (displayScore) {
- results += '<div class="content">' + getTranslation('totalQuestions') + ' <span id="totalquestions">' + countQuestions + '</span><br />' + getTranslation('correctAnswers') + ' <span id="correctanswers"></span></div>';
- }
- results += '</div>';
- results += '<a href="" id="restart" class="button">' + getTranslation('restartQuiz') + '</a>';
- results += '</section>';
-
- results = $(results);
- $(results).append(correction);
- return results;
- }
-
- function testResults() {
- var results = '<section id="resultsscreen">';
- results += '<div id="results">';
- $.each(DATA.test_results, function (k, v) {
- results += '<h2 class="test_result" data-min="' + (Math.min(v.score.first, v.score.second)) + '" data-max="' + (Math.max(v.score.first, v.score.second)) + '">' + v.text + '</h2>';
- });
- results += '</div>';
- results += '</section>';
-
- results = $(results);
- return results;
- }
-
- function init(state) {
- resize();
- $(document).on('click', ".answer", function () {
- answer($(this));
- return false;
- });
-
- $(document).on('click', ".validatemulti", function () {
- validateMulti($(this));
- return false;
- });
-
- if (state.a) {
- $.each($(state.a), function (k, v) {
- var q = $('section.question[data-q="' + (k + 1) + '"]');
- $.each(v, function (kk, vv) {
- $(q).find('.answer[data-a="' + vv + '"]').addClass('active');
- });
- });
- }
- initScreen(state.q - 1);
- }
-
- function validateMulti(button) {
- var question = $(button).closest('.question');
- if ($(question).find('input').length > 0) {
- var input = $(question).find('input');
- if (!$(input).get(0).checkValidity()) {
- $(input).get(0).reportValidity()
- return;
- }
- }
- updateScore();
- var ok = null;
- if ($(question).attr('data-count') == '1') {
- ok = questionStatus[$(question).data('q')]
- }
-
- displayBadge(ok);
- resizeContainer();
- }
-
- function answer(answer) {
- var multiple = $(answer).closest('.question').hasClass('multiple');
- if (!multiple && $("section:visible .answer.active").length > 0) {
- return;
- }
-
- if (!multiple) {
- $(answer).addClass('active');
- $('section:visible').find('.answer:not(.active)').addClass('inactive');
- updateScore();
- if (testMode) {
- displayBadge(true);
- } else {
- displayBadge($(answer).attr('data-correct') == 1);
- }
- resizeContainer();
- } else {
- $(answer).toggleClass('active');
- }
- }
-
- function initScreen(screen) {
- // When displaying first question
- setTimeout(function () {
- $("section").eq(screen).show();
- resizeContainer();
- }, 50)
- }
-
- function nextScreen() {
- var prev = $("section:visible");
- var next = $(prev).next('section');
- var $this = this;
-
- // If no screen remaining
- if ($(next).length == 0) {
- return;
- }
-
-
- if ($(next).is("#resultsscreen")) {
- updateScore();
- if (quizMode) {
- var show = showReview === 'always' || (showReview === 'passed' && checkScore());
-
- if (!show) {
- $('#correction').hide();
- } else {
- $('#correction').show();
- }
- } else {
- $('.test_result').each(function () {
- var show = score >= $(this).data('min') && score <= $(this).data('max');
- console.log(this, show, score, $(this).data('min'), $(this).data('max'));
- if (show) {
- $(this).show();
- } else {
- $(this).hide();
- }
- });
- }
- completed();
- }
-
- var w = $(prev).outerWidth();
- $(next).show();
- resize();
- gsap.fromTo($(next), {left: w + 50, opacity: 0}, {duration: 0.5, left: 0, opacity: 1});
- gsap.fromTo($(prev), {left: 0, opacity: 1}, {
- duration: 0.5, left: -w - 50, opacity: 0, onComplete: function () {
- $(prev).hide();
- endTransition();
- }
- });
- resizeContainer();
- }
-
- function endTransition() {
- $("section:visible .focusme").focus();
- }
-
- function completed() {
- updateScore();
-
- var passed = checkScore();
- if (logAttempts) {
- logAttempt(passed);
- }
-
- if (DATA.scorm) {
- cubeSCORM.setScormValue('status', 'completed');
- cubeSCORM.setScormValue('success_status', passed ? 'passed' : 'failed');
- cubeSCORM.setSCORMScore(getNormalizedScore(true), 100, 0, getNormalizedScore());
- cubeSCORM.setSCORMLocation({q: 1});
- }
- }
-
- function getNormalizedScore(pct) {
- var s = score / countQuestions;
- if (pct === undefined || pct === false) {
- return s;
- }
- return Math.round(100 * s);
- }
-
- function logAttempt(passed) {
- var score = getNormalizedScore(true);
- if (isNaN(score)) {
- score = 0;
- }
- var logdata = {
- score: score, passed: passed, questions: logQuestions,
- };
-
- $.ajax('https://toolbox.fluidbook.com/quiz/' + DATA.id + '/log', {
- method: 'POST', data: logdata, crossDomain: true,
- });
- }
-
- function checkScore() {
- if (quizMode) {
- var normalizedScore = getNormalizedScore(false);
- $('#results > h2').hide();
- var passed;
- $('#restart').hide();
- if (threshold === 0) {
- $('.defaultMessage').show();
- passed = true;
- } else if (normalizedScore >= threshold) {
- $(".passedMessage").show();
- execAction(passedAction);
- passed = true;
- } else {
- $('.failedMessage').show();
- execAction(failedAction);
- passed = false;
- if ($(data).find('restart_button').text() === "1") {
- $('#restart').show();
- }
- }
- return passed;
- }
- return true;
- }
-
- function execAction(action) {
- if (action === undefined || action === null || action === '' || !action) {
- return;
- }
- try {
- eval(action);
- } catch (e) {
- console.error('Error while running code ' + action + ' :: ' + e.message);
- }
- }
-
- function displayBadge(correct) {
- resize();
- if (!instantReview || correct === null) {
- nextScreen();
- return;
- }
- if (correct) {
- $("#badge").addClass('correct').removeClass('incorrect');
- } else {
- $("#badge").addClass('incorrect').removeClass('correct');
- }
- $("#badge").fadeIn(350, function () {
- setTimeout(function () {
- $("#badge").fadeOut(350, function () {
- nextScreen();
- });
- }, 1000);
- });
- }
-
- function updateScore() {
- if (testMode) {
- return updateTestScore();
- }
- if (quizMode) {
- return updateQuizScore();
- }
- }
-
- function updateTestScore() {
- score = 0;
- var answers = [];
- var qn = 1;
- logQuestions = [];
-
-
- $('.question').each(function () {
- var q = $(this);
- var a = [];
- var log = {};
-
- var qScore = null;
- if ($(this).data('type') === 'multiple') {
- $(this).find('.answer.active').each(function () {
- a.push($(this).data('a'))
- qScore = DATA.questions[q.data('q') - 1].answers[$(this).data('a')].score;
- });
-
- answers.push(a);
- log.answer = a;
- } else {
- log.answer = $(this).find('input,textarea,select').val();
- }
-
- questionStatus[qn] = qScore;
-
- if (qScore !== null) {
- score += qScore;
- }
- log.score = qScore;
-
- logQuestions[qn] = log;
- qn++;
- });
-
-
- var state = {
- q: $(".answer.active").last().closest('.question').data('q') + 1, a: answers
- };
-
- if (SCORM) {
- cubeSCORM.setSCORMLocation(state);
- }
- $("#correctanswers").text(score);
- }
-
- function updateQuizScore() {
- score = 0;
- var answers = [];
- var qn = 1;
- logQuestions = [];
-
- $('.question').each(function () {
- var a = [];
- var ok = true;
- var count = $(this).attr('data-count') == '1';
- var log = {
- 'count': count,
- };
-
- if ($(this).data('type') === 'multiple') {
- var min_score = parseInt($(this).data('min-score'));
- if (min_score === 0) {
- min_score = $(this).find('.answer[data-correct="1"]').length;
- }
- var this_score = 0;
- $(this).find('.answer').each(function () {
- if ($(this).hasClass('active')) {
- var correct = $(this).attr('data-correct') == '1';
- this_score += correct ? 1 : -1;
- a.push($(this).data('a'))
- }
- });
- ok = this_score >= min_score;
-
- answers.push(a);
- log.answer = a;
- } else {
- log.answer = $(this).find('input,textarea,select').val();
- }
-
- if (!count) {
- ok = null;
- }
-
- questionStatus[qn] = ok;
-
- var b = $("#correction .correction[data-i='" + qn + "'] .badge");
- $(b).removeClass('correct').removeClass('incorrect');
- if (ok === true) {
- $(b).addClass('correct');
- } else if (ok === false) {
- $(b).addClass('incorrect');
- }
- if (ok && count) {
- score++;
- log.score = 1;
- } else {
- log.score = 0;
- }
- logQuestions[qn] = log;
- qn++;
- });
-
-
- var state = {
- q: $(".answer.active").last().closest('.question').data('q') + 1, a: answers
- };
-
- if (cubeSCORM.SCORM) {
- cubeSCORM.setSCORMLocation(state);
- }
- $("#correctanswers").text(score);
- }
-
-
- });
-})(typeof window === 'undefined' ? this : window);
-
-
-(function (global) {
- 'use strict';
- if (!global.console) {
- global.console = {};
- }
- var con = global.console;
- var prop, method;
- var dummy = function () {
- };
- var properties = ['memory'];
- var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');
- while (prop = properties.pop()) if (!con[prop]) con[prop] = {};
- while (method = methods.pop()) if (typeof con[method] !== 'function') con[method] = dummy;
- // Using `this` for web workers & supports Browserify / Webpack.
-})(typeof window === 'undefined' ? this : window);
-
-/*! sprintf-js v1.1.2 | Copyright (c) 2007-present, Alexandru Mărășteanu <hello@alexei.ro> | BSD-3-Clause */
-!function () {
- "use strict";
- var g = {
- not_string: /[^s]/,
- not_bool: /[^t]/,
- not_type: /[^T]/,
- not_primitive: /[^v]/,
- number: /[diefg]/,
- numeric_arg: /[bcdiefguxX]/,
- json: /[j]/,
- not_json: /[^j]/,
- text: /^[^\x25]+/,
- modulo: /^\x25{2}/,
- placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
- key: /^([a-z_][a-z_\d]*)/i,
- key_access: /^\.([a-z_][a-z_\d]*)/i,
- index_access: /^\[(\d+)\]/,
- sign: /^[+-]/
- };
-
- function y(e) {
- return function (e, t) {
- var r, n, i, s, a, o, p, c, l, u = 1, f = e.length, d = "";
- for (n = 0; n < f; n++) if ("string" == typeof e[n]) d += e[n]; else if ("object" == typeof e[n]) {
- if ((s = e[n]).keys) for (r = t[u], i = 0; i < s.keys.length; i++) {
- if (null == r) throw new Error(y('[sprintf] Cannot access property "%s" of undefined value "%s"', s.keys[i], s.keys[i - 1]));
- r = r[s.keys[i]]
- } else r = s.param_no ? t[s.param_no] : t[u++];
- if (g.not_type.test(s.type) && g.not_primitive.test(s.type) && r instanceof Function && (r = r()), g.numeric_arg.test(s.type) && "number" != typeof r && isNaN(r)) throw new TypeError(y("[sprintf] expecting number but found %T", r));
- switch (g.number.test(s.type) && (c = 0 <= r), s.type) {
- case"b":
- r = parseInt(r, 10).toString(2);
- break;
- case"c":
- r = String.fromCharCode(parseInt(r, 10));
- break;
- case"d":
- case"i":
- r = parseInt(r, 10);
- break;
- case"j":
- r = JSON.stringify(r, null, s.width ? parseInt(s.width) : 0);
- break;
- case"e":
- r = s.precision ? parseFloat(r).toExponential(s.precision) : parseFloat(r).toExponential();
- break;
- case"f":
- r = s.precision ? parseFloat(r).toFixed(s.precision) : parseFloat(r);
- break;
- case"g":
- r = s.precision ? String(Number(r.toPrecision(s.precision))) : parseFloat(r);
- break;
- case"o":
- r = (parseInt(r, 10) >>> 0).toString(8);
- break;
- case"s":
- r = String(r), r = s.precision ? r.substring(0, s.precision) : r;
- break;
- case"t":
- r = String(!!r), r = s.precision ? r.substring(0, s.precision) : r;
- break;
- case"T":
- r = Object.prototype.toString.call(r).slice(8, -1).toLowerCase(), r = s.precision ? r.substring(0, s.precision) : r;
- break;
- case"u":
- r = parseInt(r, 10) >>> 0;
- break;
- case"v":
- r = r.valueOf(), r = s.precision ? r.substring(0, s.precision) : r;
- break;
- case"x":
- r = (parseInt(r, 10) >>> 0).toString(16);
- break;
- case"X":
- r = (parseInt(r, 10) >>> 0).toString(16).toUpperCase()
- }
- g.json.test(s.type) ? d += r : (!g.number.test(s.type) || c && !s.sign ? l = "" : (l = c ? "+" : "-", r = r.toString().replace(g.sign, "")), o = s.pad_char ? "0" === s.pad_char ? "0" : s.pad_char.charAt(1) : " ", p = s.width - (l + r).length, a = s.width && 0 < p ? o.repeat(p) : "", d += s.align ? l + r + a : "0" === o ? l + a + r : a + l + r)
- }
- return d
- }(function (e) {
- if (p[e]) return p[e];
- var t, r = e, n = [], i = 0;
- for (; r;) {
- if (null !== (t = g.text.exec(r))) n.push(t[0]); else if (null !== (t = g.modulo.exec(r))) n.push("%"); else {
- if (null === (t = g.placeholder.exec(r))) throw new SyntaxError("[sprintf] unexpected placeholder");
- if (t[2]) {
- i |= 1;
- var s = [], a = t[2], o = [];
- if (null === (o = g.key.exec(a))) throw new SyntaxError("[sprintf] failed to parse named argument key");
- for (s.push(o[1]); "" !== (a = a.substring(o[0].length));) if (null !== (o = g.key_access.exec(a))) s.push(o[1]); else {
- if (null === (o = g.index_access.exec(a))) throw new SyntaxError("[sprintf] failed to parse named argument key");
- s.push(o[1])
- }
- t[2] = s
- } else i |= 2;
- if (3 === i) throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");
- n.push({
- placeholder: t[0],
- param_no: t[1],
- keys: t[2],
- sign: t[3],
- pad_char: t[4],
- align: t[5],
- width: t[6],
- precision: t[7],
- type: t[8]
- })
- }
- r = r.substring(t[0].length)
- }
- return p[e] = n
- }(e), arguments)
- }
-
- function e(e, t) {
- return y.apply(null, [e].concat(t || []))
- }
-
- var p = Object.create(null);
- "undefined" != typeof exports && (exports.sprintf = y, exports.vsprintf = e), "undefined" != typeof window && (window.sprintf = y, window.vsprintf = e, "function" == typeof define && define.amd && define(function () {
- return {sprintf: y, vsprintf: e}
- }))
-}();