Dump from SVN

This commit is contained in:
Fándly Gergő
2019-08-08 16:43:21 +03:00
parent f96d5a49e9
commit c8973cda7e
34 changed files with 3703 additions and 0 deletions

10
script/chart.min.js vendored Normal file

File diff suppressed because one or more lines are too long

354
script/jquery.selection.js Normal file
View File

@ -0,0 +1,354 @@
/*!
* jQuery.selection - jQuery Plugin
*
* Copyright (c) 2010-2014 IWASAKI Koji (@madapaja).
* http://blog.madapaja.net/
* Under The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function($, win, doc) {
/**
* get caret status of the selection of the element
*
* @param {Element} element target DOM element
* @return {Object} return
* @return {String} return.text selected text
* @return {Number} return.start start position of the selection
* @return {Number} return.end end position of the selection
*/
var _getCaretInfo = function(element){
var res = {
text: '',
start: 0,
end: 0
};
if (!element.value) {
/* no value or empty string */
return res;
}
try {
if (win.getSelection) {
/* except IE */
res.start = element.selectionStart;
res.end = element.selectionEnd;
res.text = element.value.slice(res.start, res.end);
} else if (doc.selection) {
/* for IE */
element.focus();
var range = doc.selection.createRange(),
range2 = doc.body.createTextRange();
res.text = range.text;
try {
range2.moveToElementText(element);
range2.setEndPoint('StartToStart', range);
} catch (e) {
range2 = element.createTextRange();
range2.setEndPoint('StartToStart', range);
}
res.start = element.value.length - range2.text.length;
res.end = res.start + range.text.length;
}
} catch (e) {
/* give up */
}
return res;
};
/**
* caret operation for the element
* @type {Object}
*/
var _CaretOperation = {
/**
* get caret position
*
* @param {Element} element target element
* @return {Object} return
* @return {Number} return.start start position for the selection
* @return {Number} return.end end position for the selection
*/
getPos: function(element) {
var tmp = _getCaretInfo(element);
return {start: tmp.start, end: tmp.end};
},
/**
* set caret position
*
* @param {Element} element target element
* @param {Object} toRange caret position
* @param {Number} toRange.start start position for the selection
* @param {Number} toRange.end end position for the selection
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
setPos: function(element, toRange, caret) {
caret = this._caretMode(caret);
if (caret === 'start') {
toRange.end = toRange.start;
} else if (caret === 'end') {
toRange.start = toRange.end;
}
element.focus();
try {
if (element.createTextRange) {
var range = element.createTextRange();
if (win.navigator.userAgent.toLowerCase().indexOf("msie") >= 0) {
toRange.start = element.value.substr(0, toRange.start).replace(/\r/g, '').length;
toRange.end = element.value.substr(0, toRange.end).replace(/\r/g, '').length;
}
range.collapse(true);
range.moveStart('character', toRange.start);
range.moveEnd('character', toRange.end - toRange.start);
range.select();
} else if (element.setSelectionRange) {
element.setSelectionRange(toRange.start, toRange.end);
}
} catch (e) {
/* give up */
}
},
/**
* get selected text
*
* @param {Element} element target element
* @return {String} return selected text
*/
getText: function(element) {
return _getCaretInfo(element).text;
},
/**
* get caret mode
*
* @param {String} caret caret mode
* @return {String} return any of the following: "keep" | "start" | "end"
*/
_caretMode: function(caret) {
caret = caret || "keep";
if (caret === false) {
caret = 'end';
}
switch (caret) {
case 'keep':
case 'start':
case 'end':
break;
default:
caret = 'keep';
}
return caret;
},
/**
* replace selected text
*
* @param {Element} element target element
* @param {String} text replacement text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
replace: function(element, text, caret) {
var tmp = _getCaretInfo(element),
orig = element.value,
pos = $(element).scrollTop(),
range = {start: tmp.start, end: tmp.start + text.length};
element.value = orig.substr(0, tmp.start) + text + orig.substr(tmp.end);
$(element).scrollTop(pos);
this.setPos(element, range, caret);
},
/**
* insert before the selected text
*
* @param {Element} element target element
* @param {String} text insertion text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
insertBefore: function(element, text, caret) {
var tmp = _getCaretInfo(element),
orig = element.value,
pos = $(element).scrollTop(),
range = {start: tmp.start + text.length, end: tmp.end + text.length};
element.value = orig.substr(0, tmp.start) + text + orig.substr(tmp.start);
$(element).scrollTop(pos);
this.setPos(element, range, caret);
},
/**
* insert after the selected text
*
* @param {Element} element target element
* @param {String} text insertion text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
insertAfter: function(element, text, caret) {
var tmp = _getCaretInfo(element),
orig = element.value,
pos = $(element).scrollTop(),
range = {start: tmp.start, end: tmp.end};
element.value = orig.substr(0, tmp.end) + text + orig.substr(tmp.end);
$(element).scrollTop(pos);
this.setPos(element, range, caret);
}
};
/* add jQuery.selection */
$.extend({
/**
* get selected text on the window
*
* @param {String} mode selection mode: any of the following: "text" | "html"
* @return {String} return
*/
selection: function(mode) {
var getText = ((mode || 'text').toLowerCase() === 'text');
try {
if (win.getSelection) {
if (getText) {
// get text
return win.getSelection().toString();
} else {
// get html
var sel = win.getSelection(), range;
if (sel.getRangeAt) {
range = sel.getRangeAt(0);
} else {
range = doc.createRange();
range.setStart(sel.anchorNode, sel.anchorOffset);
range.setEnd(sel.focusNode, sel.focusOffset);
}
return $('<div></div>').append(range.cloneContents()).html();
}
} else if (doc.selection) {
if (getText) {
// get text
return doc.selection.createRange().text;
} else {
// get html
return doc.selection.createRange().htmlText;
}
}
} catch (e) {
/* give up */
}
return '';
}
});
/* add selection */
$.fn.extend({
selection: function(mode, opts) {
opts = opts || {};
switch (mode) {
/**
* selection('getPos')
* get caret position
*
* @return {Object} return
* @return {Number} return.start start position for the selection
* @return {Number} return.end end position for the selection
*/
case 'getPos':
return _CaretOperation.getPos(this[0]);
/**
* selection('setPos', opts)
* set caret position
*
* @param {Number} opts.start start position for the selection
* @param {Number} opts.end end position for the selection
*/
case 'setPos':
return this.each(function() {
_CaretOperation.setPos(this, opts);
});
/**
* selection('replace', opts)
* replace the selected text
*
* @param {String} opts.text replacement text
* @param {String} opts.caret caret mode: any of the following: "keep" | "start" | "end"
*/
case 'replace':
return this.each(function() {
_CaretOperation.replace(this, opts.text, opts.caret);
});
/**
* selection('insert', opts)
* insert before/after the selected text
*
* @param {String} opts.text insertion text
* @param {String} opts.caret caret mode: any of the following: "keep" | "start" | "end"
* @param {String} opts.mode insertion mode: any of the following: "before" | "after"
*/
case 'insert':
return this.each(function() {
if (opts.mode === 'before') {
_CaretOperation.insertBefore(this, opts.text, opts.caret);
} else {
_CaretOperation.insertAfter(this, opts.text, opts.caret);
}
});
/**
* selection('get')
* get selected text
*
* @return {String} return
*/
case 'get':
/* falls through */
default:
return _CaretOperation.getText(this[0]);
}
return this;
}
});
})(jQuery, window, window.document);

7
script/jsplumb.min.js vendored Normal file

File diff suppressed because one or more lines are too long

196
script/quizedit.js Normal file
View File

@ -0,0 +1,196 @@
/**
* /script/quizedit.js
* @version 1.9
* @desc Script file for creating and editing tests
* @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 appendNewField(type){
$("<div>"+$("#newPrototypes div[data-type="+type+"]").html()+"</div>").hide().appendTo($("#questions")).slideDown();
}
function removeField(el){
$(el).parent().slideUp(function(){
$(el).parent().remove();
});
}
function addNewAnswer(el){
$("<div>"+$(el).data("append")+"</div>").hide().appendTo($(el).parent().children("[name=answers]")).slideDown();
}
function toggleGoodAnswer(el){
if($(el).hasClass("fa-square")){
$(el).removeClass("fa-square").addClass("fa-check-square");
$(el).next().data("correct", "true");
}
else{
$(el).removeClass("fa-check-square").addClass("fa-square");
$(el).next().data("correct", "false");
}
}
function addNewFillInField(el){
$(el).parent().children("textarea").selection("insert", {text:"[]", mode:"before"});
$(el).parent().children("textarea").selection("insert", {text:"[/]", mode:"after"});
}
//map funcs
function loadMap(el){
var file=$(el).parent().children("input[type=file]")[0].files[0];
var fr=new FileReader();
fr.onload=function(){
loadMapCallback(el, fr.result);
};
fr.readAsDataURL(file);
}
function loadMapCallback(el, res){
$(el).parent().children("div").children("img").attr("src", res);
$(el).parent().children("input[name=map]").val(res);
}
function addNewMarker(el){
$(el).parent().children("div[name=mapArea]").css("cursor", "crosshair");
$(el).parent().children("div[name=mapArea]").on("click", function(e){
var x=Math.round(e.pageX-$(this).position().left)-7;
var y=Math.round(e.pageY-$(this).position().top)-7;
$("<i class=\"fa fa-circle\" style=\"position: absolute; top: "+y.toString()+"px; left: "+x.toString()+"px\" data-posx=\""+x.toString()+"\" data-posy=\""+y.toString()+"\" data-correct=\"false\" onclick=\"toggleGoodMarker(this)\"></i>").hide().appendTo($(el).parent().children("div[name=mapArea]").children("div[name=markers]")).fadeIn();
$(el).parent().children("div[name=mapArea]").css("cursor", "default");
$(el).parent().children("div[name=mapArea]").off();
});
}
function removeMarker(el){
$(el).parent().children("div[name=mapArea]").children("div[name=markers]").children("i").css("cursor", "crosshair");
$(el).parent().children("div[name=mapArea]").children("div[name=markers]").children("i").on("click", function(e){
$(this).fadeOut(function(){
$(this).remove();
});
$(el).parent().children("div[name=mapArea]").children("div[name=markers]").children("i").css("cursor", "default");
$(el).parent().children("div[name=mapArea]").children("div[name=markers]").children("i").off();
});
}
function toggleGoodMarker(el){
if($(el).hasClass("fa-circle")){
$(el).removeClass("fa-circle").addClass("fa-check-circle");
$(el).data("correct", "true");
}
else{
$(el).removeClass("fa-check-circle").addClass("fa-circle");
$(el).data("correct", "false");
}
}
//export, cancel
function resetNewQuizForm(){
if(confirm(lang.sure)){
$("#newquizcontainer").slideUp(function(){
$("#newquiz")[0].reset();
$("#questions").html("");
$("input[name=timeLimitPerTestVal]").css("display", "none");
$("input[name=timeLimitVal]").css("display", "none");
$("input[name=onlineTag]").css("display", "none");
$("#newquizcontainer").slideDown();
});
}
}
function exportQuiz(){
var exp={};
//general settings
exp.name=$("#newquiz #general input[name=name]").val();
exp.description=$("#newquiz #general textarea[name=description]").val();
exp.timeLimitPerTest=$("#newquiz #general input[name=timeLimitPerTest]").is(":checked")?$("#newquiz #general input[name=timeLimitPerTestVal]").val():-1;
exp.timeLimit=$("#newquiz #general input[name=timeLimit]").is(":checked")?$("#newquiz #general input[name=timeLimitVal]").val():-1;
var publish=$("#newquiz #general input[name=submitOnline]").is(":checked");
exp.questions=[];
//questions
$("#newquiz #questions").children("div").each(function(){
var q={};
q.type=$(this).children("input[name=type]").val();
if(q.type=="simpleQuestion"){
q.question=$(this).children("input[name=question]").val();
q.answer=$(this).children("input[name=answer]").val().toLowerCase();
}
else if(q.type=="simpleSelect"){
q.question=$(this).children("input[name=question]").val();
q.answers=[];
$(this).children("fieldset[name=answers]").children("div").each(function(){
var a={};
a.answer=$(this).children("input[name=answer]").val();
a.correct=($(this).children("input[name=answer]").data("correct")=="true")?true:false;
q.answers.push(a);
});
}
else if(q.type=="connectGraph"){
q.question=$(this).children("input[name=question]").val();
q.answers=[];
$(this).children("fieldset[name=answers]").children("div").each(function(){
var a={};
a.pair1=$(this).children("input[name=pair1]").val();
a.pair2=$(this).children("input[name=pair2]").val();
q.answers.push(a);
});
}
else if(q.type=="fillIn"){
q.question=$(this).children("input[name=question]").val();
q.text=$(this).children("textarea[name=text]").val();
}
else if(q.type=="markOnMap"){
q.question=$(this).children("input[name=question]").val();
q.map=$(this).children("input[name=map]").val();
q.markers=[];
$(this).children("div[name=mapArea]").children("div[name=markers]").children("i").each(function(){
var m={};
m.posx=$(this).data("posx");
m.posy=$(this).data("posy");
m.correct=($(this).data("correct")=="true")?true:false;
q.markers.push(m);
});
}
exp.questions.push(q);
});
var json=JSON.stringify(exp);
if(publish){
$.ajax({
url: "./engine/engine.php",
type: "POST",
data: {
"submitQuiz": json,
"submitQuiz_tag": $("#newquiz #general input[name=onlineTag]").val(),
"submitQuiz_name": $("#newquiz #general input[name=name]").val(),
"submitQuiz_description": $("#newquiz #general textarea[name=description]").val()
},
success: function(res){
alert(lang.availableAtURL+": "+res);
}
});
}
var send="text/json;charset=utf-8,"+encodeURIComponent(json);
$("<a href=\"data:"+send+"\" download=\""+exp.name+"_sQuiz.json\"></a>")[0].click();
}

279
script/resulttest.js Normal file
View File

@ -0,0 +1,279 @@
/**
* /script/resulttest.js
* @version 1.3
* @desc Script file for the result viewer page
* @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 showResSelector(){
$("#menuwrapper").slideDown();
$("#back").attr("onclick", "window.history.back()");
}
function resultFromFile(){
$("#back").attr("onclick", "$(\"#resFromFile\").slideUp(); showResSelector()");
$("#menuwrapper").slideUp();
$("#resFromFile").slideDown();
}
function resultFromId(){
$("#back").attr("onclick", "$(\"#resFromId\").slideUp(); showResSelector()");
$("#menuwrapper").slideUp();
$("#resFromId").slideDown();
}
function openResultFromFile(){
var file=$("input[name=resfile]")[0].files[0];
var fr=new FileReader();
fr.onload=function(){
openResultFromFileCallback(fr.result);
};
fr.readAsText(file, "utf-8");
//hide solvedBy
$("#quizDoneByHolder").css("display", "none");
}
function openResultFromFileCallback(file){
showResults(file);
$("#resFromFile").slideUp();
}
function openResultFromId(){
$.ajax({
url: "./engine/engine.php",
type: "GET",
data: {"getResult": $("input[name=testid]").val()},
success: function(response){
if(response!="not found"){
response=(response instanceof Object)?response:JSON.parse(response);
showResults(response.answered);
//show solvedBy
$("#quizDoneByHolder").css("display", "block");
$("#quizDoneBy").html(response.submitter);
//hide self
$("#resFromId").slideUp();
}
}
});
}
var chartCorrect=null;
var chartAnswers=null;
var chartTimeSpent=null;
var chartTimeSpentPie=null;
function showResults(results){
//show back button
$("#back").attr("onclick", "$(\"#analitycs\").slideUp(); showResSelector()");
var res=(results instanceof Object)?results:JSON.parse(results);
//process data
var correct=0;
var incorrect=0;
var totalTime=0;
var labels=[];
var correctArr=[];
var timeSpentArr=[];
var colorArr=[];
$.each(res.answers, function(key, val){
if(val.correct){
correct++;
}
else{
incorrect++;
}
totalTime+=val.timeElapsed;
labels.push((key+1).toString()+". "+lang.exercise);
correctArr.push(val.correct);
timeSpentArr.push(val.timeElapsed);
colorArr.push("rgb("+(Math.floor(Math.random()*255)).toString()+", "+(Math.floor(Math.random()*255)).toString()+", "+(Math.floor(Math.random()*255)).toString()+")");
});
//set quiz datas
$("#quizName").html(res.quizName);
$("#quizDesc").html(res.quizDesc);
var done=new Date(res.doneDate);
$("#quizDone").html(done.getFullYear().toString()+"-"+(done.getMonth()+1).toString()+"-"+done.getDate().toString()+" "+done.getHours().toString()+":"+done.getMinutes().toString()+":"+done.getSeconds().toString());
$("#quizTimeSpent").html(totalTime);
//
//show charts
//
//clear canvases
if(chartCorrect!=null){
chartCorrect.destroy();
chartAnswers.destroy();
chartTimeSpent.destroy();
chartTimeSpentPie.destroy();
}
//chartCorrect
chartCorrect=new Chart($("#chartCorrect"), {
type: "pie",
data: {
labels: [lang.correct, lang.incorrect],
datasets: [{
label: lang.answers,
backgroundColor: ["rgb(0, 255, 0)", "rgb(255, 0, 0)"],
data: [correct, incorrect]
}]
},
options: {
responsive: false,
title: {
display: true,
fontColor: "rgb(0, 0, 0)",
text: lang.answers
},
legend: {
labels: {
fontColor: "rgb(0, 0, 0)"
},
onClick: null
}
}
});
//chartAnswers
chartAnswers=new Chart($("#chartAnswers"), {
type: "bar",
data: {
labels: labels,
datasets: [{
label: lang.correct,
backgroundColor: "rgba(34,168,186,0.9)",
data: correctArr
}]
},
options: {
responsive: false,
title: {
display: true,
fontColor: "rgb(0, 0, 0)",
text: lang.correctAnswers
},
legend: {
labels: {
fontColor: "rgb(0, 0, 0)"
},
onClick: null
},
scales: {
xAxes: [{
gridLines: {
color: "rgb(0, 0, 0)"
},
ticks: {
fontColor: "rgb(0, 0, 0)"
}
}],
yAxes: [{
gridLines: {
color: "rgb(0, 0, 0)"
},
ticks: {
fontColor: "rgb(0, 0, 0)",
beginAtZero: true
}
}]
}
}
});
//chartTimeSpent
chartTimeSpent=new Chart($("#chartTimeSpent"), {
type: "line",
data: {
labels: labels,
datasets: [{
label: lang.timeSpent,
backgroundColor: "rgba(34,168,186,0.9)",
data: timeSpentArr,
lineTension: 0
}]
},
options: {
responsive: false,
title: {
display: true,
fontColor: "rgb(0, 0, 0)",
text: lang.timeSpent
},
legend: {
labels: {
fontColor: "rgb(0, 0, 0)"
},
onClick: null
},
scales: {
xAxes: [{
gridLines: {
color: "rgb(0, 0, 0)"
},
ticks: {
fontColor: "rgb(0, 0, 0)"
}
}],
yAxes: [{
gridLines: {
color: "rgb(0, 0, 0)"
},
ticks: {
fontColor: "rgb(0, 0, 0)",
beginAtZero: true
}
}]
}
}
});
//chartTimeSpentPie
chartTimeSpentPie=new Chart($("#chartTimeSpentPie"), {
type: "pie",
data: {
labels: labels,
datasets: [{
label: lang.timeSpend,
backgroundColor: colorArr,
data: timeSpentArr
}]
},
options: {
responsive: false,
title: {
display: true,
fontColor: "rgb(0, 0, 0)",
text: lang.timeSpent
},
legend: {
labels: {
fontColor: "rgb(0, 0, 0)"
},
onClick: null
}
}
});
//show container
$("#analitycs").slideDown();
}

15
script/sQuiz/lang.json Normal file
View File

@ -0,0 +1,15 @@
{
"downloadResults":"Download results",
"uploadResults":"Upload results",
"customAction":"Custom action name goes here",
"quizFinished":"Quiz finished!",
"resultsGot":"You've got the following results",
"yourname":"Your name",
"idForResult":"Share this ID with anybody you want to know your results",
"timeLeft":"Time left for entire quiz",
"timeLeftPerTest":"Time left for this question",
"submit":"Submit",
"nextQuestion":"Next question",
"startQuiz":"Start quiz",
"answer":"Answer"
}

290
script/sQuiz/sQuiz.js Normal file
View File

@ -0,0 +1,290 @@
/**
* /sQuiz/sQuiz.js
* @version 1.4
* @desc sQuiz main class file
* @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(element, quiz)
* @desc Creating a new quiz based on a json file
* @param $ element Container in which the quiz will be running
* @param string quiz A JSON string/JSON object containing an sQuiz parameter list
*/
$.sQuiz=function(element, quiz){
this.element=(element instanceof $)?element:$(element);
this.quiz=(typeof quiz=="object")?quiz:JSON.parse(quiz);
this.current=-1;
this.currentQustion;
this.reg;
this.countdown;
this.elapsedPerTest=(this.quiz.timeLimitPerTest>0)?0:-2;
this.elapsed=(this.quiz.timeLimit>0)?0:-2;
this.answers=[];
this.quizDoneCallback;
this.quizDoneOptions;
};
$.sQuiz.prototype={
/**
* sQuiz.setRegionalization(lang)
* @desc Assing an Object which has all the needed vars for language (startQuiz, timeRemaining, etc. Full list in /sQuiz/lang.json), or leave it on default for English
* @param object lang Object storing language settings
*/
setRegionalization: function(lang){
this.reg=lang;
},
/**
* sQuiz.setQuizDoneCallback(callback)
* @desc Assign a function to run when the quiz is finished
* @param function callback Function to call
*/
setQuizDoneCallback: function(callback){
this.quizDoneCallback=callback;
},
/**
* sQuiz.setQuizDoneOptions(options)
* @desc Set options to offer when quiz is finished. Set download to true, to offer downloading. Set upload to true, to offer online submit to upload_url. Set custom to a JS function call to do self made stuff. Custom action's label regionalization is customAction.
* @param object options Object containing the settings
*/
setQuizDoneOptions: function(options){
this.quizDoneOptions=options;
},
/**
* sQuiz.secToTime(sec)
* @desc Function for converting seconds to traditional MM:SS format
* @param int sec Seconds to convert
* @return string
*/
secToTime: function(sec){
var mins=Math.floor(sec/60);
var secs=sec%60;
var minstr=(mins.toString().length==1)?"0"+mins.toString():mins.toString();
var secstr=(secs.toString().length==1)?"0"+secs.toString():secs.toString();
var time=minstr+":"+secstr;
return time;
},
/**
* sQuiz.quizDone()
* @desc Function to call when a test is finished
*/
quizDone: function(){
var points=0;
$.each(this.answers, function(key, val){
if(val.correct){
points++;
}
});
var self=this;
this.element.slideUp(function(){
var buttons="<div class=\"sq sq-menu\">";
if(self.quizDoneOptions.download==true){
buttons+="<button class=\"sq sq-big\" type=\"button\" id=\"sqDownloadResults\"><i class=\"fa fa-save\"></i>"+self.reg.downloadResults+"</button>";
}
if(self.quizDoneOptions.upload==true){
buttons+="<button class=\"sq sq-big\" type=\"button=\" id=\"sqUploadResults\"><i class=\"fa fa-upload\"></i>"+self.reg.uploadResults+"</button>";
}
if(self.quizDoneOptions.custom!=undefined){
buttons+="<button class=\"sq sq-big\" type=\"button=\" id=\"sqCustomAction\" onclick=\""+self.quizDoneOptions.custom+"\">"+self.reg.customAction+"</button>";
}
buttons+="</div>";
self.element.html("<h2>"+self.reg.quizFinished+"</h2><hr class=\"sq sq-placeholder\" style=\"height: 10vh\"><div class=\"sq sq-center\"><h3>"+self.reg.resultsGot+": <b>"+points.toString()+"/"+self.quiz.questions.length+"</b></h3><br><br>"+buttons);
$("#sqDownloadResults").on("click", function(){
//store quiz name, description and done date in result file
var result={
"quizName": self.quiz.name,
"quizDesc": self.quiz.description,
"doneDate": Date.now(),
"answers": self.answers
};
var json=JSON.stringify(result);
var send="text/json;charset=utf-8,"+encodeURIComponent(json);
$("<a href=\"data:"+send+"\" download=\""+self.quiz.name+"_answers_sQuiz.json\"></a>")[0].click();
});
$("#sqUploadResults").on("click", function(){
var result={
"quizName": self.quiz.name,
"quizDesc": self.quiz.description,
"doneDate": Date.now(),
"answers": self.answers
};
var json=JSON.stringify(result);
var submitter=prompt(self.reg.yourname+":");
$.ajax({
url: (self.quizDoneOptions.upload_url!=undefined)?self.quizDoneOptions.upload_url:"",
type: "POST",
data: {
"submitResult": json,
"submitResult_submitter": submitter
},
success: function(res){
alert(self.reg.idForResult+": "+res);
}
});
});
self.element.slideDown();
});
var result={
"quizName": self.quiz.name,
"quizDesc": self.quiz.description,
"doneDate": Date.now(),
"answers": self.answers
};
if(this.quizDoneCallback!=undefined){
this.quizDoneCallback(result, this.quiz);
}
},
/**
* sQuiz.nextQuestion()
* @desc Start the next question. Should be called only internally!
*/
nextQuestion: function(){
var self=this;
this.current++;
if(this.current>=this.quiz.questions.length){
this.quizDone();
}
else{
var type=this.quiz.questions[this.current].type;
this.element.slideUp(function(){
var timer="<p id=\"sqTimer\">"+(self.quiz.timeLimit>0?"<b>"+self.reg.timeLeft+":</b> <span id=\"sqTimeLeft\"></span><br>":"")+(self.quiz.timeLimitPerTest>0?"<b>"+self.reg.timeLeftPerTest+":</b> <span id=\"sqTimeLeftPerTest\"></span>":"")+"</p>";
var submitbutton="<br><br><div class=\"sq sq-center\"><button class=\"sq green sq-big\" id=\"sqSubmitButton\"><i class=\"fa fa-check\"></i>"+self.reg.submit+"</button></div>";
self.element.html(timer+"<hr class=\"sq-placeholder\"><div id=\"sqTestArea\" style=\"overflow: auto\"></div>"+submitbutton);
self.element.children("#sqTimeLeft").html(self.secToTime(self.timeLimit));
self.element.children("#sqTimeLeftPerTest").html(self.secToTime(self.timeLimitPerTest));
self.currentQuestion=new $["sQuiz_module_"+type](self, self.quiz.questions[self.current]);
$("#sqSubmitButton").on("click", function(){
self.currentQuestion.submit();
$("#sqSubmitButton").unbind();
$("#sqSubmitButton").fadeOut(function(){
$(this).html("<i class=\"fa fa-arrow-right\"></i>"+self.reg.nextQuestion);
$(this).fadeIn();
});
$("#sqSubmitButton").on("click", function(){
self.nextQuestion();
});
});
self.currentQuestion.load();
self.element.slideDown(function(){
self.startTimer();
});
});
}
},
/**
* sQuiz.init()
* @desc set up styles and so for the container
*/
init: function(){
var self=this;
if(this.reg==undefined){
this.reg={
"downloadResults":"Download results",
"uploadResults":"Upload results",
"customAction":"Custom action name goes here",
"quizFinished":"Quiz finished!",
"resultsGot":"You've got the following results",
"yourname":"Your name",
"idForResult":"Share this ID with anybody you want to know your results",
"timeLeft":"Time left for entire quiz",
"timeLeftPerTest":"Time left for this question",
"submit":"Submit",
"nextQuestion":"Next question",
"startQuiz":"Start quiz",
"answer":"Answer"
};
}
this.element.hide();
this.element.addClass("sq sq-container");
this.element.html("<hr class=\"sq sq-placeholder\" style=\"height: 20vh\"><h2>"+this.quiz.name+"</h2><p>"+this.quiz.description+"</p><hr><div class=\"sq sq-center\"><button class=\"sq sq-big\" id=\"sqStart\">"+this.reg.startQuiz+"</button></div>");
$("#sqStart").on("click", function(){
self.nextQuestion();
});
this.element.slideDown();
},
/**
* sQuiz.startTimer
* @desc Starts the countdown
*/
startTimer: function(){
var self=this;
this.elapsedPerTest=0;
if(this.quiz.timeLimitPerTest>0 || this.quiz.timeLimit>0){
if(self.quiz.timeLimitPerTest>0){
self.elapsedPerTest++;
self.element.children("#sqTimer").children("#sqTimeLeftPerTest").html(self.secToTime(self.quiz.timeLimitPerTest-self.elapsedPerTest));
if(self.elapsedPerTest>=self.quiz.timeLimitPerTest){
$("#sqSubmitButton")[0].click();
}
}
if(self.quiz.timeLimit>0){
self.elapsed++;
self.element.children("#sqTimer").children("#sqTimeLeft").html(self.secToTime(self.quiz.timeLimit-self.elapsed));
if(self.elapsed>=self.quiz.timeLimit){
$("#sqSubmitButton")[0].click();
}
}
}
this.countdown=window.setInterval(function(self){
self.elapsedPerTest++;
if(self.quiz.timeLimitPerTest>0){
self.element.children("#sqTimer").children("#sqTimeLeftPerTest").html(self.secToTime(self.quiz.timeLimitPerTest-self.elapsedPerTest));
if(self.elapsedPerTest>=self.quiz.timeLimitPerTest){
$("#sqSubmitButton")[0].click();
}
}
if(self.quiz.timeLimit>0){
self.elapsed++;
self.element.children("#sqTimer").children("#sqTimeLeft").html(self.secToTime(self.quiz.timeLimit-self.elapsed));
if(self.elapsed>=self.quiz.timeLimit){
$("#sqSubmitButton")[0].click();
}
}
}, 1000, self);
},
/**
* sQuiz.stopTimer
* @desc Stops the countdown
*/
stopTimer: function(){
clearInterval(this.countdown);
}
}
}(jQuery));

View File

@ -0,0 +1,155 @@
/**
* /sQuiz/sQuiz_module_connectGraph.js
* @version 1.3
* @desc sQuiz class for connectGraphs
* @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_connectGraph=function(parent, quiz){
this.parent=parent;
this.quiz=quiz;
this.container=parent.element.children("#sqTestArea");
this.qidMap={};
this.currentlyClicked=null;
};
$.sQuiz_module_connectGraph.prototype={
submit: function(){
var self=this;
this.parent.stopTimer();
var sub={};
sub.answered=[];
sub.correct=true;
jsPlumb.reset();
$(this.container).children("div[data-qid=pair1]").children("i").each(function(){
if($(this).data("connectedTo")==undefined || $(this).data("connectedTo")=="--NULL--"){
sub.answered.push({pair1: $(this).data("value"), pair2: "null"});
$(this).addClass("sq-red");
sub.correct=false;
}
else{
for(var i=0; i<self.quiz.answers.length; i++){
if(self.quiz.answers[i].pair1==$(this).data("value")){
if(self.quiz.answers[i].pair2==$(this).data("connectedTo")){
$(this).addClass("sq-green");
self.container.children("div[data-qid=pair2]").children("i[data-value="+$(this).data("connectedTo")+"]").addClass("sq-green");
jsPlumb.connect({
source: $(this),
target: self.container.children("div[data-qid=pair2]").children("i[data-value="+$(this).data("connectedTo")+"]"),
anchor: "Center",
paintStyle: {
stroke: "rgba(74,230,74,0.9)",
strokeWidth: 10
},
endpoint: "Dot",
endpointStyle: {
fill: "rgba(74,230,74,0.9)",
radius: 12
},
detachable: false
});
}
else{
$(this).addClass("sq-red");
self.container.children("div[data-qid=pair2]").children("i[data-value=\""+$(this).data("connectedTo")+"\"]").addClass("sq-red");
jsPlumb.connect({
source: $(this),
target: self.container.children("div[data-qid=pair2]").children("i[data-value=\""+$(this).data("connectedTo")+"\"]"),
anchor: "Center",
paintStyle: {
stroke: "rgba(230,74,74,0.9)",
strokeWidth: 10
},
endpoint: "Dot",
endpointStyle: {
fill: "rgba(230,74,74,0.9)",
radius: 12
},
detachable: false
});
sub.correct=false;
}
sub.answered.push({pair: $(this).data("value"), pair2: $(this).data("connectedTo")});
break;
}
}
}
});
sub.timeElapsed=this.parent.elapsedPerTest;
this.parent.answers.push(sub);
},
load: function(){
var self=this;
jsPlumb.reset();
jsPlumb.setContainer(this.container);
var qid=0;
var pair1="";
var pair2="";
$.each(this.quiz.answers, function(key, val){
pair1+="<span style=\"font-size: 2em\">"+val.pair1+"</span> <i class=\"fa fa-circle fa-2x\" id=\"sqPoint"+qid.toString()+"\" data-qid=\""+qid.toString()+"\" data-value=\""+val.pair1+"\" data-connectedTo=\"--NULL--\"></i><br><br>";
qid++;
});
var qidp1=qid;
var p2=this.quiz.answers.slice();
while(p2.length>0){
var index=Math.floor(Math.random()*p2.length);
pair2+="<i class=\"fa fa-circle fa-2x\" id=\"sqPoint"+qid.toString()+"\" data-qid=\""+qid.toString()+"\" data-value=\""+p2[index].pair2+"\"></i> <span style=\"font-size: 2em\">"+p2[index].pair2+"</span><br><br>";
qid++;
p2.splice(index, 1);
}
this.container.html("<h2>"+this.quiz.question+"</h2><br><div data-qid=\"pair1\" style=\"float: left; text-align: right\">"+pair1+"</div><div data-qid=\"pair2\" style=\"float: right; text-align: left\">"+pair2+"</div>");
this.parent.element.slideDown(function(){
var typic={
anchor: "Center",
connectorStyle: {
stroke: "rgb(0,0,0)",
strokeWidth: 10
},
endpoint: "Dot",
endpointStyle: {
fill: "rgb(0,0,0)",
radius: 12
}
};
for(var i=0; i<qidp1; i++){
jsPlumb.addEndpoint("sqPoint"+i.toString(), {isSource: true, isTarget: false}, typic);
}
for(var i=qidp1; i<qid; i++){
jsPlumb.addEndpoint("sqPoint"+i.toString(), {isSource: false, isTarget: true}, typic);
}
jsPlumb.bind("connection", function(info){
$(info.source).data("connectedTo", $(info.target).data("value"));
});
jsPlumb.bind("connectionDetached", function(info){
$(info.source).data("connectedTo", "--NULL--");
});
});
}
};
}(jQuery));

View File

@ -0,0 +1,115 @@
/**
* /sQuiz/sQuiz_module_fillIn.js
* @version 1.0
* @desc sQuiz class for fillIns
* @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_fillIn=function(parent, quiz){
this.parent=parent;
this.quiz=quiz;
this.container=parent.element.children("#sqTestArea");
this.qidMap={};
this.answers=[];
};
$.sQuiz_module_fillIn.prototype={
submit: function(){
var self=this;
this.parent.stopTimer();
var sub={};
this.container.children("div[data-qid=fillers]").children("span[data-qid=filler]").draggable("disable");
sub.answered=[];
sub.correct=true;
var i=0;
this.container.children("p[data-qid=text]").children("span[data-qid=fillable]").each(function(){
if($(this).data("filledWith")==undefined || $(this).data("filledWith")=="--NULL--"){
sub.answered.push("null");
sub.correct=false;
self.container.children("div[data-qid=fillers]").children("span[data-qid=filler][data-attached=false]").addClass("red");
}
else{
if($(this).data("filledWith")==self.answers[i]){
$(this).data("attached").addClass("green");
}
else{
$(this).data("attached").addClass("red");
sub.correct=false;
}
sub.answered.push($(this).data("filledWith"));
}
i++;
});
sub.timeElapsed=this.parent.elapsedPerTest;
this.parent.answers.push(sub);
},
load: function(){
var qid=0;
var replacer="<span data-qid=\"fillable\" class=\"sq sq-droppable\" data-filledWith=\"--NULL--\"></span>"
var fillable=this.quiz.text;
fillable=fillable.replace(new RegExp(/[\n]/g), "<br>");
fillable=fillable.replace(new RegExp(/\[\][^\[\]]+\[\/\]/g), replacer);
var fillers=[];
var res;
var reg=new RegExp(/\[\]([^\[\]]+)\[\/\]/g);
while((res=reg.exec(this.quiz.text))!==null){
fillers.push("<span data-qid=\"filler\" data-value=\""+res[1]+"\" data-attached=\"false\" class=\"sq sq-draggable\">"+res[1]+"</span>");
this.answers.push(res[1]);
}
var fillerstr="";
while(fillers.length>0){
var index=Math.floor(Math.random()*fillers.length);
fillerstr+=fillers[index];
fillers.splice(index, 1);
}
this.container.html("<h2>"+this.quiz.question+"</h2><br><p data-qid=\"text\" style=\"font-size: 1.3em\">"+fillable+"</p><hr class=\"sq sq-placeholder\"><div data-qid=\"fillers\">"+fillerstr+"</div>");
//init drag 'n' drop
this.container.children("p[data-qid=text]").children("span[data-qid=fillable]").droppable({
tolerance: "pointer",
drop: function(event, ui){
ui.draggable.position({
of: $(this),
my: "left top",
at: "left top"
});
$(this).data("filledWith", ui.draggable.data("value"));
$(this).data("attached", ui.draggable);
ui.draggable.data("attached", "true");
},
out: function(event, ui){
$(this).data("filledWith", "--NULL--");
ui.draggable.data("attached", "false");
}
});
this.container.children("div[data-qid=fillers]").children("span[data-qid=filler]").draggable({
cursor: "move"
});
}
};
}(jQuery));

View File

@ -0,0 +1,88 @@
/**
* /sQuiz/sQuiz_module_markOnMap.js
* @version 1.2
* @desc sQuiz class for markOnMaps
* @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_markOnMap=function(parent, quiz){
this.parent=parent;
this.quiz=quiz;
this.container=parent.element.children("#sqTestArea");
this.qidMap={};
};
$.sQuiz_module_markOnMap.prototype={
submit: function(){
var self=this;
this.parent.stopTimer();
var sub={};
//unbind handlers
this.container.children("div[data-qid=mapArea]").children("div[data-qid=markers]").children("i[data-qid=marker]").off();
sub.answers=[];
sub.correct=true;
this.container.children("div[data-qid=mapArea]").children("div[data-qid=markers]").children("i[data-qid=marker]").each(function(){
for(var i=0; i<self.quiz.markers.length; i++){
if(self.quiz.markers[i].posx==$(this).data("posx") && self.quiz.markers[i].posy==$(this).data("posy")){
var selected=$(this).data("selected");
if(self.quiz.markers[i].correct==selected){
$(this).addClass("sq-green");
}
else{
$(this).addClass("sq-red");
sub.correct=false;
}
sub.answers.push({posx: $(this).data("posx"), posy: $(this).data("posy"), selected: selected});
}
}
});
sub.timeElapsed=this.parent.elapsedPerTest;
this.parent.answers.push(sub);
},
load: function(){
var map="<img src=\""+this.quiz.map+"\" alt=\"map to fill\">";
var markers="";
$.each(this.quiz.markers, function(key, val){
markers+="<i class=\"fa fa-circle\" style=\"position: absolute; top: "+val.posy.toString()+"px; left: "+val.posx.toString()+"px\" data-posx=\""+val.posx.toString()+"\" data-posy=\""+val.posy.toString()+"\" data-qid=\"marker\" data-selected=\"false\"></i>";
});
this.container.html("<h2>"+this.quiz.question+"</h2><br><div class=\"sq sq-center sq-mapArea\" data-qid=\"mapArea\">"+map+"<div data-qid=\"markers\">"+markers+"</div></div>");
this.container.children("div[data-qid=mapArea]").children("div[data-qid=markers]").children("i[data-qid=marker]").on("click", function(){
if($(this).data("selected")==false){
$(this).removeClass("fa-circle");
$(this).addClass("fa-check-circle");
$(this).data("selected", true);
}
else{
$(this).removeClass("fa-check-circle");
$(this).addClass("fa-circle");
$(this).data("selected", false);
}
});
}
};
}(jQuery));

View File

@ -0,0 +1,58 @@
/**
* /sQuiz/sQuiz_module_simpleQuestion.js
* @version 1.2
* @desc sQuiz class for simpleQuestions
* @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_simpleQuestion=function(parent, quiz){
this.parent=parent;
this.quiz=quiz;
this.container=parent.element.children("#sqTestArea");
this.qidMap={};
};
$.sQuiz_module_simpleQuestion.prototype={
submit: function(){
var self=this;
this.parent.stopTimer();
var sub={};
sub.answered=this.container.children("input[data-qid="+this.qidMap["answer"]+"]").val();
if(sub.answered.toLowerCase()==this.quiz.answer){
this.container.children("input[data-qid="+this.qidMap["answer"]+"]").addClass("sq-green");
sub.correct=true;
}
else{
this.container.children("input[data-qid="+this.qidMap["answer"]+"]").addClass("sq-red");
sub.correct=false;
}
sub.timeElapsed=this.parent.elapsedPerTest;
this.parent.answers.push(sub);
},
load: function(){
var qid=0;
this.container.html("<h2>"+this.quiz.question+"</h2><br><p>"+this.parent.reg.answer+":</p><input type=\"text\" class=\"sq\" data-qid=\""+qid.toString()+"\" placeholder=\""+this.parent.reg.answer+"...\">");
this.qidMap["answer"]=qid;
$("input[data-qid="+this.qidMap["answer"]+"]").focus();
}
};
}(jQuery));

View File

@ -0,0 +1,81 @@
/**
* /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.timeElapsed=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));

View File

@ -0,0 +1,137 @@
/**
* /sQuiz/style/sQuiz.css
* @version 1.1
* @desc Style file for sQuiz
* @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/>.
**/
.sq.sq-container{
margin: auto;
background: rgba(34,168,186,0.7);
padding: 1em;
border-radius: 0.5em;
border: 1px solid rgba(28,157,175,0.9);
width: 95%;
}
.sq.sq-center{
margin: auto;
text-align: center;
}
hr.sq.sq-placeholder{
border: none;
height: 30px;
}
div.sq.sq-mapArea{
position: relative;
width: fit-content;
}
div.sq.sq-mapArea div{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
button.sq{
background: rgba(34,168,186,0.9);
padding: 1em;
border-radius: 0.5em;
border: 1px solid rgba(28,157,175,0.9);
}
button.sq:hover{
background: rgba(24,148,165,0.9);
}
button.sq.sq-big{
font-size: 3em;
padding: 1em;
padding-top: 4em;
padding-bottom: 4em;
width: 9em;
}
button.sq.red{
background: rgba(230,74,74,0.9);
border: 1px solid rgba(187,48,48,0.9);
}
button.sq.red:hover{
background: rgba(200,54,54,0.9);
}
button.sq.green{
background: rgba(74,230,74,0.9);
border: 1px solid rgba(48,487,48,0.9);
}
button.sq.green:hover{
background: rgba(54,200,54,0.9);
}
input.sq{
border-radius: 5px;
padding: 0.5em;
border: 1px solid rgba(28,157,175,0.9);
width: 90%;
font-size: 2em;
}
.sq-red{
color: rgba(230,74,74,0.9);
}
.sq-green{
color: rgba(74,230,74,0.9);
}
span.sq.sq-draggable{
height: 1.3em;
width: 10em;
padding: 0.5em;
margin: 1em;
overflow: auto;
cursor: move;
color: rgb(255,255,255);
background: rgb(130,130,130);
display: inline-block;
font-size: 1.3em;
border-radius: 0.3em;
}
span.sq.sq-draggable.red{
background: rgba(230,74,74,0.9);
}
span.sq.sq-draggable.green{
background: rgba(74,230,74,0.9);
}
span.sq.sq-droppable{
height: 2em;
width: 10.7em;
margin: 0 0.3em;
overflow: auto;
color: rgb(255,255,255);
border: 3px dashed rgb(130,130,130);
display: inline-block;
border-radius: 0.3em;
}
div.sq.sq-menu{
display: flex;
justify-content: space-around;
flex-wrap: wrap;
width: 99%;
}

163
script/screenfull.js Normal file
View File

@ -0,0 +1,163 @@
(function () {
'use strict';
var document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {};
var isCommonjs = typeof module !== 'undefined' && module.exports;
var keyboardAllowed = typeof Element !== 'undefined' && 'ALLOW_KEYBOARD_INPUT' in Element;
var fn = (function () {
var val;
var fnMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenElement',
'fullscreenEnabled',
'fullscreenchange',
'fullscreenerror'
],
// New WebKit
[
'webkitRequestFullscreen',
'webkitExitFullscreen',
'webkitFullscreenElement',
'webkitFullscreenEnabled',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
// Old WebKit (Safari 5.1)
[
'webkitRequestFullScreen',
'webkitCancelFullScreen',
'webkitCurrentFullScreenElement',
'webkitCancelFullScreen',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
[
'mozRequestFullScreen',
'mozCancelFullScreen',
'mozFullScreenElement',
'mozFullScreenEnabled',
'mozfullscreenchange',
'mozfullscreenerror'
],
[
'msRequestFullscreen',
'msExitFullscreen',
'msFullscreenElement',
'msFullscreenEnabled',
'MSFullscreenChange',
'MSFullscreenError'
]
];
var i = 0;
var l = fnMap.length;
var ret = {};
for (; i < l; i++) {
val = fnMap[i];
if (val && val[1] in document) {
for (i = 0; i < val.length; i++) {
ret[fnMap[0][i]] = val[i];
}
return ret;
}
}
return false;
})();
var eventNameMap = {
change: fn.fullscreenchange,
error: fn.fullscreenerror
};
var screenfull = {
request: function (elem) {
var request = fn.requestFullscreen;
elem = elem || document.documentElement;
// Work around Safari 5.1 bug: reports support for
// keyboard in fullscreen even though it doesn't.
// Browser sniffing, since the alternative with
// setTimeout is even worse.
if (/ Version\/5\.1(?:\.\d+)? Safari\//.test(navigator.userAgent)) {
elem[request]();
} else {
elem[request](keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT);
}
},
exit: function () {
document[fn.exitFullscreen]();
},
toggle: function (elem) {
if (this.isFullscreen) {
this.exit();
} else {
this.request(elem);
}
},
onchange: function (callback) {
this.on('change', callback);
},
onerror: function (callback) {
this.on('error', callback);
},
on: function (event, callback) {
var eventName = eventNameMap[event];
if (eventName) {
document.addEventListener(eventName, callback, false);
}
},
off: function (event, callback) {
var eventName = eventNameMap[event];
if (eventName) {
document.removeEventListener(eventName, callback, false);
}
},
raw: fn
};
if (!fn) {
if (isCommonjs) {
module.exports = false;
} else {
window.screenfull = false;
}
return;
}
Object.defineProperties(screenfull, {
isFullscreen: {
get: function () {
return Boolean(document[fn.fullscreenElement]);
}
},
element: {
enumerable: true,
get: function () {
return document[fn.fullscreenElement];
}
},
enabled: {
enumerable: true,
get: function () {
// Coerce to boolean in case of old WebKit
return Boolean(document[fn.fullscreenEnabled]);
}
}
});
if (isCommonjs) {
module.exports = screenfull;
} else {
window.screenfull = screenfull;
}
})();

92
script/script.js Normal file
View File

@ -0,0 +1,92 @@
/**
* /script/script.js
* @version 1.6
* @desc Main script file
* @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/>.
**/
//load language
var lang;
function loadLang(){
$.each(lang, function(key, val) {
var repl=$("title").html().replace(new RegExp("{{"+key+"}}", "g"), val);
$("title").html(repl);
repl=$("body").html().replace(new RegExp("{{"+key+"}}", "g"), val);
$("body").html(repl);
window.cookieconsent_options={
message: lang.cookie_message,
dismiss: lang.cookie_dismiss,
};
});
}
//switch pages
function goTo(site, pop=false){
Site=site;
//slide up
$("#content").slideUp(function(){
//load part
$.ajax({
url: "./"+site,
type: "GET",
success: function(response){
$("#content").html(response);
if(!pop){
window.history.pushState({"site": site}, null, "./");
}
},
complete: function(){
loadLang();
$("#content").slideDown();
}
});
});
}
//toggle element visibility
function toggleElement(sel){
sel=(sel instanceof $)?sel:$(sel);
if(sel.css("display")=="none"){
sel.slideDown();
}
else{
sel.slideUp();
}
}
//load
$(document).ready(function(){
$.getJSON("lang.json", function(json){
lang=json;
loadLang();
});
window.addEventListener("popstate", function(e){
if(e.state!=null){
goTo(e.state["site"], true);
}
else{
goTo("indexc.html", true);
}
});
});

132
script/tester.js Normal file
View File

@ -0,0 +1,132 @@
/**
* /script/tester.js
* @version 1.3
* @desc Script file for the tester page (not the actual sQuizEngine yet. :P)
* @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 showSelector(){
$("#list").slideUp();
$("#fromfile").slideUp();
$("#fromurl").slideUp();
$("#sQuiz").slideUp();
$("#menuwrapper").slideDown();
$("#back").attr("onclick", "window.history.back()");
}
function loadFromList(){
$("#back").attr("onclick", "showSelector()");
$("#menuwrapper").slideUp();
$.getJSON("./tests/main.json", function(json){
var list;
if(!json.locallist){
//get list from server
$.getJSON("./engine/engine.php?list", function(json){
list=json;
$("#listcontent").html("");
$.each(list, function(key, val){
var push="<tr>";
push+="<td>"+(parseInt(key)+1).toString()+"</td>";
push+="<td>"+val.name+"</td>";
push+="<td>"+val.description+"</td>";
push+="<td><button type=\"button\" onclick=\"startQuiz('"+val.file+"')\">"+lang.solve+"</td>";
push+="</tr>";
$("#listcontent").append(push);
});
$("#list table").footable();
$("#list").slideDown();
});
}
else{
//get list from locallist
list=json.available;
$("#listcontent").html("");
$.each(list, function(key, val){
var push="<tr>";
push+="<td>"+(parseInt(key)+1).toString()+"</td>";
push+="<td>"+val.name+"</td>";
push+="<td>"+val.description+"</td>";
push+="<td><button type=\"button\" onclick=\"startQuiz('"+val.file+"')\">"+lang.solve+"</td>";
push+="</tr>";
$("#listcontent").append(push);
});
$("#list table").footable();
$("#list").slideDown();
}
});
}
function loadFromFile(){
$("#back").attr("onclick", "showSelector()");
$("#menuwrapper").slideUp();
$("#fromfile").slideDown();
}
function loadFromURL(){
$("#back").attr("onclick", "showSelector()");
$("#menuwrapper").slideUp();
$("#fromurl").slideDown();
}
function openQuizFromFile(){
var file=$("#fromfile").children("input[type=file]")[0].files[0];
var fr=new FileReader();
fr.onload=function(){
openQuizFromFileCallback(fr.result);
};
fr.readAsText(file, "utf-8");
}
function openQuizFromFileCallback(res){
$("#fromfile").slideUp();
startQuizStr(res);
}
function openQuizFromURL(){
$("#fromurl").slideUp();
startQuiz($("input[name=testurl]").val());
}
//load quiz
function startQuiz(path){
$("#menuwrapper").slideUp();
$("#list").slideUp();
var sQuiz;
$.ajax({
url: path,
type: "GET",
success: function(res){
startQuizStr(res);
}
});
}
function startQuizStr(quizstr){
sQuiz=new $.sQuiz($("#sQuiz"), quizstr);
sQuiz.setRegionalization(lang);
sQuiz.setQuizDoneCallback(function(res, quiz){
console.log(res);
});
sQuiz.setQuizDoneOptions({
download: true,
upload: true,
upload_url: "./engine/engine.php"
});
sQuiz.init();
}