Better dots for progress, still not perfect..

d3summaryChart
Frank Ronny Larsen 2013-01-09 16:26:52 +01:00
parent 37a7d54fbf
commit c57e0d5921
3 changed files with 81 additions and 13 deletions

View File

@ -14,19 +14,41 @@ H5P.QuestionSet = function (options) {
return new H5P.QuestionSet(options); return new H5P.QuestionSet(options);
var texttemplate = '' + var texttemplate = '' +
'<style type="text/css">' +
'.dots-container {' +
' text-align: center;' +
'}' +
'.progress-dot {' +
' display: inline-block;' +
' width: 10px;' +
' height: 10px;' +
' border-radius: 50%;' +
'}' +
'.progress-dot.unanswered {' +
' background: darkred;' +
'}' +
'.progress-dot.answered {' +
' background: darkgreen;' +
'}' +
'.progress-dot.current {' +
' box-shadow: 0px 0px 6px firebrick;' +
'}' +
'</style>' +
'<div class="questionset">' + '<div class="questionset">' +
' <div class="title"><%= title %></div>' + ' <div class="title"><%= title %></div>' +
' <% for (var i=0; i<questions.length; i++) { %>' + ' <% for (var i=0; i<questions.length; i++) { %>' +
' <div class="question" id="q-<%= i %>">' + ' <div class="question-container" id="q-<%= i %>">' +
' <div><%= questions[i].machineName %></div>' + ' <div><%= questions[i].machineName %></div>' +
' </div>' + ' </div>' +
' <% } %>' + ' <% } %>' +
' <div class="question-footer">' + ' <div class="question-footer">' +
' <div class="progress">' + ' <div class="progress">' +
' <% if (progressType == "dots") { %>' + ' <% if (progressType == "dots") { %>' +
' <% for (var i=0; i<questions.length; i++) { %>' + ' <div class="dots-container">' +
' <span class="progress-dot unanswered" id="qdot-<%= i %>">o</span>' + ' <% for (var i=0; i<questions.length; i++) { %>' +
' <%} %>' + ' <span class="progress-dot unanswered" id="qdot-<%= i %>"></span>' +
' <%} %>' +
' </div>' +
' <% } else if (progressType == "textual") { %>' + ' <% } else if (progressType == "textual") { %>' +
' <span class="progress-text"></span>' + ' <span class="progress-text"></span>' +
' <% } %>' + ' <% } %>' +
@ -55,7 +77,7 @@ H5P.QuestionSet = function (options) {
var template = new EJS({text: texttemplate}); var template = new EJS({text: texttemplate});
var params = jQuery.extend({}, defaults, options); var params = jQuery.extend({}, defaults, options);
var currentQuestion = -1; var currentQuestion = 0;
var questionInstances = new Array(); var questionInstances = new Array();
var allQuestionsAnswered = false; var allQuestionsAnswered = false;
var myDom; var myDom;
@ -65,6 +87,14 @@ H5P.QuestionSet = function (options) {
console.log("TODO: Randomize order of questions"); console.log("TODO: Randomize order of questions");
} }
var _allQuestionsAnswered = function () {
var answered = true;
for (var i = questionInstances.length - 1; i >= 0; i--) {
answered = answered && (questionInstances[i]).getAnswerGiven();
}
return answered;
};
var _showQuestion = function (questionNumber) { var _showQuestion = function (questionNumber) {
// Sanitize input. // Sanitize input.
if (questionNumber < 0) { questionNumber = 0; } if (questionNumber < 0) { questionNumber = 0; }
@ -72,9 +102,10 @@ H5P.QuestionSet = function (options) {
$('.prev.button', myDom).attr({'disabled': (questionNumber === 0)}); $('.prev.button', myDom).attr({'disabled': (questionNumber === 0)});
$('.next.button', myDom).attr({'disabled': (questionNumber == params.questions.length-1)}); $('.next.button', myDom).attr({'disabled': (questionNumber == params.questions.length-1)});
$('.finish.button', myDom).attr({'disabled': !(_allQuestionsAnswered())});
// Hide all questions // Hide all questions
$('.question', myDom).hide(); $('.question-container', myDom).hide();
// Reshow the requested question // Reshow the requested question
$('#q-' + questionNumber, myDom).show(); $('#q-' + questionNumber, myDom).show();
@ -88,6 +119,9 @@ H5P.QuestionSet = function (options) {
$('.progress-dot.current', myDom).removeClass('current'); $('.progress-dot.current', myDom).removeClass('current');
// Set answered/unanswered for current. // Set answered/unanswered for current.
$('#qdot-' + questionNumber, myDom).addClass('current'); $('#qdot-' + questionNumber, myDom).addClass('current');
if (questionInstances[currentQuestion].getAnswerGiven()) {
$('#qdot-' + currentQuestion, myDom).removeClass('unanswered').addClass('answered');
}
} }
// Remember where we are // Remember where we are
@ -110,12 +144,19 @@ H5P.QuestionSet = function (options) {
} }
// Set event listeners. // Set event listeners.
$('.next.button', myDom).click(function() { $('.next.button', myDom).click(function (ev) {
_showQuestion(currentQuestion + 1); _showQuestion(currentQuestion + 1);
}); });
$('.prev.button', myDom).click(function() { $('.prev.button', myDom).click(function (ev) {
_showQuestion(currentQuestion - 1); _showQuestion(currentQuestion - 1);
}); });
$('.finish.button', myDom).click(function (ev) {
// get total score.
// Display result page.
// Display animation if present.
// Remove DOM. (delete container)
myDom.remove();
});
// Hide all but initial Question. // Hide all but initial Question.
_showQuestion(params.initialQuestion); _showQuestion(params.initialQuestion);

View File

@ -17,13 +17,18 @@
"type": "integer", "type": "integer",
"default": 0 "default": 0
}, },
"backgroundImage": {
"name": "Background image",
"description": "An optional background image for the Question set.",
"type": "image"
},
"progressType": { "progressType": {
"name": "Progress indicator", "name": "Progress indicator",
"description": "Question set progress indicator style", "description": "Question set progress indicator style",
"type": "select", "type": "select",
"values": [{"text": "Textual", "value": "textual"}, {"text": "Dots", "value": "dots"}], "values": [{"text": "Textual", "value": "textual"}, {"text": "Dots", "value": "dots"}],
"default": "textual" "default": "textual"
}, },
"questions": { "questions": {
"name": "Questions", "name": "Questions",
"description": "List of questions in this set.", "description": "List of questions in this set.",

View File

@ -1,16 +1,38 @@
<style type="text/css">
.dots-container {
text-align: center;
}
.progress-dot {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
}
.progress-dot.unanswered {
background: darkred;
}
.progress-dot.answered {
background: darkgreen;
}
.progress-dot.current {
box-shadow: 0px 0px 6px firebrick;
}
</style>
<div class="questionset"> <div class="questionset">
<div class="title"><%= title %></div> <div class="title"><%= title %></div>
<% for (var i=0; i<questions.length; i++) { %> <% for (var i=0; i<questions.length; i++) { %>
<div class="question" id="q-<%= i %>"> <div class="question-container" id="q-<%= i %>">
<div><%= questions[i].machineName %></div> <div><%= questions[i].machineName %></div>
</div> </div>
<% } %> <% } %>
<div class="question-footer"> <div class="question-footer">
<div class="progress"> <div class="progress">
<% if (progressType == "dots") { %> <% if (progressType == "dots") { %>
<% for (var i=0; i<questions.length; i++) { %> <div class="dots-container">
<span class="progress-dot unanswered" id="qdot-<%= i %>">o</span> <% for (var i=0; i<questions.length; i++) { %>
<%} %> <span class="progress-dot unanswered" id="qdot-<%= i %>"></span>
<%} %>
</div>
<% } else if (progressType == "textual") { %> <% } else if (progressType == "textual") { %>
<span class="progress-text"></span> <span class="progress-text"></span>
<% } %> <% } %>