From 0623eae79fef8f09cd1b5e16c3bde9b974afb7b8 Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Tue, 8 Jan 2013 08:14:47 +0100 Subject: [PATCH 01/54] Initial empty files --- content.json | 0 js/questionset.js | 0 library.json | 0 schema.json | 0 views/questionset.ejs | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 content.json create mode 100644 js/questionset.js create mode 100644 library.json create mode 100644 schema.json create mode 100644 views/questionset.ejs diff --git a/content.json b/content.json new file mode 100644 index 0000000..e69de29 diff --git a/js/questionset.js b/js/questionset.js new file mode 100644 index 0000000..e69de29 diff --git a/library.json b/library.json new file mode 100644 index 0000000..e69de29 diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..e69de29 diff --git a/views/questionset.ejs b/views/questionset.ejs new file mode 100644 index 0000000..e69de29 From ae4040f27a4649c5a6b33bc38417b939a389558e Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Tue, 8 Jan 2013 13:04:15 +0100 Subject: [PATCH 02/54] First working version of QuestionSet --- js/questionset.js | 136 ++++++++++++++++++++++++++++++++++++++++++ schema.json | 35 +++++++++++ views/questionset.ejs | 25 ++++++++ 3 files changed, 196 insertions(+) diff --git a/js/questionset.js b/js/questionset.js index e69de29..93e7d0b 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -0,0 +1,136 @@ +// Will render a Question with multiple choices for answers. + +// Options format: +// { +// title: "Optional title for question box", +// question: "Question text", +// answers: [{text: "Answer text", correct: false}, ...], +// singleAnswer: true, // or false, will change rendered output slightly. +// } +window.H5P = window.H5P || {}; + +H5P.QuestionSet = function (options) { + if ( !(this instanceof H5P.QuestionSet) ) + return new H5P.QuestionSet(options); + + var texttemplate = '' + +'
' + +'

<%= title %>

' + +' <% for (var i=0; i' + +'
' + +'

<%= questions[i].machineName %>

' + +'
' + +' <% } %>' + +' ' + +'
' + + ''; + + var defaults = { + title: "", + randomOrder: false, + initialQuestion: 0, + progressType: 'textual', + questions: [] + }; + + var template = new EJS({text: texttemplate}); + var params = jQuery.extend({}, defaults, options); + + var currentQuestion = -1; + var questionInstances = new Array(); + var allQuestionsAnswered = false; + var myDom; + + if (params.randomOrder) { + // TODO: Randomize order of questions + console.log("TODO: Randomize order of questions"); + } + + var _showQuestion = function (questionNumber) { + // Sanitize input. + if (questionNumber < 0) { questionNumber = 0; } + if (questionNumber >= params.questions.length) { questionNumber = params.questions.length - 1; } + + $('.prev.button', myDom).attr({'disabled': (questionNumber === 0)}); + $('.next.button', myDom).attr({'disabled': (questionNumber == params.questions.length-1)}); + + // Hide all questions + $('.question', myDom).hide(); + + // Reshow the requested question + $('#q-' + questionNumber, myDom).show(); + + // Update progress indicator + // Test if current has been answered. + if (params.progressType == 'textual') { + $('.progress-current', myDom).text("" + (questionNumber+1)); + } else { + $('.progress-dot.current', myDom).removeClass('current'); + // Set answered/unanswered for current. + $('#qdot-' + questionNumber, myDom).addClass('current'); + } + + // Remember where we are + currentQuestion = questionNumber; + return currentQuestion; + }; + + // Function for attaching the multichoice to a DOM element. + var attach = function (targetId) { + // Render own DOM into target. + template.update(targetId, params); + myDom = jQuery('#' + targetId); + + // Attach questions + for (var i=0; i= 0; i--) { + score += questionInstances[i].getScore(); + } + return score; + }; + + return { + attach: attach, // Attach to DOM object + getQuestions: function () {return questionInstances;}, + getScore: getScore, + defaults: defaults // Provide defaults for inspection + }; +}; diff --git a/schema.json b/schema.json index e69de29..63026ba 100644 --- a/schema.json +++ b/schema.json @@ -0,0 +1,35 @@ +{ + "title": { + "name": "Title", + "description": "Question set title (optional)", + "type": "text", + "default": "" + }, + "randomOrder": { + "name": "Randomize order", + "description": "Whether questions should be shown in random order", + "type": "boolean", + "default": false + }, + "initialQuestion": { + "name": "Initial question", + "description": "Which question to start with. Count from 0", + "type": "integer", + "default": 0 + }, + "progressType": { + "name": "Progress indicator", + "description": "Question set progress indicator style", + "type": "select", + "values": [{"text": "Textual", "value": "textual"}, {"text": "Dots", "value": "dots"}], + "default": "textual" + }, + "questions": { + "name": "Questions", + "description": "List of questions in this set.", + "type": "h5p-library", + "array": true, + "minEntries": 1, + "maxEntries": -1 + } +} diff --git a/views/questionset.ejs b/views/questionset.ejs index e69de29..a9c19b4 100644 --- a/views/questionset.ejs +++ b/views/questionset.ejs @@ -0,0 +1,25 @@ +
+

<%= title %>

+ <% for (var i=0; i +
+

<%= questions[i].machineName %>

+
+ <% } %> + +
From 37a7d54fbf851cad4219fdab9c6d228bbf8bfc32 Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Tue, 8 Jan 2013 16:16:19 +0100 Subject: [PATCH 03/54] Multiple changes Don't use H* in templates. Stick to DIVs and SPANs. (so as not to get any styling) Translatable strings. (options.texts.*) --- js/questionset.js | 26 +++++++++++++++----------- schema.json | 1 + views/questionset.ejs | 15 ++++++--------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 93e7d0b..e354141 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -15,10 +15,10 @@ H5P.QuestionSet = function (options) { var texttemplate = '' + '
' + -'

<%= title %>

' + +'
<%= title %>
' + ' <% for (var i=0; i' + '
' + -'

<%= questions[i].machineName %>

' + +'
<%= questions[i].machineName %>
' + '
' + ' <% } %>' + ' ' + -' ' + -' ' + -' ' + +' ' + +' ' + +' ' + '
' + '' + ''; @@ -46,7 +43,13 @@ H5P.QuestionSet = function (options) { randomOrder: false, initialQuestion: 0, progressType: 'textual', - questions: [] + questions: [], + texts: { + prevButton: "Previous", + nextButton: "Next", + finishButton: "Finish", + textualProgress: "Question: @current of @total questions" + } }; var template = new EJS({text: texttemplate}); @@ -79,7 +82,8 @@ H5P.QuestionSet = function (options) { // Update progress indicator // Test if current has been answered. if (params.progressType == 'textual') { - $('.progress-current', myDom).text("" + (questionNumber+1)); + $('.progress-text', myDom).text(params.texts.textualProgress.replace("@current", questionNumber+1).replace("@total", params.questions.length)); + // $('.progress-current', myDom).text("" + (questionNumber+1)); } else { $('.progress-dot.current', myDom).removeClass('current'); // Set answered/unanswered for current. diff --git a/schema.json b/schema.json index 63026ba..d76e117 100644 --- a/schema.json +++ b/schema.json @@ -28,6 +28,7 @@ "name": "Questions", "description": "List of questions in this set.", "type": "h5p-library", + "validLibs": ["H5P.MultiChoice"], "array": true, "minEntries": 1, "maxEntries": -1 diff --git a/views/questionset.ejs b/views/questionset.ejs index a9c19b4..8a1dee1 100644 --- a/views/questionset.ejs +++ b/views/questionset.ejs @@ -1,8 +1,8 @@
-

<%= title %>

+
<%= title %>
<% for (var i=0; i
-

<%= questions[i].machineName %>

+
<%= questions[i].machineName %>
<% } %> - - - + + +
From c57e0d5921e225978773775d5be2e7a3389df43b Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Wed, 9 Jan 2013 16:26:52 +0100 Subject: [PATCH 04/54] Better dots for progress, still not perfect.. --- js/questionset.js | 57 +++++++++++++++++++++++++++++++++++++------ schema.json | 7 +++++- views/questionset.ejs | 30 ++++++++++++++++++++--- 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index e354141..9a482de 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -14,19 +14,41 @@ H5P.QuestionSet = function (options) { return new H5P.QuestionSet(options); var texttemplate = '' + +'' + '
' + '
<%= title %>
' + ' <% for (var i=0; i' + -'
' + +'
' + '
<%= questions[i].machineName %>
' + '
' + ' <% } %>' + '