diff --git a/html/startAdvanced.html b/html/startAdvanced.html index ded050c..2c387b0 100755 --- a/html/startAdvanced.html +++ b/html/startAdvanced.html @@ -130,6 +130,7 @@

Set up your quiz:

quizObject.title = $("#quizTitle").val(); quizObject.quiz = quiz; var jsonString = JSON.stringify(quizObject); + jsonString = jsonString.replace(/"/g, "'"); $("#jsontextarea").val(jsonString); } diff --git a/js/exam.js b/js/exam.js index f2597b4..8b3ebd4 100644 --- a/js/exam.js +++ b/js/exam.js @@ -1,3 +1,5 @@ +var QUESTION_COUNT = 1; + function ExamContext() { this.answerKeyVisible = true; @@ -74,6 +76,90 @@ function ExamContext() { } +function updateAwesomeQuestions(seed) +{ + $(".pa-question").each( function() { + var pa_params = $(this).data("pa-params"); + pa_params = pa_params.replace(/'/g, '"'); + var showPts = true; //$(this).data("pa-showPts") == "true"; TODO: don't hardcode true, figure out who comparison failing + var pts = $(this).data("pa-pts"); + var ptsString = null; + + if(showPts) + { + ptsString = "(" + pts + (pts == "1" ? "pt" : "pts") + ")"; + } + + var quizJson = JSON.parse(pa_params); + var quiz = new Quiz(seed, quizJson); + + $(this).html((showPts ? ptsString : "") + quiz.formatQuestionsHTML() + "
" + quiz.formatAnswersHTML()); + }); + +} + +// data-pa-params="{'version':0.1,'title':'beef','quiz':[{'question':'cppBooleanEval','repeat':'1'}]}" +function makeQuestionJsonString(questionType) +{ + var questionObject = "[{'question':'" + questionType + "','repeat':'1'}]"; + var qStr = "{'version':0.1,'title':'Awesome Question','quiz':" + questionObject + "}"; + + return qStr; +} + +function insertHtmlQuestion()//li, ta) +{ + console.log("Button beep"); + //$(li).html($(ta).value()); +} + +function addHtmlQuestion() +{ + $(".theQuestions").append('
  • '); + + $(".html-question" + QUESTION_COUNT).html( + "
    " + + "" + ); + + var b = $(".button-html-question" + QUESTION_COUNT); + if(b === []) + { + console.log("Couldn't find the button."); + } + //.click(insertHtmlQuestion); + // function() { + // var liId = '#html-question' + QUESTION_COUNT; + // var taId = '#textarea-html-question' + QUESTION_COUNT; + // insertHtmlQuestion(liId, taId); + //}); + + QUESTION_COUNT++; +} + +function addAwesomeQuestion() +{ + var url = purl(); //Parse the current URL using the purl library + var seed = parseInt(url.param("start")); + + var qJsonString = makeQuestionJsonString($('#awesomeQuestionType').val()); + $(".theQuestions").append('
  • '); + + qJsonString = qJsonString.replace(/'/g, '"'); + var qJson = JSON.parse(qJsonString); + var question = new Quiz(seed, qJson); + + $(".pa-question" + (QUESTION_COUNT++)).html("(10 pst) " + question.formatQuestionsHTML() + "
    " + question.formatAnswersHTML()); +} + +function showHideAnswers() +{ + $(".pa-question-answer").each( function() + { + $(this).toggle(); + }); +} + $(document.body).ready(function () { @@ -84,6 +170,13 @@ $(document.body).ready(function () { var startExamNum = parseInt(url.param("start")); var examCount = parseInt(url.param("count")); + addOptionForEachQuestionType($("#awesomeQuestionType")); + //updateAwesomeQuestions(startExamNum); + + $("#htmlQuestionButton").click(addHtmlQuestion); + $("#awesomeQuestionButton").click(addAwesomeQuestion); + $("#showHideKey").click(showHideAnswers); + $(".showAnswerKey").click(function(){ ec.showAnswerKey(); }); diff --git a/js/quiz.js b/js/quiz.js index 80cdee0..67921d0 100755 --- a/js/quiz.js +++ b/js/quiz.js @@ -1,6 +1,6 @@ //quiz.js -- handles the generation of the Quiz from a QuizDescriptor and a Seed, //and the rendering of it as HTML -function Quiz(seed,quizDescriptor) +var Quiz = function Quiz(seed,quizDescriptor) { this.seed = seed; this.jsonObject = quizDescriptor; @@ -14,7 +14,8 @@ function Quiz(seed,quizDescriptor) this.formatQuestionsHTML = function() { var text = ""; for(var i=0; i" + this.questions[i].formatQuestion("HTML") + "
    "; + // text += "

    Question " + (i+1) + ":

    " + this.questions[i].formatQuestion("HTML") + "
    "; TODO: modified to use Awesome questions in exams + text += this.questions[i].formatQuestion("HTML") + "
    "; return text; } @@ -22,7 +23,7 @@ function Quiz(seed,quizDescriptor) this.formatAnswersHTML = function() { var text = ""; for(var i=0; i" + this.questions[i].formatAnswer("HTML") + "
    "; + text += "
    Answer " + this.questions[i].formatAnswer("HTML") + "
    "; return text; }