Merge branch 'master' into stable

pull/1/head
Svein-Tore Griff With 2015-02-19 02:18:17 +01:00
commit 84eea1e44a
3 changed files with 71 additions and 56 deletions

View File

@ -14,8 +14,10 @@ H5P.QuestionSet = function (options, contentId) {
if (!(this instanceof H5P.QuestionSet)) { if (!(this instanceof H5P.QuestionSet)) {
return new H5P.QuestionSet(options, contentId); return new H5P.QuestionSet(options, contentId);
} }
H5P.EventDispatcher.call(this);
var $ = H5P.jQuery; var $ = H5P.jQuery;
var self = this;
this.contentId = contentId;
var texttemplate = var texttemplate =
'<% if (introPage.showIntroPage) { %>' + '<% if (introPage.showIntroPage) { %>' +
@ -96,8 +98,7 @@ H5P.QuestionSet = function (options, contentId) {
overrideButtons: false, overrideButtons: false,
overrideShowSolutionButton: false, overrideShowSolutionButton: false,
overrideRetry: false overrideRetry: false
}, }
postUserStatistics: (H5P.postUserStatistics === true)
}; };
var template = new EJS({text: texttemplate}); var template = new EJS({text: texttemplate});
@ -122,11 +123,11 @@ H5P.QuestionSet = function (options, contentId) {
enableSolutionsButton: params.override.overrideShowSolutionButton enableSolutionsButton: params.override.overrideShowSolutionButton
}); });
} }
var questionInstance = H5P.newRunnable(question, contentId);
$.extend(question.params, { questionInstances.push(questionInstance);
postUserStatistics: false questionInstance.on('resize', function() {
self.trigger('resize');
}); });
questionInstances.push(H5P.newRunnable(question, contentId));
} }
// Update button state. // Update button state.
@ -167,7 +168,7 @@ H5P.QuestionSet = function (options, contentId) {
// Trigger resize on question in case the size of the QS has changed. // Trigger resize on question in case the size of the QS has changed.
var instance = questionInstances[questionNumber]; var instance = questionInstances[questionNumber];
if (instance.$ !== undefined) { if (instance.$ !== undefined) {
instance.$.trigger('resize'); instance.trigger('resize');
} }
// Update progress indicator // Update progress indicator
@ -184,6 +185,7 @@ H5P.QuestionSet = function (options, contentId) {
// Remember where we are // Remember where we are
currentQuestion = questionNumber; currentQuestion = questionNumber;
_updateButtons(); _updateButtons();
self.trigger('resize');
return currentQuestion; return currentQuestion;
}; };
@ -225,7 +227,7 @@ H5P.QuestionSet = function (options, contentId) {
var rendered = false; var rendered = false;
var reRender = function () { this.reRender = function () {
rendered = false; rendered = false;
}; };
@ -239,8 +241,8 @@ H5P.QuestionSet = function (options, contentId) {
rendered = true; rendered = true;
// Get total score. // Get total score.
var finals = getScore(); var finals = self.getScore();
var totals = totalScore(); var totals = self.totalScore();
var scoreString = params.endGame.scoreString.replace("@score", finals).replace("@total", totals); var scoreString = params.endGame.scoreString.replace("@score", finals).replace("@total", totals);
var success = ((100 * finals / totals) >= params.passPercentage); var success = ((100 * finals / totals) >= params.passPercentage);
var eventData = { var eventData = {
@ -248,12 +250,10 @@ H5P.QuestionSet = function (options, contentId) {
passed: success passed: success
}; };
var displayResults = function () { var displayResults = function () {
if (params.postUserStatistics === true) { self.triggerXAPICompleted(self.getScore(), self.totalScore());
H5P.setFinished(contentId, getScore(), totalScore());
}
if (!params.endGame.showResultPage) { if (!params.endGame.showResultPage) {
$(returnObject).trigger('h5pQuestionSetFinished', eventData); self.trigger('h5pQuestionSetFinished', eventData);
return; return;
} }
@ -271,7 +271,7 @@ H5P.QuestionSet = function (options, contentId) {
$myDom.children().hide(); $myDom.children().hide();
$myDom.append(endTemplate.render(eparams)); $myDom.append(endTemplate.render(eparams));
$('.qs-finishbutton').click(function () { $('.qs-finishbutton').click(function () {
$(returnObject).trigger('h5pQuestionSetFinished', eventData); self.trigger('h5pQuestionSetFinished', eventData);
}); });
$('.qs-solutionbutton', $myDom).click(function () { $('.qs-solutionbutton', $myDom).click(function () {
showSolutions(); showSolutions();
@ -293,21 +293,23 @@ H5P.QuestionSet = function (options, contentId) {
var $videoContainer = $('<div class="video-container"></div>').appendTo($myDom); var $videoContainer = $('<div class="video-container"></div>').appendTo($myDom);
var video = new H5P.Video({ var video = new H5P.Video({
files: videoData, sources: videoData,
fitToWrapper: true, fitToWrapper: true,
controls: false, controls: false,
autoplay: false autoplay: false
}, contentId); }, contentId);
video.endedCallback = function () { video.on('stateChange', function (event) {
displayResults(); if (event.data === H5P.Video.ENDED) {
$videoContainer.hide(); displayResults();
}; $videoContainer.hide();
}
});
video.attach($videoContainer); video.attach($videoContainer);
video.play(); video.play();
if (params.endGame.skipButtonText) { if (params.endGame.skipButtonText) {
$('<a class="h5p-button skip">' + params.endGame.skipButtonText + '</a>').click(function () { $('<a class="h5p-button skip">' + params.endGame.skipButtonText + '</a>').click(function () {
video.stop(); video.pause();
$videoContainer.hide(); $videoContainer.hide();
displayResults(); displayResults();
}).appendTo($videoContainer); }).appendTo($videoContainer);
@ -318,10 +320,11 @@ H5P.QuestionSet = function (options, contentId) {
} }
// Trigger finished event. // Trigger finished event.
displayResults(); displayResults();
self.trigger('resize');
}; };
// Function for attaching the multichoice to a DOM element. // Function for attaching the multichoice to a DOM element.
var attach = function (target) { this.attach = function (target) {
if (typeof(target) === "string") { if (typeof(target) === "string") {
$myDom = $('#' + target); $myDom = $('#' + target);
} }
@ -354,9 +357,11 @@ H5P.QuestionSet = function (options, contentId) {
var question = questionInstances[i]; var question = questionInstances[i];
question.attach($('.question-container:eq(' + i + ')', $myDom)); question.attach($('.question-container:eq(' + i + ')', $myDom));
$(question).on('h5pQuestionAnswered', function () { question.on('xAPI', function (event) {
$('.progress-dot:eq(' + currentQuestion +')', $myDom).removeClass('unanswered').addClass('answered'); if (event.getVerb() === 'attempted') {
_updateButtons(); $('.progress-dot:eq(' + currentQuestion +')', $myDom).removeClass('unanswered').addClass('answered');
_updateButtons();
}
}); });
if (question.getAnswerGiven()) { if (question.getAnswerGiven()) {
$('.progress-dot:eq(' + i +')' $('.progress-dot:eq(' + i +')'
@ -394,13 +399,14 @@ H5P.QuestionSet = function (options, contentId) {
if (renderSolutions) { if (renderSolutions) {
showSolutions(); showSolutions();
} }
this.trigger('resize');
this.$.trigger('resize');
return this; return this;
}; };
// Get current score for questionset. // Get current score for questionset.
var getScore = function () { this.getScore = function () {
var score = 0; var score = 0;
for (var i = questionInstances.length - 1; i >= 0; i--) { for (var i = questionInstances.length - 1; i >= 0; i--) {
score += questionInstances[i].getScore(); score += questionInstances[i].getScore();
@ -409,7 +415,7 @@ H5P.QuestionSet = function (options, contentId) {
}; };
// Get total score possible for questionset. // Get total score possible for questionset.
var totalScore = function () { this.totalScore = function () {
var score = 0; var score = 0;
for (var i = questionInstances.length - 1; i >= 0; i--) { for (var i = questionInstances.length - 1; i >= 0; i--) {
score += questionInstances[i].getMaxScore(); score += questionInstances[i].getMaxScore();
@ -422,7 +428,7 @@ H5P.QuestionSet = function (options, contentId) {
* *
* @returns {H5P.ContentCopyrights} * @returns {H5P.ContentCopyrights}
*/ */
var getCopyrights = function () { this.getCopyrights = function () {
var info = new H5P.ContentCopyrights(); var info = new H5P.ContentCopyrights();
// Background // Background
@ -462,20 +468,12 @@ H5P.QuestionSet = function (options, contentId) {
return info; return info;
}; };
this.getQuestions = function() {
// Masquerade the main object to hide inner properties and functions. return questionInstances;
var returnObject = {
$: $(this),
attach: attach, // Attach to DOM object
getQuestions: function () {return questionInstances;},
getScore: getScore,
showSolutions: function () {
renderSolutions = true;
},
totalScore: totalScore,
reRender: reRender,
defaults: defaults, // Provide defaults for inspection
getCopyrights: getCopyrights
}; };
return returnObject; this.showSolutions = function() {
}; renderSolutions = true;
}
};
H5P.QuestionSet.prototype = Object.create(H5P.EventDispatcher.prototype);
H5P.QuestionSet.prototype.constructor = H5P.QuestionSet;

View File

@ -2,15 +2,18 @@
"title": "Question set", "title": "Question set",
"contentType": "question", "contentType": "question",
"majorVersion": 1, "majorVersion": 1,
"minorVersion": 1, "minorVersion": 2,
"patchVersion": 0, "patchVersion": 0,
"embedTypes": [
"iframe"
],
"runnable": 1, "runnable": 1,
"fullscreen": 0, "fullscreen": 0,
"machineName": "H5P.QuestionSet", "machineName": "H5P.QuestionSet",
"author": "Amendor AS", "author": "Joubel AS",
"coreApi": { "coreApi": {
"majorVersion": 1, "majorVersion": 1,
"minorVersion": 1 "minorVersion": 4
}, },
"license": "cc-by-sa", "license": "cc-by-sa",
"preloadedJs": [ "preloadedJs": [
@ -37,13 +40,18 @@
{ {
"machineName": "H5P.Video", "machineName": "H5P.Video",
"majorVersion": 1, "majorVersion": 1,
"minorVersion": 0 "minorVersion": 1
} }
], ],
"editorDependencies": [ "editorDependencies": [
{ {
"machineName": "H5PEditor.VerticalTabs", "machineName": "H5PEditor.VerticalTabs",
"majorVersion": 1, "majorVersion": 1,
"minorVersion": 1
},
{
"machineName": "H5PEditor.QuestionSetTextualEditor",
"majorVersion": 1,
"minorVersion": 0 "minorVersion": 0
} }
] ]

View File

@ -92,7 +92,16 @@
"name": "questions", "name": "questions",
"label": "Questions", "label": "Questions",
"type": "list", "type": "list",
"widget": "verticalTabs", "widgets": [
{
"name": "VerticalTabs",
"label": "Default"
},
{
"name": "QuestionSetTextualEditor",
"label": "Textual"
}
],
"min": 1, "min": 1,
"entity": "question", "entity": "question",
"field": { "field": {
@ -101,11 +110,11 @@
"label": "Question type", "label": "Question type",
"description": "Library for this question.", "description": "Library for this question.",
"options": [ "options": [
"H5P.MultiChoice 1.1", "H5P.MultiChoice 1.2",
"H5P.DragQuestion 1.1", "H5P.DragQuestion 1.2",
"H5P.Blanks 1.1", "H5P.Blanks 1.2",
"H5P.MarkTheWords 1.1", "H5P.MarkTheWords 1.2",
"H5P.DragText 1.1" "H5P.DragText 1.2"
] ]
} }
}, },