mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:25:38 +03:00
635 lines
16 KiB
JavaScript
635 lines
16 KiB
JavaScript
var totalCorrect = 0;
|
|
var count = 0;
|
|
var verboseCorrectAnswers = [];
|
|
var startTimeStamp = new Date();
|
|
var lable1;
|
|
var lable2;
|
|
var lable3;
|
|
var lable4;
|
|
var lable5;
|
|
var lable6;
|
|
var lable7;
|
|
|
|
var langcode;
|
|
try {
|
|
langcode = document.getElementsByClassName('language')[0].getAttribute('id');
|
|
}
|
|
|
|
catch (e){
|
|
|
|
}
|
|
|
|
|
|
switch (langcode) {
|
|
case 'en' :
|
|
lable1 = ' Testing completed. Your result ';
|
|
lable2 = ' correct answers from ';
|
|
lable3 = 'Question Number';
|
|
lable4 = 'Question text';
|
|
lable5 = 'Correct answer';
|
|
lable6 = 'The answer is incorrect.';
|
|
lable7 = 'The answer is correct.';
|
|
break;
|
|
case 'ru' :
|
|
lable1 = ' Тестирование завершено. Ваш результат ';
|
|
lable2 = ' правильных ответов из ';
|
|
lable3 = 'Номер вопроса';
|
|
lable4 = 'Текст вопроса';
|
|
lable5 = 'Правильность ответа';
|
|
lable6 = 'Ответ неверный.';
|
|
lable7 = 'Ответ верный.';
|
|
break;
|
|
case 'es' :
|
|
lable1 = ' Test completado. Su resultado ';
|
|
lable2 = ' respuestas correctas de ';
|
|
lable3 = 'Número de la pregunta';
|
|
lable4 = 'Texto de la pregunta';
|
|
lable5 = 'Corrección de la respuesta';
|
|
lable6 = 'Respuesta incorrecta';
|
|
lable7 = 'Respuesta correcta';
|
|
break;
|
|
}
|
|
|
|
|
|
// For Hotspots
|
|
var selectedHotspot = null;
|
|
|
|
function toggle_visibility(id)
|
|
{
|
|
var e = document.getElementById(id);
|
|
if(e.style.display == 'block' | e.style == null)
|
|
{
|
|
e.style.display = 'none';
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
e.style.display = 'block';
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function navToContent(url)
|
|
{
|
|
}
|
|
|
|
function activate_flash_hotspots(hs_id, hs_title, icn)
|
|
{
|
|
alert(icn + " \r\n" + hs_id + " \r\n" + hs_title);
|
|
}
|
|
|
|
function openWindow(theFileName) {
|
|
|
|
alert(theFileName);
|
|
|
|
}
|
|
|
|
function showNextQuestion()
|
|
{
|
|
var nextCount = count + 1;
|
|
document.getElementById('questionNumber' + count).style.display = 'none';
|
|
if (document.getElementById('questionNumber' + nextCount))
|
|
{
|
|
document.getElementById('questionNumber' + nextCount).style.display = 'block';
|
|
}
|
|
else
|
|
{
|
|
document.getElementById('grade').style.display = 'block';
|
|
console.log(verboseCorrectAnswers);
|
|
if (totalCorrect == 1)
|
|
{
|
|
document.getElementById('grade').innerHTML = lable1 + totalCorrect + lable2 + count + '.';
|
|
//verboseCorrectAnswers.join('/');
|
|
assessmentResult();
|
|
showResultTable(verboseCorrectAnswers);
|
|
}
|
|
else
|
|
{
|
|
document.getElementById('grade').innerHTML = lable1 + totalCorrect + lable2 + count + '.';
|
|
assessmentResult();
|
|
showResultTable(verboseCorrectAnswers);
|
|
}
|
|
}
|
|
}
|
|
|
|
function showResultTable (resultArray) {
|
|
var stringInnerTable = "";
|
|
var verboseIsCorrect = "";
|
|
stringInnerTable += '<table class="S1000DrandomList"><tr><th>'+lable3+'</th><th>'+lable4+'</th><th>'+lable5+'</th></tr>';
|
|
for (index = 0; index < resultArray.length; ++index) {
|
|
switch (resultArray[index][3]) {
|
|
case 0: verboseIsCorrect = '<span style="color: red">'+lable6+'</span>'; break;
|
|
case 1: verboseIsCorrect = '<span style="color: green">'+lable7+'</span>'; break;
|
|
}
|
|
stringInnerTable += '<tr>';
|
|
stringInnerTable += '<td>'+resultArray[index][0]+'</td>';
|
|
stringInnerTable += '<td>'+resultArray[index][1]+'</td>';
|
|
stringInnerTable += '<td>'+verboseIsCorrect+'</td>';
|
|
stringInnerTable += '</tr>';
|
|
}
|
|
stringInnerTable += '</table>';
|
|
document.getElementById('tableResult').innerHTML = stringInnerTable;
|
|
}
|
|
|
|
function assessmentResult () {
|
|
var ratio = totalCorrect/count;
|
|
if (ratio > 0.7) {
|
|
doSetValue("cmi.score.scaled", ratio);
|
|
doSetValue("cmi.success_status", "passed");}
|
|
else {
|
|
doSetValue("cmi.score.scaled", totalCorrect);
|
|
doSetValue("cmi.success_status", "failed" );
|
|
|
|
}
|
|
doSetValue("cmi.completion_status", "completed");
|
|
}
|
|
|
|
|
|
function learnResult () {
|
|
|
|
doSetValue("cmi.completion_status", "completed");
|
|
doSetValue("cmi.success_status", "passed");
|
|
}
|
|
|
|
window.onunload = function() {
|
|
var endTimeStamp = new Date();
|
|
var totalMilliseconds = (endTimeStamp.getTime() - startTimeStamp.getTime());
|
|
var scormTime = ConvertMilliSecondsIntoSCORM2004Time(totalMilliseconds);
|
|
doSetValue("cmi.session_time",scormTime);
|
|
doSetValue( "cmi.exit", "suspend" );
|
|
doTerminate();
|
|
}
|
|
|
|
function checkIfSingleTrue(radioObj, quizType)
|
|
{
|
|
var radioLength = radioObj.answerChoiceRadio.length;
|
|
var feedbackCorrect = document.getElementById('feedbackCorrect');
|
|
var feedbackIncorrect = document.getElementById('feedbackIncorrect');
|
|
var answer = null;
|
|
var isCorrect =0;
|
|
|
|
for(var i=0; i < radioLength; i++)
|
|
{
|
|
if(radioObj.answerChoiceRadio[i].checked)
|
|
{
|
|
answer = radioObj.answerChoiceRadio[i].value.split(", ");
|
|
}
|
|
}
|
|
|
|
// Show feedback if Knowledge Check or go to next question for Assessment
|
|
if (quizType == 'Knowledge Check')
|
|
{
|
|
// is answer correct?
|
|
if (answer)
|
|
{
|
|
if (answer[1])
|
|
{
|
|
feedbackCorrect.style.display = 'block';
|
|
feedbackIncorrect.style.display = 'none';
|
|
}
|
|
else
|
|
{
|
|
feedbackIncorrect.style.display = 'block';
|
|
feedbackCorrect.style.display = 'none';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
feedbackCorrect.style.display = 'none';
|
|
feedbackIncorrect.style.display = 'none';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Check if answer is correct
|
|
if (answer)
|
|
{
|
|
if (answer[1])
|
|
{
|
|
isCorrect = 1;
|
|
totalCorrect++;
|
|
|
|
}
|
|
}
|
|
count++;
|
|
var questionText = radioObj.getElementsByClassName("questionText")[0].innerHTML;
|
|
verboseCorrectAnswers.push([count,questionText,answer[1], isCorrect]);
|
|
showNextQuestion();
|
|
}
|
|
}
|
|
|
|
function checkIfMultipleTrue(checkObj, quizType)
|
|
{
|
|
var feedbackCorrect = document.getElementById('feedbackCorrect');
|
|
var feedbackIncorrect = document.getElementById('feedbackIncorrect');
|
|
var checkLength = checkObj.answerChoiceCheckbox.length;
|
|
var answer = null;
|
|
var correctAnswers = [];
|
|
var chosenAnswers = [];
|
|
var correctChosenAnswers = [];
|
|
var numberIncorrect = 0;
|
|
var isCorrect = 0;
|
|
|
|
for(var i=0; i < checkLength; i++)
|
|
{
|
|
answer = checkObj.answerChoiceCheckbox[i].value.split(", ");
|
|
if (answer[1] != "")
|
|
{
|
|
correctAnswers.push(answer[1]);
|
|
}
|
|
if (checkObj.answerChoiceCheckbox[i].checked)
|
|
{
|
|
chosenAnswers.push(answer[0]);
|
|
if (answer[1] != "")
|
|
{
|
|
correctChosenAnswers.push(answer[1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Show feedback if Knowledge Check or go to next question for Assessment
|
|
if (quizType == 'Knowledge Check')
|
|
{
|
|
// Check if answer is correct
|
|
if (chosenAnswers.length == correctChosenAnswers.length)
|
|
{
|
|
if(correctChosenAnswers.length == correctAnswers.length)
|
|
{
|
|
feedbackIncorrect.style.display = 'none';
|
|
feedbackCorrect.style.display = 'block';
|
|
}
|
|
else
|
|
{
|
|
feedbackIncorrect.style.display = 'block';
|
|
feedbackCorrect.style.display = 'none';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
feedbackIncorrect.style.display = 'block';
|
|
feedbackCorrect.style.display = 'none';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Check if answer is correct
|
|
if (chosenAnswers.length == correctChosenAnswers.length)
|
|
{
|
|
if(correctChosenAnswers.length == correctAnswers.length)
|
|
{
|
|
isCorrect = 1;
|
|
totalCorrect++;
|
|
}
|
|
}
|
|
count++;
|
|
var questionText = checkObj.getElementsByClassName("questionText")[0].innerHTML;
|
|
verboseCorrectAnswers.push([count,questionText,correctChosenAnswers.length, isCorrect]);
|
|
showNextQuestion();
|
|
}
|
|
}
|
|
|
|
function checkIfMatchingTrue(selectObj, selectBoxCount)
|
|
{
|
|
var isCorrect = 0;
|
|
var correctAnswers = [];
|
|
var chosenAnswers = [];
|
|
var correctChosenAnswers = [];
|
|
var selected = null;
|
|
var selectedAnswer = null;
|
|
var correctAnswer = null;
|
|
var numberIncorrect = 0;
|
|
|
|
for (var i=0; i < selectBoxCount; i++)
|
|
{
|
|
selectedAnswer = selectObj[i].value;
|
|
correctAnswer = selectObj[i].name;
|
|
|
|
if (selectedAnswer != correctAnswer)
|
|
{
|
|
numberIncorrect++;
|
|
}
|
|
}
|
|
|
|
// WOULD HAVE SOMETHING LIKE THE FOLLOWING IF ABLE TO TEST AND WOULD NEED TO PASS IN quizType
|
|
// Show feedback if Knowledge Check or go to next question for Assessment
|
|
//if (quizType == 'Knowledge Check')
|
|
|
|
if (numberIncorrect == 0)
|
|
{
|
|
isCorrect = 1;
|
|
totalCorrect++;
|
|
}
|
|
count++;
|
|
var questionText = selectObj.getElementsByClassName("questionText")[0].innerHTML;
|
|
verboseCorrectAnswers.push([count,questionText,correctChosenAnswers.length, isCorrect]);
|
|
showNextQuestion();
|
|
|
|
}
|
|
|
|
// NOTE: This function does not deal with Knowledge Check because there were no Sortable Questions in Knowledge Check to test
|
|
function checkSortableCorrect (checkObj, position)
|
|
{
|
|
var feedbackCorrect = document.getElementById('feedbackCorrect');
|
|
var feedbackIncorrect = document.getElementById('feedbackIncorrect');
|
|
var questionNumber = "#questionNumber" + position;
|
|
var newOrdering = $(questionNumber).find( ".sortable" ).sortable('toArray');
|
|
var isCorrect = true;
|
|
|
|
for (var v = 0; v < newOrdering.length; v++)
|
|
{
|
|
if (newOrdering[v] != (v + 1))
|
|
{
|
|
isCorrect= false;
|
|
}
|
|
}
|
|
|
|
// WOULD HAVE SOMETHING LIKE THE FOLLOWING IF ABLE TO TEST AND WOULD NEED TO PASS IN quizType
|
|
// Show feedback if Knowledge Check or go to next question for Assessment
|
|
/*if (quizType == 'Knowledge Check')
|
|
{
|
|
if (isCorrect)
|
|
{
|
|
feedbackCorrect.style.display = 'block';
|
|
feedbackIncorrect.style.display = 'none';
|
|
//noAnswerChosen.style.display = 'none'; //line not working completely
|
|
}
|
|
else
|
|
{
|
|
feedbackIncorrect.style.display = 'block';
|
|
feedbackCorrect.style.display = 'none';
|
|
//noAnswerChosen.style.display = 'none'; //line not working completely
|
|
}
|
|
}
|
|
else
|
|
{*/
|
|
if (isCorrect)
|
|
{
|
|
totalCorrect++;
|
|
}
|
|
count++;
|
|
var isCorrect2 = 0;
|
|
if (isCorrect) {
|
|
isCorrect2= 1;
|
|
}
|
|
var questionText = checkObj.getElementsByClassName("questionText")[0].innerHTML;
|
|
verboseCorrectAnswers.push([count,questionText,newOrdering.length, isCorrect2]);
|
|
showNextQuestion();
|
|
//}
|
|
}
|
|
|
|
function shuffle(elems)
|
|
{
|
|
allElems = (function(){
|
|
var ret = [], l = elems.length;
|
|
while (l--) { ret[ret.length] = elems[l]; }
|
|
return ret;
|
|
})();
|
|
|
|
var shuffled = (function(){
|
|
var l = allElems.length, ret = [];
|
|
while (l--) {
|
|
var random = Math.floor(Math.random() * allElems.length),
|
|
randEl = allElems[random].cloneNode(true);
|
|
allElems.splice(random, 1);
|
|
ret[ret.length] = randEl;
|
|
}
|
|
return ret;
|
|
})(), l = elems.length;
|
|
|
|
while (l--) {
|
|
elems[l].parentNode.insertBefore(shuffled[l], elems[l].nextSibling);
|
|
elems[l].parentNode.removeChild(elems[l]);
|
|
}
|
|
}
|
|
|
|
function showSlide(currentSlide, direction)
|
|
{
|
|
var nextSlide = parseFloat(currentSlide) + 1;
|
|
var previousSlide = parseFloat(currentSlide) - 1;
|
|
|
|
if (direction == 'next')
|
|
{
|
|
document.getElementById('slide' + currentSlide).style.display = 'none';
|
|
if (document.getElementById('slide' + nextSlide))
|
|
{
|
|
document.getElementById('slide' + nextSlide).style.display = 'block';
|
|
}
|
|
}
|
|
if (direction == 'previous')
|
|
{
|
|
document.getElementById('slide' + currentSlide).style.display = 'none';
|
|
if (document.getElementById('slide' + previousSlide))
|
|
{
|
|
document.getElementById('slide' + previousSlide).style.display = 'block';
|
|
}
|
|
}
|
|
}
|
|
|
|
function highlightArea(id, coords, countTotal)
|
|
{
|
|
var coordsArray = new Array();
|
|
coordsArray = coords.split(",");
|
|
|
|
// left and right coordinates
|
|
var xCoords = new Array();
|
|
var minXCoord = null;
|
|
var maxXCoord = null;
|
|
// up and down coordinates
|
|
var yCoords = new Array();
|
|
var minYCoord = null;
|
|
var maxYCoord = null;
|
|
|
|
for (var i=0; i < coordsArray.length; i=i+2)
|
|
{
|
|
xCoords.push(coordsArray[i]);
|
|
yCoords.push(coordsArray[i + 1]);
|
|
}
|
|
|
|
minXCoord = Math.min.apply(Math, xCoords);
|
|
maxXCoord = Math.max.apply(Math, xCoords);
|
|
|
|
minYCoord = Math.min.apply(Math, yCoords);
|
|
maxYCoord = Math.max.apply(Math, yCoords);
|
|
|
|
document.getElementById('div' + id).style.top = minYCoord;
|
|
document.getElementById('div' + id).style.left = minXCoord;
|
|
document.getElementById('div' + id).style.height = maxYCoord - minYCoord;//left = minXCoord;
|
|
document.getElementById('div' + id).style.width = maxXCoord - minXCoord;//right = maxXCoord;
|
|
|
|
// unhighlight all hotspots
|
|
unhighlightArea(countTotal);
|
|
|
|
// highlight only hotspot curser is over
|
|
document.getElementById('div' + id).style.display = 'block';
|
|
}
|
|
|
|
function unhighlightArea(countTotal)
|
|
{
|
|
for (var j=1; j <= countTotal; j++)
|
|
{
|
|
if (j != selectedHotspot)
|
|
{
|
|
document.getElementById('div' + j).style.display = 'none';
|
|
}
|
|
}
|
|
}
|
|
|
|
function selectArea(id, countTotal)
|
|
{
|
|
selectedHotspot = id;
|
|
unhighlightArea(countTotal);
|
|
}
|
|
|
|
function checkHotspotCorrect(correctAnswer, countTotal)
|
|
{
|
|
var correctId = correctAnswer.replace(/^(hotspot)0*/, '');
|
|
var feedbackCorrect = document.getElementById('feedbackCorrect');
|
|
var feedbackIncorrect = document.getElementById('feedbackIncorrect');
|
|
var correctCoords = document.getElementById('area' + correctId).getAttribute('coords');
|
|
|
|
if (correctId == selectedHotspot)
|
|
{
|
|
feedbackIncorrect.style.display = 'none';
|
|
feedbackCorrect.style.display = 'block';
|
|
}
|
|
else
|
|
{
|
|
if (selectedHotspot)
|
|
{
|
|
feedbackIncorrect.style.display = 'block';
|
|
feedbackCorrect.style.display = 'none';
|
|
document.getElementById('div' + selectedHotspot).style.display = 'none';
|
|
|
|
// Changed the selected hotspot to be the correct hotspot for feedback
|
|
selectedHotspot = correctId;
|
|
highlightArea(correctId, correctCoords, countTotal);
|
|
document.getElementById('div' + correctId).style.backgroundColor = '#30BF30';
|
|
}
|
|
}
|
|
}
|
|
|
|
function changeCallout(id, coords, countTotal)
|
|
{
|
|
for (var j=1; j <= countTotal; j++)
|
|
{
|
|
document.getElementById('callout' + j).style.display = 'none';
|
|
}
|
|
|
|
var coordsArray = new Array();
|
|
coordsArray = coords.split(",");
|
|
|
|
// left and right coordinates
|
|
var xCoords = new Array();
|
|
var minXCoord = null;
|
|
var maxXCoord = null;
|
|
// up and down coordinates
|
|
var yCoords = new Array();
|
|
var minYCoord = null;
|
|
var maxYCoord = null;
|
|
|
|
for (var i=0; i < coordsArray.length; i=i+2)
|
|
{
|
|
xCoords.push(coordsArray[i]);
|
|
yCoords.push(coordsArray[i + 1]);
|
|
}
|
|
|
|
minXCoord = Math.min.apply(Math, xCoords);
|
|
maxXCoord = Math.max.apply(Math, xCoords);
|
|
|
|
minYCoord = Math.min.apply(Math, yCoords);
|
|
maxYCoord = Math.max.apply(Math, yCoords);
|
|
|
|
document.getElementById('callout' + id).style.top = minYCoord;
|
|
document.getElementById('callout' + id).style.left = minXCoord;
|
|
document.getElementById('callout' + id).style.maxWidth = maxXCoord - minXCoord;
|
|
|
|
document.getElementById('callout' + id).style.display = "block";
|
|
}
|
|
|
|
function ConvertMilliSecondsIntoSCORM2004Time(intTotalMilliseconds){
|
|
|
|
var ScormTime = "";
|
|
|
|
var HundredthsOfASecond; //decrementing counter - work at the hundreths of a second level because that is all the precision that is required
|
|
|
|
var Seconds; // 100 hundreths of a seconds
|
|
var Minutes; // 60 seconds
|
|
var Hours; // 60 minutes
|
|
var Days; // 24 hours
|
|
var Months; // assumed to be an "average" month (figures a leap year every 4 years) = ((365*4) + 1) / 48 days - 30.4375 days per month
|
|
var Years; // assumed to be 12 "average" months
|
|
|
|
var HUNDREDTHS_PER_SECOND = 100;
|
|
var HUNDREDTHS_PER_MINUTE = HUNDREDTHS_PER_SECOND * 60;
|
|
var HUNDREDTHS_PER_HOUR = HUNDREDTHS_PER_MINUTE * 60;
|
|
var HUNDREDTHS_PER_DAY = HUNDREDTHS_PER_HOUR * 24;
|
|
var HUNDREDTHS_PER_MONTH = HUNDREDTHS_PER_DAY * (((365 * 4) + 1) / 48);
|
|
var HUNDREDTHS_PER_YEAR = HUNDREDTHS_PER_MONTH * 12;
|
|
|
|
HundredthsOfASecond = Math.floor(intTotalMilliseconds / 10);
|
|
|
|
Years = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_YEAR);
|
|
HundredthsOfASecond -= (Years * HUNDREDTHS_PER_YEAR);
|
|
|
|
Months = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_MONTH);
|
|
HundredthsOfASecond -= (Months * HUNDREDTHS_PER_MONTH);
|
|
|
|
Days = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_DAY);
|
|
HundredthsOfASecond -= (Days * HUNDREDTHS_PER_DAY);
|
|
|
|
Hours = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_HOUR);
|
|
HundredthsOfASecond -= (Hours * HUNDREDTHS_PER_HOUR);
|
|
|
|
Minutes = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_MINUTE);
|
|
HundredthsOfASecond -= (Minutes * HUNDREDTHS_PER_MINUTE);
|
|
|
|
Seconds = Math.floor(HundredthsOfASecond / HUNDREDTHS_PER_SECOND);
|
|
HundredthsOfASecond -= (Seconds * HUNDREDTHS_PER_SECOND);
|
|
|
|
if (Years > 0) {
|
|
ScormTime += Years + "Y";
|
|
}
|
|
if (Months > 0){
|
|
ScormTime += Months + "M";
|
|
}
|
|
if (Days > 0){
|
|
ScormTime += Days + "D";
|
|
}
|
|
|
|
//check to see if we have any time before adding the "T"
|
|
if ((HundredthsOfASecond + Seconds + Minutes + Hours) > 0 ){
|
|
|
|
ScormTime += "T";
|
|
|
|
if (Hours > 0){
|
|
ScormTime += Hours + "H";
|
|
}
|
|
|
|
if (Minutes > 0){
|
|
ScormTime += Minutes + "M";
|
|
}
|
|
|
|
if ((HundredthsOfASecond + Seconds) > 0){
|
|
ScormTime += Seconds;
|
|
|
|
if (HundredthsOfASecond > 0){
|
|
ScormTime += "." + HundredthsOfASecond;
|
|
}
|
|
|
|
ScormTime += "S";
|
|
}
|
|
|
|
}
|
|
|
|
if (ScormTime == ""){
|
|
ScormTime = "0S";
|
|
}
|
|
|
|
ScormTime = "P" + ScormTime;
|
|
|
|
return ScormTime;
|
|
}
|
|
|
|
function setStartTime() {
|
|
startTimeStamp = new Date();
|
|
} |