torierettsegifelkeszito/include/sQuiz/sQuiz_module_simpleSelect.js
2019-08-08 16:56:20 +03:00

82 lines
3.0 KiB
JavaScript

/**
* /sQuiz/sQuiz_module_simpleSelect.js
* @version 1.3
* @desc sQuiz class for simpleSelects
* @author Fándly Gergő Zoltán (gergo@systemtest.tk, systemtest.tk)
* @copy 2017 Fándly Gergő Zoltán
* License:
sQuiz for creating small jQuery based quizs in an implementable way
Copyright (C) 2017 Fándly Gergő Zoltán
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
**/
(function($){
$.sQuiz_module_simpleSelect=function(parent, quiz){
this.parent=parent;
this.quiz=quiz;
this.container=parent.element.children("#sqTestArea");
this.qidMap={};
};
$.sQuiz_module_simpleSelect.prototype={
submit: function(){
var self=this;
this.parent.stopTimer();
this.container.children("i").off();
var sub={};
sub.answered=[];
sub.correct=true;
this.container.children("i").each(function(index){
var checked=($(this).data("checked")=="true")?true:false;
if(checked==self.quiz.answers[index].correct){
$(this).addClass("sq-green");
}
else{
sub.correct=false;
$(this).addClass("sq-red");
}
sub.answered.push(checked);
});
sub.elapsed=this.parent.elapsedPerTest;
this.parent.answers.push(sub);
},
load: function(){
var qid=0;
var answers="";
$.each(this.quiz.answers, function(key, val){
answers+="<i class=\"fa fa-square fa-2x\" data-qid=\""+qid.toString+"\" data-checked=\"false\"></i> <span style=\"font-size: 2em\">"+val.answer+"</span><br><br>";
qid++;
});
this.container.html("<h2>"+this.quiz.question+"</h2><br>"+answers);
this.container.children("i").on("click", function(){
if($(this).hasClass("fa-square")){
$(this).removeClass("fa-square");
$(this).addClass("fa-check-square");
$(this).data("checked", "true");
}
else{
$(this).removeClass("fa-check-square");
$(this).addClass("fa-square");
$(this).data("checked", "false");
}
});
}
};
}(jQuery));