upgrade
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
H5P.Question.Explainer = (function ($) {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @class
|
||||
* @param {string} title
|
||||
* @param {array} explanations
|
||||
*/
|
||||
function Explainer(title, explanations) {
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Create the DOM structure
|
||||
*/
|
||||
var createHTML = function () {
|
||||
self.$explanation = $('<div>', {
|
||||
'class': 'h5p-question-explanation-container'
|
||||
});
|
||||
|
||||
// Add title:
|
||||
$('<div>', {
|
||||
'class': 'h5p-question-explanation-title',
|
||||
role: 'heading',
|
||||
html: title,
|
||||
appendTo: self.$explanation
|
||||
});
|
||||
|
||||
var $explanationList = $('<ul>', {
|
||||
'class': 'h5p-question-explanation-list',
|
||||
appendTo: self.$explanation
|
||||
});
|
||||
|
||||
for (var i = 0; i < explanations.length; i++) {
|
||||
var feedback = explanations[i];
|
||||
var $explanationItem = $('<li>', {
|
||||
'class': 'h5p-question-explanation-item',
|
||||
appendTo: $explanationList
|
||||
});
|
||||
|
||||
var $content = $('<div>', {
|
||||
'class': 'h5p-question-explanation-status'
|
||||
});
|
||||
|
||||
if (feedback.correct) {
|
||||
$('<span>', {
|
||||
'class': 'h5p-question-explanation-correct',
|
||||
html: feedback.correct,
|
||||
appendTo: $content
|
||||
});
|
||||
}
|
||||
if (feedback.wrong) {
|
||||
$('<span>', {
|
||||
'class': 'h5p-question-explanation-wrong',
|
||||
html: feedback.wrong,
|
||||
appendTo: $content
|
||||
});
|
||||
}
|
||||
$content.appendTo($explanationItem);
|
||||
|
||||
if (feedback.text) {
|
||||
$('<div>', {
|
||||
'class': 'h5p-question-explanation-text',
|
||||
html: feedback.text,
|
||||
appendTo: $explanationItem
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
createHTML();
|
||||
|
||||
/**
|
||||
* Return the container HTMLElement
|
||||
*
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
self.getElement = function () {
|
||||
return self.$explanation;
|
||||
};
|
||||
}
|
||||
|
||||
return Explainer;
|
||||
|
||||
})(H5P.jQuery);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
(function (Question) {
|
||||
|
||||
/**
|
||||
* Makes it easy to add animated score points for your question type.
|
||||
*
|
||||
* @class H5P.Question.ScorePoints
|
||||
*/
|
||||
Question.ScorePoints = function () {
|
||||
var self = this;
|
||||
|
||||
var elements = [];
|
||||
var showElementsTimer;
|
||||
|
||||
/**
|
||||
* Create the element that displays the score point element for questions.
|
||||
*
|
||||
* @param {boolean} isCorrect
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
self.getElement = function (isCorrect) {
|
||||
var element = document.createElement('div');
|
||||
element.classList.add(isCorrect ? 'h5p-question-plus-one' : 'h5p-question-minus-one');
|
||||
element.classList.add('h5p-question-hidden-one');
|
||||
elements.push(element);
|
||||
|
||||
// Schedule display animation of all added elements
|
||||
if (showElementsTimer) {
|
||||
clearTimeout(showElementsTimer);
|
||||
}
|
||||
showElementsTimer = setTimeout(showElements, 0);
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var showElements = function () {
|
||||
// Determine delay between triggering animations
|
||||
var delay = 0;
|
||||
var increment = 150;
|
||||
var maxTime = 1000;
|
||||
|
||||
if (elements.length && elements.length > Math.ceil(maxTime / increment)) {
|
||||
// Animations will run for more than ~1 second, reduce it.
|
||||
increment = maxTime / elements.length;
|
||||
}
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
// Use timer to trigger show
|
||||
setTimeout(showElement(elements[i]), delay);
|
||||
|
||||
// Increse delay for next element
|
||||
delay += increment;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger transition animation for the given element
|
||||
*
|
||||
* @private
|
||||
* @param {HTMLElement} element
|
||||
* @return {function}
|
||||
*/
|
||||
var showElement = function (element) {
|
||||
return function () {
|
||||
element.classList.remove('h5p-question-hidden-one');
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
})(H5P.Question);
|
||||
Reference in New Issue
Block a user