Skip to content

Commit

Permalink
HFP-3820 Fix compound children answer state tracking (#301)
Browse files Browse the repository at this point in the history
* HFP-3820 Fix compound children answer state tracking

* HFP-3820 Make eslint happy

* HFP-3820 Update modules

* Run npm audit fix
  • Loading branch information
otacke authored Jul 3, 2024
1 parent 5d66d7c commit e6eeb3c
Show file tree
Hide file tree
Showing 13 changed files with 3,023 additions and 2,585 deletions.
5,392 changes: 2,914 additions & 2,478 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
"author": "Joubel",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.3",
"@babel/plugin-proposal-object-rest-spread": "^7.18.6",
"@babel/plugin-transform-object-assign": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"babel-loader": "^8.2.5",
"@babel/plugin-transform-object-assign": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"babel-loader": "^9.1.3",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"eslint": "^8.18.0",
"css-loader": "^6.10.0",
"eslint": "^8.57.0",
"h5p-lib-controls": "0.0.15",
"h5p-parent": "0.0.2",
"mini-css-extract-plugin": "^2.6.1",
"regenerator-runtime": "^0.13.9",
"mini-css-extract-plugin": "^2.8.1",
"regenerator-runtime": "^0.14.1",
"resolve-url-loader": "^5.0.0",
"sass": "^1.53.0",
"sass-loader": "^13.0.2",
"webpack": "^5.76.0",
"webpack-cli": "^4.10.0"
"sass": "^1.72.0",
"sass-loader": "^14.1.1",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
}
}
10 changes: 5 additions & 5 deletions src/scripts/confirmation-dialog.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

/**
* Confirmation dialog
*
*
*/
const ConfirmationDialog = function (options, offset) {
const ConfirmationDialog = function (options) {
const confirmationDialog = new H5P.ConfirmationDialog(options)
.appendTo(document.body);

let element = confirmationDialog.getElement();
element.classList.add('h5p-cp-confirmation-dialog');

confirmationDialog.show();
return confirmationDialog;
};

export default ConfirmationDialog;
export default ConfirmationDialog;
56 changes: 28 additions & 28 deletions src/scripts/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let CoursePresentation = function (params, id, extras) {
containsCompleted: '@slideName contains completed interaction',
slideCount: 'Slide @index of @total',
accessibilityCanvasLabel: 'Presentation canvas. Use left and right arrow to move between slides.',
containsOnlyCorrect: "@slideName only has correct answers",
containsOnlyCorrect: '@slideName only has correct answers',
containsIncorrectAnswers: '@slideName has incorrect answers',
shareResult: 'Share Result',
accessibilityTotalScore: 'You got @score of @maxScore points in total',
Expand Down Expand Up @@ -203,8 +203,8 @@ CoursePresentation.prototype.slideHasAnsweredTask = function (index) {

// Disregard questions where "no answer" is the correct answer.
return tasks
.filter(task => isFunction(task.getAnswerGiven))
.some(task => task.getAnswerGiven() && !H5P.isEmpty(task.getCurrentState()));
.filter((task) => isFunction(task.getAnswerGiven))
.some((task) => task.getAnswerGiven() && !H5P.isEmpty(task.getCurrentState()));
};

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ CoursePresentation.prototype.attach = function ($container) {
if (keywordMenuConfig.length > 0 || this.isEditor()) {
// Initialize keyword titles
this.keywordMenu.init(keywordMenuConfig);
this.keywordMenu.on('select', event => this.keywordClick(event.data.index));
this.keywordMenu.on('select', (event) => this.keywordClick(event.data.index));
this.keywordMenu.on('close', () => this.hideKeywords());
this.keywordMenu.on('select', () => {
this.$currentKeyword = this.$keywords.children('.h5p-current');
Expand Down Expand Up @@ -436,7 +436,7 @@ CoursePresentation.prototype.attach = function ($container) {
appendTo: this.$wrapper
});

H5P.Tooltip(this.$fullScreenButton.get(0), {position: 'left'});
H5P.Tooltip(this.$fullScreenButton.get(0), { position: 'left' });

addClickAndKeyboardListeners(this.$fullScreenButton, () => that.toggleFullScreen());
}
Expand Down Expand Up @@ -468,7 +468,7 @@ CoursePresentation.prototype.belongsToTagName = function (node, tagNames, stop)
if (typeof tagNames === 'string') {
tagNames = [tagNames];
}
tagNames = tagNames.map(tagName => tagName.toLowerCase());
tagNames = tagNames.map((tagName) => tagName.toLowerCase());

const tagName = node.tagName.toLowerCase();
if (tagNames.indexOf(tagName) !== -1) {
Expand Down Expand Up @@ -504,7 +504,7 @@ CoursePresentation.prototype.hasTabIndex = (element, stopElement) => {
}
}
return false;
}
};

/**
* Removes old menu items, and create new ones from slides.
Expand All @@ -531,7 +531,7 @@ CoursePresentation.prototype.getKeywordMenuConfig = function () {
subtitle: `${this.l10n.slide} ${index + 1}`,
index
}))
.filter(config => config.title !== KEYWORD_TITLE_SKIP);
.filter((config) => config.title !== KEYWORD_TITLE_SKIP);
};

/**
Expand Down Expand Up @@ -639,7 +639,7 @@ CoursePresentation.prototype.getMaxScore = function () {
CoursePresentation.prototype.setProgressBarFeedback = function (slideScores) {
if (slideScores !== undefined && slideScores) {
// Set feedback icons for progress bar.
slideScores.forEach(singleSlide => {
slideScores.forEach((singleSlide) => {
const $indicator = this.progressbarParts[singleSlide.slide - 1]
.find('.h5p-progressbar-part-has-task');

Expand All @@ -653,7 +653,7 @@ CoursePresentation.prototype.setProgressBarFeedback = function (slideScores) {
}
else {
// Remove all feedback icons.
this.progressbarParts.forEach(pbPart => {
this.progressbarParts.forEach((pbPart) => {
pbPart.find('.h5p-progressbar-part-has-task')
.removeClass('h5p-is-correct')
.removeClass('h5p-is-wrong');
Expand Down Expand Up @@ -919,7 +919,7 @@ CoursePresentation.prototype.attachElements = function ($slide, index) {
'$target': $slide,
'library': 'CoursePresentation',
'key': 'newSlide'
}, {'bubbles': true, 'external': true});
}, { 'bubbles': true, 'external': true });

this.elementsAttached[index] = true;
};
Expand All @@ -935,7 +935,7 @@ CoursePresentation.prototype.attachElements = function ($slide, index) {
*/
CoursePresentation.prototype.attachElement = function (element, instance, $slide, index) {
const displayAsButton = (element.displayAsButton !== undefined && element.displayAsButton);
var buttonSizeClass = (element.buttonSize !== undefined ? "h5p-element-button-" + element.buttonSize : "");
var buttonSizeClass = (element.buttonSize !== undefined ? 'h5p-element-button-' + element.buttonSize : '');
var classes = 'h5p-element' +
(displayAsButton ? ' h5p-element-button-wrapper' : '') +
(buttonSizeClass.length ? ' ' + buttonSizeClass : '');
Expand Down Expand Up @@ -1097,7 +1097,7 @@ CoursePresentation.prototype.createInteractionButton = function (element, instan
* @param {jQuery} $btn
* @return {Function}
*/
const setAriaExpandedFalse = $btn => () => $btn.attr('aria-expanded', 'false');
const setAriaExpandedFalse = ($btn) => () => $btn.attr('aria-expanded', 'false');

const $button = $('<div>', {
role: 'button',
Expand Down Expand Up @@ -1200,7 +1200,7 @@ CoursePresentation.prototype.showInteractionPopup = function (instance, $button,
* @param {string} library
* @return {string}
*/
CoursePresentation.prototype.getLibraryTypePmz = library => kebabCase(library.split(' ')[0]).toLowerCase();
CoursePresentation.prototype.getLibraryTypePmz = (library) => kebabCase(library.split(' ')[0]).toLowerCase();

/**
* Resize image inside popup dialog.
Expand Down Expand Up @@ -1504,22 +1504,22 @@ CoursePresentation.prototype.showPopup = function ({
.removeClass('h5p-animate')
.click(self.closePopup)
.find('.h5p-popup-container')
.removeClass('h5p-animate')
.click(function () {
doNotClose = true;
})
.keydown(function (event) {
if (event.which === keyCode.ESC) {
self.closePopup(event);
}
})
.find('.h5p-close-popup')
.focus();
.removeClass('h5p-animate')
.click(function () {
doNotClose = true;
})
.keydown(function (event) {
if (event.which === keyCode.ESC) {
self.closePopup(event);
}
})
.find('.h5p-close-popup')
.focus();

// Hide other elements from the tab order
this.disableTabIndexes();

addClickAndKeyboardListeners($popup.find('.h5p-close-popup'), event => self.closePopup(event));
addClickAndKeyboardListeners($popup.find('.h5p-close-popup'), (event) => self.closePopup(event));

return $popup;
};
Expand Down Expand Up @@ -2242,7 +2242,7 @@ CoursePresentation.prototype.getCopyrights = function () {
// Create a generic flat copyright list
elementCopyrights = new H5P.ContentCopyrights();
// In metadata alone there's no way of knowing what the machineName is.
H5P.findCopyrights(elementCopyrights, params, this.contentId, {metadata: metadata, machineName: instance.libraryInfo.machineName});
H5P.findCopyrights(elementCopyrights, params, this.contentId, { metadata: metadata, machineName: instance.libraryInfo.machineName });
}
var label = (element + 1);
if (params.contentName !== undefined) {
Expand Down Expand Up @@ -2289,7 +2289,7 @@ CoursePresentation.prototype.getXAPIData = function () {
if (child && child.getXAPIData) {
return child.getXAPIData();
}
}).filter(data => !!data);
}).filter((data) => !!data);

return {
statement: xAPIEvent.data.statement,
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Element(parameters) {
});

if (!self.parent.parent.isEditor()) {
self.instance.on('navigate', event => {
self.instance.on('navigate', (event) => {
const index = event.data;
self.parent.parent.jumpToSlide(index);
self.parent.parent.focus();
Expand Down Expand Up @@ -43,7 +43,7 @@ function Element(parameters) {

// Override child settings
library.params = library.params || {};
self.instance = H5P.newRunnable(library, self.parent.parent.contentId, undefined, true, {parent: self.parent.parent});
self.instance = H5P.newRunnable(library, self.parent.parent.contentId, undefined, true, { parent: self.parent.parent });
if (self.instance.preventResize !== undefined) {
self.instance.preventResize = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/go-to-slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class GoToSlide {
title: title
});

addClickAndKeyboardListeners(this.$element, event => {
addClickAndKeyboardListeners(this.$element, (event) => {
this.eventDispatcher.trigger('navigate', goTo);
event.preventDefault();
});
Expand Down
20 changes: 10 additions & 10 deletions src/scripts/keyword-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { jQuery as $, EventDispatcher } from './globals';
* @param {Element|EventTarget} element
* @return {number}
*/
const getElementsDatasetIndex = element => parseInt(element.dataset.index);
const getElementsDatasetIndex = (element) => parseInt(element.dataset.index);

/**
* @class
Expand All @@ -48,7 +48,7 @@ export default class KeywordMenu {
this.controls = new Controls([new UIKeyboard()]);

// on keyboard select
this.controls.on('select', event => {
this.controls.on('select', (event) => {
this.onMenuItemSelect(getElementsDatasetIndex(event.element));
});

Expand All @@ -66,9 +66,9 @@ export default class KeywordMenu {
* @returns {Element[]}
*/
init(keywordConfigs) {
this.menuItemElements = keywordConfigs.map(config => this.createMenuItemElement(config));
this.menuItemElements.forEach(element => this.menuElement.appendChild(element));
this.menuItemElements.forEach(element => this.controls.addElement(element));
this.menuItemElements = keywordConfigs.map((config) => this.createMenuItemElement(config));
this.menuItemElements.forEach((element) => this.menuElement.appendChild(element));
this.menuItemElements.forEach((element) => this.controls.addElement(element));

this.setCurrentSlideIndex(this.state.currentIndex);

Expand Down Expand Up @@ -99,7 +99,7 @@ export default class KeywordMenu {
*/
removeAllMenuItemElements() {
this.menuItemElements
.forEach(element => {
.forEach((element) => {
this.controls.removeElement(element);
this.menuElement.removeChild(element);
});
Expand Down Expand Up @@ -128,7 +128,7 @@ export default class KeywordMenu {
const element = document.createElement('li');

element.setAttribute('role', 'menuitem');
element.addEventListener('click', event => {
element.addEventListener('click', (event) => {
this.onMenuItemSelect(getElementsDatasetIndex(event.currentTarget));
});
this.applyConfigToMenuItemElement(element, config);
Expand Down Expand Up @@ -180,7 +180,7 @@ export default class KeywordMenu {
* @param {KeywordMenuState} state
*/
updateCurrentlySelected(elements, state) {
elements.forEach(element => {
elements.forEach((element) => {
const isSelected = state.currentIndex === getElementsDatasetIndex(element);
element.classList.toggle('h5p-current', isSelected);

Expand Down Expand Up @@ -218,7 +218,7 @@ export default class KeywordMenu {
* @return {Element}
*/
getFirstElementAfter(index) {
return this.menuItemElements.filter(element => getElementsDatasetIndex(element) >= index)[0];
return this.menuItemElements.filter((element) => getElementsDatasetIndex(element) >= index)[0];
}

/**
Expand All @@ -229,7 +229,7 @@ export default class KeywordMenu {
* @return {Element}
*/
getElementByIndex(elements, index) {
return elements.filter(element => getElementsDatasetIndex(element) === index)[0];
return elements.filter((element) => getElementsDatasetIndex(element) === index)[0];
}

/**
Expand Down
Loading

0 comments on commit e6eeb3c

Please sign in to comment.