From 11bd302697f677b018a90fa9b188101aaa41dfa4 Mon Sep 17 00:00:00 2001 From: Jasen Hall Date: Sun, 8 Mar 2015 05:34:59 -0700 Subject: [PATCH 1/2] Now able to insert Project: Awesome questions in exams. --- html/startAdvanced.html | 1 + js/exam.js | 18 ++++++++++++++++++ js/quiz.js | 5 +++-- 3 files changed, 22 insertions(+), 2 deletions(-) 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..0c2d52f 100644 --- a/js/exam.js +++ b/js/exam.js @@ -84,6 +84,24 @@ $(document.body).ready(function () { var startExamNum = parseInt(url.param("start")); var examCount = parseInt(url.param("count")); + $(".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(startExamNum, quizJson); + + $(this).html((showPts ? ptsString : "") + quiz.formatQuestionsHTML() + "
" + quiz.formatAnswersHTML()); + }); + $(".showAnswerKey").click(function(){ ec.showAnswerKey(); }); diff --git a/js/quiz.js b/js/quiz.js index 80cdee0..be18529 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; } From 2aec87d836c746fae23ba32c8c8032d8c6e7b293 Mon Sep 17 00:00:00 2001 From: Jasen Hall Date: Tue, 10 Mar 2015 23:06:57 -0700 Subject: [PATCH 2/2] Added Awesome and HTML-type question insertion. HTML is only half complete. --- js/exam.js | 97 +++++++++++++++++++++++++++++++++++++++++++++++------- js/quiz.js | 2 +- 2 files changed, 87 insertions(+), 12 deletions(-) diff --git a/js/exam.js b/js/exam.js index 0c2d52f..8b3ebd4 100644 --- a/js/exam.js +++ b/js/exam.js @@ -1,3 +1,5 @@ +var QUESTION_COUNT = 1; + function ExamContext() { this.answerKeyVisible = true; @@ -74,16 +76,8 @@ function ExamContext() { } - -$(document.body).ready(function () { - - var ec = new ExamContext(); - - var url = purl(); //Parse the current URL using the purl library - - var startExamNum = parseInt(url.param("start")); - var examCount = parseInt(url.param("count")); - +function updateAwesomeQuestions(seed) +{ $(".pa-question").each( function() { var pa_params = $(this).data("pa-params"); pa_params = pa_params.replace(/'/g, '"'); @@ -97,11 +91,92 @@ $(document.body).ready(function () { } var quizJson = JSON.parse(pa_params); - var quiz = new Quiz(startExamNum, quizJson); + 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 () { + + var ec = new ExamContext(); + + var url = purl(); //Parse the current URL using the purl library + + 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 be18529..67921d0 100755 --- a/js/quiz.js +++ b/js/quiz.js @@ -23,7 +23,7 @@ var Quiz = 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; }