Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registerMode('multiple-choice', {
- validate: true,
- validateAnswer: function(question){
- var correctAnswers = 0;
- var wrongAnswers = 0;
- $('#question').find('.answers .answer').each(function() {
- $(this).off('click');
- var answer_id = $(this).attr('data-answer-id');
- var selected = $(this).hasClass('active');
- if((question.answers[answer_id].correct && selected) || (!question.answers[answer_id].correct && !selected)) {
- correctAnswers++;
- } else {
- wrongAnswers++;
- }
- if(question.answers[answer_id].correct) {
- $(this).addClass('correct');
- } else {
- $(this).addClass('wrong');
- }
- });
- var correct = wrongAnswers === 0 && correctAnswers > 0;
- if(correct) {
- $("#site .meta").removeClass("wrong");
- $("#site .meta").addClass("correct");
- } else {
- $("#site .meta").removeClass("correct");
- $("#site .meta").addClass("wrong");
- $("#check").removeClass("shake");
- setTimeout( function(){$("#check").addClass("shake");}, 100);
- }
- showHint(false);
- $("#check").unbind( "click" );
- $("#check").text("Weiter");
- $("#check").on("click", function(e){
- next();
- });
- return correct;
- },
- loadQuestion: function(question){
- var editArea = $('.meta #edit');
- var checkButton = $('#check');
- var questionContainer = $('#question');
- var hintContainer = $('#hint');
- var answersContainer = questionContainer.find('.answers');
- if(question.edit_url) {
- editArea.attr('href', question.edit_url);
- editArea.show();
- } else {
- editArea.hide();
- }
- checkButton.unbind( "click" );
- checkButton.text("Überprüfen");
- checkButton.on("click", function(){
- check();
- });
- questionContainer.find('.question').html(question.question);
- answersContainer.html('');
- hintContainer.fadeOut(0);
- hintContainer.html(question.hint);
- for(var i = 0; i < question.answers.length; i++) {
- var answer = question.answers[i];
- answersContainer.append('<div class="answer choice" data-answer-id="' + i +'"><div class="tick"></div>'+ answer.answer +'</div>');
- }
- questionContainer.find('.answers .answer').on('click',function() {
- $(this).toggleClass('active');
- });
- },
- init: function() {
- $('#hint-link').on('click',function() {
- if(window.lives > 0) {
- showHint(true);
- } else {
- alert("Du hast nicht genug Herzen, um einen Hinweis zur Hilfe anzeigen zu lassen.");
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement