Kinetic.MultipleChoice = function(config){ Kinetic.Group.call(this, config); this.data = config.data; // check if multiple answers can be given var correctAnswers = this.data.correctAnswers; this.multipleAnswers = false; if (correctAnswers.length > 1){ this.multipleAnswers = true; } this.initExercise(); this.createExercise(); this.eventHandlers(); } Kinetic.MultipleChoice.prototype = { createExercise: function(){ // question var question = new Kinetic.Text({ 'y': 2, 'text': this.data.question, 'fontSize': 14, 'fontFamily': 'Arial', 'fill': '#000000', 'width': exerciseSettings.questionWidth }); this.add(question); // answers var answerData = this.data.answers; if (exerciseSettings.shuffleAnswers && eqSettings.forceShuffleAnswersOff != 1){ answerData = shuffleArray(answerData); } var yPos = question.getHeight() + 30; this.answers = new Array(); for (var i = 0; i < answerData.length; i++){ this.answers[i] = new Kinetic.MultipleChoiceAnswer({ 'data': answerData[i], 'y': yPos }); this.add(this.answers[i]); yPos += this.answers[i].label.getHeight(); } }, eventHandlers: function(){ var thisObject = this; for (var i = 0; i < this.answers.length; i++){ this.answers[i].hitzone.on("mouseup touchend", function(evt){ if (thisObject.multipleAnswers){ if (this.getParent().selected){ this.getParent().setUnselected(); } else { this.getParent().setSelected(); } } else { for (var j = 0; j < thisObject.answers.length; j++){ thisObject.answers[j].setUnselected(); } this.getParent().setSelected(); } }); this.answers[i].hitzone.on("mouseover", function(evt){ this.getParent().setMouseOver(); }); this.answers[i].hitzone.on("mouseout", function(evt){ if (typeof this.getParent() != 'undefined'){ this.getParent().setMouseOut(); } }); } }, checkAnswer: function(){ this.attempts -= 1; if (this.attempts == 0){ this.blockExercise(); } var correctAnswers = this.data.correctAnswers; this.correct = true; for (var i = 0; i < this.answers.length; i++){ var selected = this.answers[i].selected; if ($.inArray(this.answers[i].data.id, correctAnswers) != -1){ // right answer if (selected){ // mark correct if (eqSettings.mode == 'exercise'){ this.answers[i].setCorrect(); } } else { // mark forgot if (eqSettings.mode == 'exercise'){ this.answers[i].setForgot(); } this.correct = false; } } else { // wrong answer if (selected){ // mark wrong if (eqSettings.mode == 'exercise'){ this.answers[i].setWrong(); } this.correct = false; } } } this.showFeedback(this.correct, this.attempts); } } Kinetic.Util.extend(Kinetic.MultipleChoice, Kinetic.ExerciseType);