/*********************************************************************** quiz.js ************************************************************************ Do not change this file unless it should change for all users. This file defines functions that deal with the various quizes and tests ************************************************************************/ //TODO //1. Save responses in array [pageID,[responses,responses],nrAttempts, correct] // pageID - the id in the addressbar after pageid= // responses - an array with the id's of the selected responses // nrAttempts - nr of attempts required to get correct // correct - true/false if they've gotten it right at some point //2. When returning to a question // Check if the question has been attempted before // Put in the previous responses // Set the next button to just move to the next page if they've gotten it right before // Dim options so they can't change their response if they've gotten it correct //3. Warn on reload // Warn user on reload that responses will be cleared function TestResponseData(){ this.testPassStatus; this.totalTestQuestions; this.testStarted = false; this.questionData = new Array(); } function QuestionResponseData(){ this.questionAttempted = false; this.questionType; this.questionNumber = 0; this.passStatus; this.correctResponses = new Array(); this.givenResponses = new Array(); }; //Called by content.js when a section page is a quiz page. Content.prototype.quiz_createChallenge = function (){ var challengeObjs = $(this).find("."+elements.challenge); var c = this; var thisIsATest = c.currentPageItem.currentQuestionInfo.isTestQuestion; if(thisIsATest){ //Check if this is the first page $("#backBtn_div").hide(); var webTemplate = c.currentPageItem.template; if(webTemplate == 'Quiz_Text_Choice' || webTemplate == 'Quiz_Image_Choice' || webTemplate == 'Quiz_Drag_Drop'){ $("#nextBtn_div").hide(); } //Check if we started on the first page var quiz_started_correct = c.quiz_checkFirstTestPage(); //Find the pass grade testPassGrade = c.currentPageItem.currentQuestionInfo.minTestGrade; if(quiz_started_correct == false){ return; } } var questionType = $('.challenge').attr('questionType'); //Hide all feedback until needed hideElements([ $("."+elements.feedback), $("."+elements.feedbackIncorrect), $("."+elements.feedbackCorrect) ]); c.quiz_submitButton(questionType); c.quiz_formatQuestions(); }; //Helper function that allows for the entire element to be clickable, image, words //and anything else within the answer option Content.prototype.quiz_makeImageSpanClickable = function(){ //Figure out if it is checkboxes or radio buttons var isMultiSel = false; if($("."+elements.multipleSelect).length){ isMultiSel = true; } //make a list of all the answer options var answerOptions = $(".image_for_image_response"); $(answerOptions).each(function(i){ //Bind each answer option's click function $(this).bind('click',function(){ //If multiple select checkboxes, do this if(isMultiSel){ var cb = $(this).parent().find('input:checkbox'); if($(cb).length == 0){ cb = $(this).parent().prev().find('input:checkbox'); } $(cb).prop('checked',!$(cb).is(':checked')); } //If radio buttons do this else{ var cb = $(this).parent().find('input:radio'); if($(cb).length == 0){ cb = $(this).parent().prev().find('input:radio'); } //Radio buttons can't be 'undone' one must always be chosen. if(!$(cb).is(':checked')){ $(cb).prop('checked',!$(cb).is(':checked')); } } }); }); } //Helper function that allows for the entire element to be clickable, image, words //and anything else within the answer option Content.prototype.quiz_makeSpanClickable = function(){ //Figure out if it is checkboxes or radio buttons var isMultiSel = false; if($("."+elements.multipleSelect).length){ isMultiSel = true; } //make a list of all the answer options var answerOptions = $(".answerOption_p"); $(answerOptions).each(function(i){ //Bind each answer option's click function $(this).bind('click',function(){ var cb = $(this).parentsUntil(".quizCell").parent().prev().find('input:checkbox'); if($(cb).length == 0){ cb = $(this).parent().prev().find('input:checkbox'); } //If multiple select checkboxes, do this if(isMultiSel){ $(cb).prop('checked',!$(cb).is(':checked')); } //If radio buttons do this else{ //$(this).parent().find('input:radio').prop('checked', true); } }); }); } //Creates an array of quiz questions in the current section-1 //This is used to figure out the quiz number later var quizQuestionArray = []; Content.prototype.quiz_fillQuestionArray = function(chapterObject){ quizQuestionArray = []; var pageObjects = $(chapterObject).find(".section-3").children(".ax-topic"); $(pageObjects).each(function (i) { var curr_webTemplate = $(this).attr("webtemplate"); var quizStylerId = $(this).find(".heading1").attr("id"); if(curr_webTemplate == "Quiz_Text_Choice" || curr_webTemplate == "Quiz_Image_Choice" || curr_webTemplate == "Quiz_Drag_Drop"){ quizQuestionArray.push(quizStylerId); } }); } /* quiz.js New quiz with three functions test - a whole chapter test with summerized results after all questions are answered quiz - question that shows results on the same slide evaluation - shows what users think of the course */ var testFeedback = []; //Check the length of this to see how many questions have been answered //testFeedback array holds information on each question the user has answered //[passStatus, questionTitle, questionText]; //passStatus: did the user answer correctly (true/false) //questionTitle: The page title on the question page //questionText: the actual question text (lcQuestion) var testPassGrade = 0; //saves the minimum required pass grade from the chapter object var startedOnFirstPage = false; //Check if the user started on the first page or not. var testStarted = false; //Figure out the first page in the chapter and move user there //Used for situations where the user has reloaded or used //their browser's back button to navigate Content.prototype.test_restart = function (){ var c = this; //Warn user (broken into two messages to prevent problems in some languages with overly long messages causing problems) alert(GENTEXT_QUIZ_ERR_RELOAD +" " + GENTEXT_QUIZ_ERR_RESTART); //Reset variables testFeedback = []; startedOnFirstPage = false; testStarted = false; //Load first page in chapter var firstQuizPage = c.currentPageItem.chapterlink; c.loadCurrentPage(firstQuizPage); } Content.prototype.quiz_formatImageQuestions = function(){ //Should be called after quiz_formatQuestions $("#imageAnswerGroup").detach().appendTo($("."+elements.pageDelimiter)); } Content.prototype.quiz_formatQuestions = function (){ var c = this; //Wrap the questions into a table $(".optionGroupForm").wrapInner("
"); var quizType = $(".challenge").attr("questionType"); var curTemplate = c.currentPageItem.template; if(quizType == "singleselect"){ if(curTemplate == "Quiz_Image_Choice"){ c.quiz_formatImage(); } else if(curTemplate == "Quiz_Text_Choice"){ c.quiz_formatSingle(); } } else if(quizType == "multipleselect"){ if(curTemplate == "Quiz_Image_Choice"){ c.quiz_formatMultiImage(); } else { c.quiz_formatMulti(); } } else { c.quiz_formatDragDrop(); } c.quiz_formatImageQuestions(); }; Content.prototype.quiz_formatDragDrop = function(){ var c = this; if($("."+elements.dragdrop).length < 1){ return; } //move the correct answer information to the proper location var $rightAnswers = $(".lcCorrectResponse").prev().prev(); $(".lcCorrectResponse").appendTo($rightAnswers); } Content.prototype.quiz_formatMultiImage = function (){ var c = this; var checkboxCounter = 1; //Table created in arbortext //Go through each placeholder and add in the correct checkbox var placeholders = $(".placeholder_imageSelect"); $(placeholders).each(function(i,v){ var checkboxId = "cb_"+checkboxCounter; //check if the following element is correct or not var correctresponse = $(this).parent(".multiple_correct"); var textForLabel = $(this).siblings(".text_for_image_response").text(); if(correctresponse.length){ //This is a correct response $(this).html(""); } else { //This is an incorrect response $(this).html(""); } checkboxCounter++; }); c.quiz_makeImageSpanClickable(); }; Content.prototype.quiz_formatMulti = function (){ var c = this; var checkboxCounter = 1; //Do we even need a table anymore? var optionList = $(".multipleSelectOption"); $(optionList).each(function(i,v){ var checkboxId = "cb_"+checkboxCounter; var textForLabel = $(this).find(".answerOption_p").text(); $(this).html("
"); checkboxCounter++; }); /* $(".multipleSelectOption").each(function(ii,vv){ $(vv).click(function(e){ $("#cb_"+ii).attr("checked", !$("#cb_"+ii).attr("checked")); }); });*/ }; Content.prototype.quiz_formatImage = function(){ var c = this; //Table created in arbortext var checkboxCounter = 1; //Go through each placeholder and add in the correct checkbox var placeholders = $(".placeholder_imageSelect"); $(placeholders).each(function(i,v){ var checkboxId = "cb_"+checkboxCounter; //check if the following element is correct or not var correctresponse = $(this).parent(".single_correct"); var textForLabel = $(this).siblings(".text_for_image_response").text(); if(correctresponse.length){ //This is a correct response $(this).html(""); } else { //This is an incorrect response $(this).html(""); } checkboxCounter++; }); //Lägg till id på resp radiobutton /*$(".radioSingle").each(function(i,v){ $(v).attr("id","cb_"+i); });*/ c.quiz_makeImageSpanClickable(); }; Content.prototype.quiz_addNumToPageTitle = function (){ var c = this; var currPageNum = c.quiz_getQuestionNum(); currentTitle = $(".heading1").text(); if($("#at_body_container").attr("quiz_type") == "test" || $("#at_body_container").attr("quiz_type") == "excercise"){ $(".heading1").text(currPageNum + ". " + currentTitle); }else{ $(".heading1").text(currentTitle); } } function getWebTemplate(){ var webTemplate = $(".section-3").find("div:first").attr("webtemplate"); return webTemplate; }; Content.prototype.quiz_formatSingle = function (){ var c = this; var checkboxCounter = 1; //Do we even need a table anymore? var optionList = $(".singleSelectOption"); $(optionList).each(function(i,v){ var checkboxId = "rb_"+checkboxCounter; var textForLabel = $(this).find(".answerOption_p").text(); $(this).html("
"); checkboxCounter++; }); }; function quiz_presentQuizResults(passStatus, feedbackTitle, feedback){ //Find the content and set it to c so that we can use the prototype functions var c = content; //Remove any existing feedback first. $('#questionFeedbackBox').remove(); //Create the feedback box var dialogDiv = "

"+feedback+"

"; $("#at_body_container").append(dialogDiv); //Turn the feedback box into a dialog with an OK button (that closes the dialog box) using jquery ui //TODO: Set the buttons' text to be language based. var nextQuestionText = GENTEXT_NEXT_BTN; //figure out the window width var winW = $(window).width(); //Save 60% of the width for the dialog width var winW = Math.floor(winW*(0.60)); if(passStatus){ //Passed $( "#questionFeedbackBox" ).dialog({ width:winW, modal: true, position: { my: "center", at: "center"}, dialogClass: "clickoncloseoutside feedbackCorrectDialog", closeText: false, close: function(event, ui) { //Destroys the dialogbox on close. Prevents multiple feedback boxes from existing. $(this).dialog("close"); $(this).remove(); } }); } else { //Failed $( "#questionFeedbackBox" ).dialog({ width:winW, modal: true, position: { my: "center", at: "center"}, dialogClass: "clickoncloseoutside feedbackIncorrectDialog", closeText: false, close: function(event, ui) { //Destroys the dialogbox on close. Prevents multiple feedback boxes from existing. $(this).dialog("close"); $(this).remove(); } }); } }; //What happens when the user selects to try again function quiz_retry(){ } //Runs when the user gets the answer correct in a quiz and clicks the next question button function quiz_next(){ var c = content; var nextID = c.currentPageItem.nextPage; c.loadCurrentPage(nextID); } function quiz_singleSelectCorrect(){ var isPassed = false; //Get the content object var c = content; //Figure out if this is a test or not var isTest = c.currentPageItem.currentQuestionInfo.isTestQuestion; //Need to check which element is checked (if one even is) var response = $('input[name=answerGroup]:checked'); //make sure at least one response is given if(response.length !== 0){ //Then check if that element's parent has the attribute iscorrect set to true var answer = $(response).parent().parent().attr("iscorrect"); //Check that a correct response was found if(answer == "true"){ isPassed = true; } else { //Check another system //Check another system if it might be correct that way instead... var answer2 = $(response).hasClass("radioSingle1"); if(answer2){ isPassed = true; } } if(isTest){ quiz_saveTestResults(isPassed); } else { quiz_getFeedback(isPassed); } //Disable clicking on radio buttons //Don't disable buttons, the user should keep trying until they get it correct. //var $radioButtons = $(":radio"); //$radioButtons.each(function () { // $(this).attr('disabled','disabled'); //}); } else{ c.quiz_noQuizResponse(isTest); } }; function quiz_DragDropCorrect(){ var isPassed = false; //Get the content object var c = content; //Figure out if this is a test or not var isTest = c.currentPageItem.currentQuestionInfo.isTestQuestion; //Need to check which (if any) objects are selected(dropped) var $response = $('.'+elements.droppable+'[dropped]'); //make sure at least one response is given if($response.length !== 0){ //Then check if that element has any siblings with the CorrectResponse class var correctAnswers = $('.'+elements.droppable); correct = 0; $response.each(function(i, v) { if($(v).attr("correct") == 1 || $(v).attr("correct") == "1"){ correct+=1; } }); //Check that a correct response was found if(correct == correctAnswers.length){ isPassed = true; } if(isTest){ //If the question is part of a test, save the results quiz_saveTestResults(isPassed); } else { //If the question is not part of a test, present the results quiz_getFeedback(isPassed); } } else{ //The user is not allowed to go forward unless they have selected at least one response c.quiz_noQuizResponse(isTest); } }; function quiz_multipleSelectCorrect(){ var isPassed = false; var numWrong = 0; //Get the content object var c = content; //Figure out if this is a test or not var isTest = c.currentPageItem.currentQuestionInfo.isTestQuestion; //check that at least one response is chosen var $response = $('input[name=answerGroup]:checked'); var numCorrect = 0; //Get the total correct responses (set by arbortext as an attribute) var shouldBeCorrect = $(".lcAnswerOptionGroup").attr("correctResponses"); if($response.length !== 0){ $response.each(function(i){ //Then check if that element's parent has the attribute iscorrect set to true var answer = $(this).parent().parent().attr("iscorrect"); //Check that a correct response was found if(answer == "true"){ numCorrect++; }else{ //Check another system if it might be correct that way instead... var answer2 = $(this).hasClass("checkboxMulti1"); if(answer2){ numCorrect++; }else{ //Just remove one from the number correct to force the number to no longer match numCorrect--; } } }); //Check if the number correct responses matches the number that should be correct if(numCorrect == shouldBeCorrect){ isPassed = true; } if(isTest){ //With a test, save the results to present on the summary page quiz_saveTestResults(isPassed); } else { //With an exercise, show the results immediately quiz_getFeedback(isPassed); } } else{ c.quiz_noQuizResponse(isTest); } }; Content.prototype.quiz_noQuizResponse = function(isTest){ alert(GENTEXT_QUIZ_ERR_NORESPONSE); } function quiz_getFeedback(passStatus){ var feedback = ""; var feedbackTitle; var typeOfQuiz = $('.challenge').attr('quizType'); //If not a test if(typeOfQuiz !== "test"){ //We don't have a test, just present the information on the same page //If pass if(passStatus){ var correctFeedback = $("."+elements.feedbackCorrect); if(correctFeedback.length){ feedback = correctFeedback.html(); feedbackTitle = GENTEXT_QUIZ_CORRECT; } else { feedback = GENTEXT_QUIZ_CORRECT; feedbackTitle = GENTEXT_QUIZ_CORRECT; } }else{ var incorrectFeedback = $("."+elements.feedbackIncorrect); if(incorrectFeedback.length){ feedback = incorrectFeedback.html(); feedbackTitle = GENTEXT_QUIZ_INCORRECT; } else { feedback = GENTEXT_QUIZ_INCORRECT; feedbackTitle = GENTEXT_QUIZ_INCORRECT; } } quiz_presentQuizResults(passStatus, feedbackTitle, feedback); } else { //We have a test, save the results for presentation later quiz_saveTestResults(passStatus); } }; /*-------------------------------------------------------------- TEST FUNCTIONS ----------------------------------------------------------------*/ var currentTitle = ""; Content.prototype.quiz_createTest = function (chapterObject){ var c = this; //Hide all feedback since it is not needed in a test hideElements([ $("span[class='"+elements.feedback+"']"), $("div[class='"+elements.feedbackIncorrect+"']"), $("div[class='"+elements.feedbackCorrect+"']"), $("#backBtn") ]); //Create a form for each answerOptionGroup $("." + elements.answerGroup).wrap("
"); //Add in function for the submit button //Checks for question type var questionType = $('.challenge').attr('questionType'); //When using Drag and Drop-quizzes, qType will return false //If undefined, check for draganddrop-challenge if(questionType == undefined && $("."+elements.dragdrop)){ questionType = $("."+elements.challenge).find("div").filter(":first").attr("class"); } c.quiz_createSubmitButton(questionType,"test"); c.quiz_formatQuestions(); //Set the page title so that it has a number before it //c.quiz_addNumToPageTitle(); }; //Gets the total number of pages in the section Content.prototype.getTotalPages = function (section2Title){ var slashLocation = section2Title.lastIndexOf("/"); var totalPages = section2Title.slice(slashLocation+1, section2Title.length-1); return totalPages; }; //Figures out the current page number Content.prototype.getCurrentPage = function (section2Title){ var slashLocation = section2Title.lastIndexOf("/"); var paranLocation = section2Title.lastIndexOf("("); var currPage = section2Title.slice(paranLocation+1, slashLocation); return currPage; }; //Calls a bunch of other functions to create the summary page Content.prototype.quiz_createSummaryPage = function(){ var c = this; var startOfChapter = c.currentPageItem.chapterlink; //If we don't have any feedback (such as when a user has somehow navigated directly to the summary page...) //Return to the first page in the chapter if(!testFeedback.length){ c.test_restart(); return; } $("."+elements.pageDelimiter).wrapInner("
"); //Put content into scroll c.quiz_fillSummaryPage(); //Set title c.setSummaryTitle(); //Scorm anrop c.SetScormGrade(); //Change back button $("#backBtn_div").hide(); //$("#"+ elements.backButton).hide(); } //Sets the page title for the summary page Content.prototype.setSummaryTitle = function () { var c = this; //Figure out if user passed var passed = c.CalculatePassed(); var totalQuestions = testFeedback.length; //Total number of questions var questionsRight = c.NumberQuestionsRight(); var summaryTitle = GENTEXT_QUIZ_TESTSUMMARY + ": "; //Set title if(passed){ summaryTitle += GENTEXT_QUIZ_PASS; $(".Page_Centered_Text_Heading").addClass("quizPassTitle"); } else{ summaryTitle += GENTEXT_QUIZ_FAIL; $(".Page_Centered_Text_Heading").addClass("quizFailTitle"); } summaryTitle += " (" + questionsRight + "/" + totalQuestions + ")"; $(".Page_Centered_Text_Heading").text(summaryTitle); }; //Creates the navigation for the summary page Content.prototype.createSummaryNav = function (){ var c = this; //Create the Next and home buttons for the quiz summary page var navHTML = '
'; navHTML += '
'; navHTML += ''; $("#at_nav").html(navHTML); //Add click function to the next button $("#nextButton").click(function(e){ c.gotoNextPage(); }); }; //Sets the scorm grade at the end of the test Content.prototype.SetScormGrade = function (){ var c = this; var passed = c.CalculatePassed(); var grade = c.CalculateGrade(); if(passed){ setStatusPassed(); setStatusComplete(); } else { setStatusFailed(); } setScore(grade); LMSCommit(); }; //Creates the summary page Content.prototype.quiz_fillSummaryPage = function (){ var summaryContentString = ""; var c = this; //First bit of the table summaryContentString += ""; //Fill in information for each question for(var i = 0; i < testFeedback.length; i++){ //start a new row summaryContentString += ""; //First column has an icon showing right or wrong for that question summaryContentString += ""; //Third column has the title and question, and the correct response as well as the given response var currQuestion = testFeedback[i].questionText; var currQuestionTitle = testFeedback[i].questionTitle; summaryContentString += ""; }else { //If the question was wrong, list the correct answers and the user answers if(testFeedback[i].passStatus == false){ summaryContentString += "

"+GENTEXT_QUIZ_YOURRESPONSE+" "; for(j=0;j"; for(j=0;j"; for(j=0;j 0){ tempQData.givenResponses.push(currRespText); } }); } //var arrayObject = [passStatus, questionTitle, questionText]; testFeedback.push(tempQData); //Load next page c.loadCurrentPage(c.currentPageItem.nextPage); }; //Figure out the number of questions answered correctly //Return that number Content.prototype.NumberQuestionsRight = function(){ var questionsRight = 0; for(var i = 0; i < testFeedback.length; i++){ if(testFeedback[i].passStatus == true){ questionsRight = questionsRight +1; } } return questionsRight; }; //Figures out if the user passed Content.prototype.CalculatePassed = function(){ var c = this; var totalQuestions = testFeedback.length; var questionsRight = c.NumberQuestionsRight(); var percentpassed = c.CalculateGrade(); if(percentpassed >= testPassGrade){ return true; } else{ return false; } }; //Calculates the user percent Content.prototype.CalculateGrade = function(){ var c = this; var totalQuestions = testFeedback.length; var questionsRight = c.NumberQuestionsRight(); var percentpassed = 0; if(totalQuestions > 0){ percentpassed = (questionsRight/totalQuestions)*100; } return percentpassed; }; /*-------------------------------------------------------------- QUIZ FUNCTIONS ----------------------------------------------------------------*/ Content.prototype.quiz_createNormal = function (){ var c = this; //Create a form for each answerOptionGroup $("." + elements.answerGroup).wrap("
"); //Set the page title so that it has a number before it //c.quiz_addNumToPageTitle(); //Add in function for the submit button //Checks for question type (should be quiz/test/evaulation) var quizType = $('.challenge').attr('quizType'); var questionType = $('.challenge').attr('questionType'); if(quizType == undefined && $("."+elements.dragdrop)){ quizType = $("."+elements.challenge).find("div").filter(":first").attr("class"); } c.quiz_createSubmitButton(questionType,quizType); c.quiz_formatQuestions(); }; Content.prototype.quiz_submitButton = function(questionType){ var newHtml = '

' +GENTEXT_SUBMIT_BTN+ '

'; $("#questionScrollDiv").append(newHtml); $("#scrollDiv").append(newHtml); $(".dragdrop_p_wrapper").append(newHtml); //$(".Quiz_Drag_Drop_figure").append(newHtml); switch(questionType){ case "singleselect": $("#quizBtn").click(function(e){ quiz_singleSelectCorrect(); }); break; case "multipleselect": $("#quizBtn").click(function(e){ quiz_multipleSelectCorrect(); }); break; case "dragDrop": $("#quizBtn").click(function(e){ quiz_DragDropCorrect(); }); break; default: if(window.console){ console.log("no match of questionType found"); } break; } }; /*-------------------------------------------------------------- EVAL FUNCTIONS ----------------------------------------------------------------*/ function quiz_submitButtonEval(questionType){ }; /*-------------------------------------------------------------- HELPER FUNCTIONS ----------------------------------------------------------------*/ //Check quiz minimum passing grade Content.prototype.quiz_checkPassingGrade = function(chapterObject){ var passGrade = $(chapterObject).attr("quiz_pass_limit"); return passGrade; }; function hideFeedbackBox(){ $(".questionFeedbackBox").hide(); }; //Creates an array of quiz questions in the current section-1 //This is used to figure out the quiz number later var quizQuestionArray = []; Content.prototype.quiz_fillQuestionArray = function(chapterObject){ quizQuestionArray = []; var pageObjects = $(chapterObject).find(".section-3").children(".ax-topic"); $(pageObjects).each(function (i) { var curr_webTemplate = $(this).attr("webtemplate"); var quizStylerId = $(this).find(".heading1").attr("id"); if(curr_webTemplate == "Quiz_Text_Choice" || curr_webTemplate == "Quiz_Image_Choice" || curr_webTemplate == "Quiz_Drag_Drop"){ quizQuestionArray.push(quizStylerId); } }); } //Figures out the current number of the quiz question Content.prototype.quiz_getQuestionNum = function(){ var c = this; var currentPageID = c.getPageID(); var dotIndex = currentPageID.lastIndexOf("#"); currentPageID = currentPageID.slice(dotIndex+1); for(var i =0; i < quizQuestionArray.length; i++){ if(quizQuestionArray[i] == currentPageID) { return i+1; } } } /********************************************* Function: receiveMessage Indata: event Hanterar anrop från externa prov *********************************************/ Content.prototype.receiveMessage = function(event){ var c = this; if(event.data == "next") { //Navigera till correct //section-4 quiz="complete" $(".externalQuiz").remove(); showExternalQuizResult("complete"); for(var i=0;i<10;i++){ if(lmsConnected){ //Registrera complete i LMS setStatusPassed(); setStatusComplete(); setScore("1"); LMSCommit(); } } } if(event.data == "prev"){ //Navigera till incorrect //section-4 quiz="incomplete" $(".externalQuiz").remove(); showExternalQuizResult("incomplete"); //Registrera fail i LMS if(lmsConnected){ setStatusFailed(); setScore("0"); LMSCommit(); } } if(event.data == "hidepreload"){ $("#quizPreload").hide(); } } showExternalQuizResult = function(result){ var resultID = ""; if(result == "complete"){ resultID = $(".quiz_complete").attr('id'); } else { resultID = $(".quiz_incomplete").attr('id'); } $("#"+resultID).show(); } //Presents the test results. //Edit to set how the client wishes the test results to be shown. //alertMessage - the correct or incorrect text to be displayed //correctText - says 'correct' or 'incorrect' or whatever else is //specified in settings. function template_presentTestResults(passStatus){ var alertMessage = ""; var titleText = ""; //If pass if(passStatus){ alertMessage = $("div[class='"+elements.feedbackCorrect+"']").text(); titleText = GENTEXT_QUIZ_CORRECT; }else{ alertMessage = $("div[class='"+elements.feedbackIncorrect+"']").text(); titleText = GENTEXT_QUIZ_INCORRECT; } //Opens results in a dialog box if(alertMessage.length){ var tempDiv = '
'+alertMessage+'
'; } else { var tempDiv = '
'+titleText+'
'; } $("#at_content").append(tempDiv); $("#feedbackDialog" ).dialog({ autoOpen: false, width:300, closeText: false }); $("#feedbackDialog").dialog("open"); } //Checks if the user is on the first page //If not, returns to first page in chapter Content.prototype.quiz_checkFirstTestPage = function (){ var c = this; //Check if this is the first page //check if the chapter link and the page link are the same if(c.currentPageItem.currentQuestionInfo.isFirstQuestion == true){ //If this is the first page, set a flag that says that the user started there startedOnFirstPage = true; //Check if the test has been attempted before if(testStarted == true){ c.test_restart(); return false; } return true; } else { testStarted = true; //set the quiz started to true. if(startedOnFirstPage == false){ c.test_restart(); return false; } return true; } } /*Resizes elements in drag and drop so that they scale nicely*/ Content.prototype.quiz_resizeDragDrop = function (){ //Max width 1920px (Currently image space is 1556 at max) var backgroundImage = $(".Quiz_Drag_Drop_figure.graphic").find("img:first"); //Base everything off of the size of the background image var i = new Image(); i.src = $(backgroundImage).attr('src'); //Don't do anything until the image is loaded, so that we can get the original size i.onload = function() { //Get the original image width var originalWidth = i.width; //Get new image size var currentWidth = $(backgroundImage).width(); //Figure out the ratio var imageRatio = currentWidth/originalWidth; //Go through all the images and widths on the screen and multiple them by the ratio. var resizeElements = $(".DragDropText"); $(resizeElements).each(function(){ //Set the width var specificedWidth = parseInt($(this).css('max-width'), 10); var newWidth = Math.floor(specificedWidth*imageRatio); $(this).css("max-width",newWidth); }); //Change the left & top positions of the droppable and draggable sections var droppableBoxes = $(".droppable, .draggable"); $(droppableBoxes).each(function(){ //Set the left position var originalLeft = parseInt($(this).css('left'), 10); var newLeft = Math.floor(originalLeft*imageRatio); $(this).css("left",newLeft); //set the top position var originalTop = parseInt($(this).css('top'), 10); var newTop = Math.floor(originalTop*imageRatio); $(this).css("top",newTop); }); var dragDropImgs = $(".dragDropImg"); $(dragDropImgs).each(function(){ var currImg = $(this); var j = new Image(); j.src = $(this).attr('src'); //Don't do anything until the image is loaded, so that we can get the original size j.onload = function() { //Get the original image width var dragdropOriginalWidth = j.width; //Set the width var newdragdropWidth = Math.floor(dragdropOriginalWidth*imageRatio); $(currImg).css("width",newdragdropWidth); $(currImg).attr("width",newdragdropWidth); } }); } }
"; if(currQuestionTitle.length > 0){ //Only add in the title if it exists. summaryContentString += "

" + currQuestionTitle + "

"; summaryContentString += "

" + currQuestion + "

"; } else { summaryContentString += "

" + currQuestion + "

"; } if(testFeedback[i].questionType == "dragDrop"){ //Don't do anything but close the table cell and row summaryContentString += "