📄 api_wrapper.js
字号:
if (strWholeSec.length < 2) { strWholeSec = "0" + strWholeSec; } strSec = strWholeSec; if (strFractionSec.length) { strSec = strSec+ "." + strFractionSec; } if ((ts % 3600) != 0 ) var hour = 0; else var hour = (ts / 3600); if ( (tmp % 60) != 0 ) var min = 0; else var min = (tmp / 60); if ((new String(hour)).length < 2) hour = "0"+hour; if ((new String(min)).length < 2) min = "0"+min; var rtnVal = hour+":"+min+":"+strSec; return rtnVal}/** * Handles the use of the back button (saves data and closes SCO) */function doBack(){ checkAnswers(true); doLMSSetValue( "cmi.core.exit", "suspend" ); computeTime(); exitPageStatus = true; var result; result = doLMSCommit(); result = doLMSFinish();}/** * Handles the closure of the current SCO before an interruption. This is only useful if the LMS * deals with the cmi.core.exit, cmi.core.lesson_status and cmi.core.lesson_mode *and* the SCO * sends some kind of value for cmi.core.exit, which is not the case here (yet). */function doContinue(status){ // Reinitialize Exit to blank doLMSSetValue( "cmi.core.exit", "" ); var mode = doLMSGetValue( "cmi.core.lesson_mode" ); if ( mode != "review" && mode != "browse" ) { doLMSSetValue( "cmi.core.lesson_status", status ); } computeTime(); exitPageStatus = true; var result; result = doLMSCommit(); result = doLMSFinish();}/** * handles the recording of everything on a normal shutdown */function doQuit(){ checkAnswers(); computeTime(); exitPageStatus = true; var result; result = doLMSCommit(); result = doLMSFinish();}/** * Called upon unload event from body element */function unloadPage(status){ if (exitPageStatus != true) { doQuit( status ); }}/** * Third section - depending on Dokeos - check answers and set score */var questions = new Array();var questions_answers = new Array();var questions_answers_correct = new Array();var questions_types = new Array();var questions_score_max = new Array();var questions_answers_ponderation = new Array();/** * Checks the answers on the test formular page */function checkAnswers(interrupted){ var tmpScore = 0; var status = 'not attempted'; var scoreMax = 0; for(var i=0; i<questions.length;i++) { if(questions[i] != undefined && questions[i] != null){ var idQuestion = questions[i]; var type = questions_types[idQuestion]; var interactionScore = 0; var interactionAnswers = ''; var interactionCorrectResponses = ''; var interactionType = ''; if (type == 'mcma') { var interactionType = 'choice'; var myScore = 0; for(var j=0; j<questions_answers[idQuestion].length;j++) { var idAnswer = questions_answers[idQuestion][j]; var answer = document.getElementById('question_'+(idQuestion)+'_multiple_'+(idAnswer)); if(answer.checked == true) { interactionAnswers += idAnswer+','; for(k=0;k<questions_answers_correct[idQuestion].length;k++) { if(questions_answers_correct[idQuestion][k] == idAnswer) { if(questions_answers_ponderation[idQuestion][idAnswer]) { myScore += questions_answers_ponderation[idQuestion][idAnswer]; } else { myScore ++; } } } } } interactionScore = myScore; //correct responses work by pattern, see SCORM Runtime Env Doc //for(k=0;k<questions_answers_correct[idQuestion].length;k++) //{ // interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+','; //} scoreMax += questions_score_max[idQuestion]; } else if(type == 'mcua') { var interactionType = 'choice'; var myScore = 0; for(var j=0; j<questions_answers[idQuestion].length;j++) { var idAnswer = questions_answers[idQuestion][j]; var answer = document.getElementById('question_'+(idQuestion)+'_unique_'+(idAnswer)); if(answer.checked == true) { interactionAnswers += idAnswer; if(questions_answers_correct[idQuestion] == idAnswer) { if(questions_answers_ponderation[idQuestion][idAnswer]) { myScore += questions_answers_ponderation[idQuestion][idAnswer]; } else { myScore ++; } } } } interactionScore = myScore; //correct responses work by pattern, see SCORM Runtime Env Doc //interactionCorrectResponses += questions_answers_correct[idQuestion].toString(); scoreMax += questions_score_max[idQuestion]; } else if(type == 'tf') { var interactionType = 'true-false'; var myScore = 0; for(var j=0; j<questions_answers[idQuestion].length;j++) { var idAnswer = questions_answers[idQuestion][j]; var answer = document.getElementById('question_'+(idQuestion)+'_tf_'+(idAnswer)); if(answer.checked.value == true) { interactionAnswers += idAnswer; for(k=0;k<questions_answers_correct[idQuestion].length;k++) { if(questions_answers_correct[idQuestion][k] == idAnswer) { if(questions_answers_ponderation[idQuestion][idAnswer]) { myScore += questions_answers_ponderation[idQuestion][idAnswer]; } else { myScore ++; } } } } } interactionScore = myScore; //correct responses work by pattern, see SCORM Runtime Env Doc //interactionCorrectResponses += questions_answers_correct[idQuestion].toString(); scoreMax += questions_score_max[idQuestion]; } else if(type == 'fib') { var interactionType = 'fill-in'; var myScore = 0; for(var j=0; j<questions_answers[idQuestion].length;j++) { var idAnswer = questions_answers[idQuestion][j]; var answer = document.getElementById('question_'+(idQuestion)+'_fib_'+(idAnswer)); if(answer.value) { interactionAnswers += answer.value+','; for(k=0;k<questions_answers_correct[idQuestion].length;k++) { if(questions_answers_correct[idQuestion][k] == answer.value) { if(questions_answers_ponderation[idQuestion][idAnswer]) { myScore += questions_answers_ponderation[idQuestion][idAnswer]; } else { myScore ++; } } } } } interactionScore = myScore; //correct responses work by pattern, see SCORM Runtime Env Doc //for(k=0;k<questions_answers_correct[idQuestion].length;k++) //{ // interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+','; //} scoreMax += questions_score_max[idQuestion]; } else if(type == 'matching') { var interactionType = 'matching'; var myScore = 0; for(var j=0; j<questions_answers[idQuestion].length;j++) { var idAnswer = questions_answers[idQuestion][j]; var answer = document.getElementById('question_'+(idQuestion)+'_matching_'+(idAnswer)); if(answer && answer.value) { interactionAnswers += answer.value+','; for(k=0;k<questions_answers_correct[idQuestion].length;k++) { var left = questions_answers_correct[idQuestion][k][0]; var right = questions_answers_correct[idQuestion][k][1]; if(left == idAnswer && right == answer.value) { if(questions_answers_ponderation[idQuestion][idAnswer]) { myScore += questions_answers_ponderation[idQuestion][idAnswer]; } else { myScore ++; } } } } } interactionScore = myScore; //correct responses work by pattern, see SCORM Runtime Env Doc //for(k=0;k<questions_answers_correct[idQuestion].length;k++) //{ // interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+','; //} scoreMax += questions_score_max[idQuestion]; } else if(type == 'free') { //ignore for now as a score cannot be given var interactionType = 'likert'; interactionScore = 0; //interactionAnswers = document.getElementById('question_'+(idQuestion)+'_free').value; //correct responses work by pattern, see SCORM Runtime Env Doc //interactionCorrectResponses += questions_answers_correct[idQuestion].toString(); } else if(type == 'hotspot') { var interactionType = 'sequencing'; //if(question_score && question_score[idQuestion]){ // interactionScore = question_score[idQuestion]; //} //else, 0 //interactionAnswers = document.getElementById('question_'+(idQuestion)+'_free').innerHTML; //correct responses work by pattern, see SCORM Runtime Env Doc //for(k=0;k<questions_answers_correct[idQuestion].length;k++) //{ // interactionCorrectResponses += questions_answers_correct[idQuestion][k].toString()+','; //} } else { // } tmpScore += interactionScore; doLMSSetValue('cmi.interactions.'+idQuestion+'.id','Q'+idQuestion); doLMSSetValue('cmi.interactions.'+idQuestion+'.type',interactionType); doLMSSetValue('cmi.interactions.'+idQuestion+'.student_response',interactionAnswers); doLMSSetValue('cmi.interactions.'+idQuestion+'.result',interactionScore); //correct responses work by pattern, see SCORM Runtime Env Doc //doLMSSetValue('cmi.interactions.'+idQuestion+'.correct_responses',questions_answers_correct[idQuestion]); //doLMSSetValue('cmi.interactions.'+idQuestion+'.correct_responses',interactionCorrectResponses); } } doLMSSetValue('cmi.core.score.min',0); doLMSSetValue('cmi.core.score.max',scoreMax); doLMSSetValue('cmi.core.score.raw',tmpScore); //doLMSSetValue('cmi.student_data.mastery_score',(scoreMax*0.7)); //get status var mastery_score = doLMSGetValue('cmi.student_data.mastery_score'); if(mastery_score <= 0) { mastery_score = (scoreMax*0.80); } if(tmpScore > mastery_score) { status = 'passed'; } else { status = 'failed'; } doLMSSetValue('cmi.core.lesson_status',status); if((interrupted==true) && (status != 'completed') && (status != 'passed')) { doLMSSetValue('cmi.core.exit','suspended'); } else { } return false; //do not submit the form}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -