Skip to content

Commit f3994ee

Browse files
committed
Make eslint happy
1 parent 0455243 commit f3994ee

File tree

10 files changed

+105
-93
lines changed

10 files changed

+105
-93
lines changed

src/scripts/components/main.js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import Util from '@services/util.js';
22
import PanelList from '@components/panel-list/panel-list.js';
33
import { VIEW_STATES } from '@scripts/h5p-discrete-option-multi-choice';
44

5+
/** @constant {number} DISTRACTION_CHANCE Chance of distraction. */
6+
const DISTRACTION_CHANCE = 0.5;
7+
8+
/** @constant {number} JUMPING_PREVENTION_TIMEOUT_MS Timeout to prevent jumping. */
9+
const JUMPING_PREVENTION_TIMEOUT_MS = 10;
10+
11+
/** @constant {number} OFFSET_FACTOR Factor for offset calculations. */
12+
const OFFSET_FACTOR = 2;
13+
514
/**
615
* Main DOM component incl. main controller.
716
*/
@@ -19,7 +28,7 @@ export default class Main {
1928

2029
this.callbacks = Util.extend({
2130
onAnswered: () => {},
22-
onGameOver: () => {}
31+
onGameOver: () => {},
2332
}, callbacks);
2433

2534
this.dom = document.createElement('div');
@@ -127,7 +136,7 @@ export default class Main {
127136
}
128137

129138
// Randomly add one more option on correct answer to distract
130-
if (scoreDelta === 1 && Math.random() < 0.5) {
139+
if (scoreDelta === 1 && Math.random() < DISTRACTION_CHANCE) {
131140
this.callbacks.onGameOver({ quiet: params.quiet }); // Done
132141
return;
133142
}
@@ -145,7 +154,7 @@ export default class Main {
145154
if (!params.quiet) {
146155
const message = Util.stripHTML(
147156
this.params.dictionary.get('a11y.panelAdded')
148-
.replace(/@option/, this.answerOptions[this.currentPanelIndex].text)
157+
.replace(/@option/, this.answerOptions[this.currentPanelIndex].text),
149158
);
150159

151160
this.params.globals.get('read')(message);
@@ -155,7 +164,7 @@ export default class Main {
155164
if (params.focus) {
156165
window.setTimeout(() => {
157166
this.panelList.focus(this.currentPanelIndex, true);
158-
}, 10); // Prevent jumping before iframe resize and let screenreader read
167+
}, JUMPING_PREVENTION_TIMEOUT_MS); // Prevent jumping before iframe resize and let screenreader read
159168
}
160169
}
161170

@@ -168,7 +177,7 @@ export default class Main {
168177

169178
this.scorePoints = this.scorePoints || new H5P.Question.ScorePoints();
170179
this.panelList.showResults(
171-
params.showScores ? this.scorePoints : null
180+
params.showScores ? this.scorePoints : null,
172181
);
173182
}
174183

@@ -177,7 +186,7 @@ export default class Main {
177186
*/
178187
showFeedback() {
179188
this.panelList.showFeedback(
180-
{ selected: this.answerOptions.map((option) => option.userAnswer) }
189+
{ selected: this.answerOptions.map((option) => option.userAnswer) },
181190
);
182191
}
183192

@@ -206,10 +215,10 @@ export default class Main {
206215
appendResultsMessage() {
207216
this.resultsMessage = document.createElement('p');
208217
this.resultsMessage.classList.add(
209-
'h5p-discrete-option-multi-choice-message'
218+
'h5p-discrete-option-multi-choice-message',
210219
);
211220
this.resultsMessage.innerText = this.params.dictionary.get(
212-
'l10n.yourResults'
221+
'l10n.yourResults',
213222
);
214223

215224
this.dom.append(this.resultsMessage);
@@ -262,7 +271,7 @@ export default class Main {
262271
*/
263272
reset(params = {}) {
264273
params = Util.extend({
265-
previousState: {}
274+
previousState: {},
266275
}, params);
267276

268277
this.dom.innerHTML = '';
@@ -296,7 +305,7 @@ export default class Main {
296305
for (let i = 0; i < values.length; i++) {
297306
selector.options.push({
298307
value: values[i],
299-
label: labels?.[i] ?? values[i]
308+
label: labels?.[i] ?? values[i],
300309
});
301310
}
302311
}
@@ -321,21 +330,21 @@ export default class Main {
321330
{
322331
dictionary: this.params.dictionary,
323332
globals: this.params.globals,
324-
options: this.answerOptions
333+
options: this.answerOptions,
325334
},
326335
{
327336
onAnswered: (index, userAnswer) => {
328337
this.handleAnswered({
329338
index: index,
330339
userAnswer: userAnswer,
331340
quiet: false,
332-
focus: true
341+
focus: true,
333342
});
334343
},
335344
onConfidenceChanged: (index, confidenceIndex) => {
336345
this.handleConfidenceChanged(index, confidenceIndex);
337-
}
338-
}
346+
},
347+
},
339348
);
340349

341350
this.panelList.reset({ previousState: params.previousState.answers });
@@ -367,10 +376,10 @@ export default class Main {
367376
answers: this.answerOptions.map((option) => {
368377
return ({
369378
userAnswer: option.userAnswer,
370-
confidenceIndex: option.confidenceIndex
379+
confidenceIndex: option.confidenceIndex,
371380
});
372381
}),
373-
isOvertime: this.isOvertime
382+
isOvertime: this.isOvertime,
374383
};
375384
}
376385

@@ -404,11 +413,11 @@ export default class Main {
404413
return this.getScoredAnswerOptions()
405414
.map((option, index) => {
406415
if ((option.userAnswer === true)) {
407-
return 2 * index;
416+
return OFFSET_FACTOR * index;
408417
}
409418

410419
if ((option.userAnswer === false)) {
411-
return 2 * index + 1;
420+
return OFFSET_FACTOR * index + 1;
412421
}
413422

414423
return null;
@@ -426,17 +435,17 @@ export default class Main {
426435
.reduce((choices, choice, index) => {
427436
choices.push(
428437
{
429-
id: (index * 2).toString(),
438+
id: (index * OFFSET_FACTOR).toString(),
430439
description: {
431-
'en-US': `${Util.stripHTML(choice.text)} (@correct)`
432-
}
440+
'en-US': `${Util.stripHTML(choice.text)} (@correct)`,
441+
},
433442
},
434443
{
435-
id: (index * 2 + 1).toString(),
444+
id: (index * OFFSET_FACTOR + 1).toString(),
436445
description: {
437-
'en-US': `${Util.stripHTML(choice.text)} (@incorrect)`
438-
}
439-
}
446+
'en-US': `${Util.stripHTML(choice.text)} (@incorrect)`,
447+
},
448+
},
440449
);
441450

442451
return choices;
@@ -452,15 +461,15 @@ export default class Main {
452461
this.getScoredAnswerOptions()
453462
.reduce((correct, option, index) => {
454463
if (option.correct) {
455-
correct.push((2 * index).toString());
464+
correct.push((OFFSET_FACTOR * index).toString());
456465
}
457466
else {
458-
correct.push((2 * index + 1).toString());
467+
correct.push((OFFSET_FACTOR * index + 1).toString());
459468
}
460469

461470
return correct;
462471
}, [])
463-
.join('[,]')
472+
.join('[,]'),
464473
];
465474
}
466475
}

src/scripts/components/panel-list/panel-list.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class PanelList {
1515
*/
1616
constructor(params = {}, callbacks = {}) {
1717
this.params = Util.extend({
18-
options: []
18+
options: [],
1919
}, params);
2020

2121
// Set uuid for each option
@@ -26,7 +26,7 @@ export default class PanelList {
2626

2727
this.callbacks = Util.extend({
2828
onAnswered: () => {},
29-
onConfidenceChanged: () => {}
29+
onConfidenceChanged: () => {},
3030
}, callbacks);
3131

3232
this.attachedPanels = [];
@@ -41,7 +41,7 @@ export default class PanelList {
4141
return new Panel(
4242
{
4343
dictionary: this.params.dictionary,
44-
options: option
44+
options: option,
4545
},
4646
{
4747
onAnswered: (score) => {
@@ -52,8 +52,8 @@ export default class PanelList {
5252
},
5353
onGotFocus: () => {
5454
this.handlePanelGotFocus(index);
55-
}
56-
}
55+
},
56+
},
5757
);
5858
});
5959

@@ -97,7 +97,7 @@ export default class PanelList {
9797
// Mark selected answer option correctness
9898
panel.markAnswer(
9999
wasAnswerCorrect,
100-
scorePoints?.getElement(wasAnswerCorrect)
100+
scorePoints?.getElement(wasAnswerCorrect),
101101
);
102102
});
103103
}
@@ -327,7 +327,7 @@ export default class PanelList {
327327
*/
328328
reset(params = {}) {
329329
params = Util.extend({
330-
previousState: []
330+
previousState: [],
331331
}, params);
332332

333333
this.panels.forEach((panel, index) => {

src/scripts/components/panel-list/panel/cycle-button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export default class CycleButton {
1717
constructor(params = {}, callbacks = {}) {
1818
this.params = Util.extend({
1919
selector: {},
20-
confidenceIndex: 0
20+
confidenceIndex: 0,
2121
}, params);
2222

2323
this.callbacks = Util.extend({
2424
onClicked: () => {},
25-
onGotFocus: () => {}
25+
onGotFocus: () => {},
2626
}, callbacks);
2727

2828
this.dom = document.createElement('button');
@@ -85,7 +85,7 @@ export default class CycleButton {
8585
this.dom.innerHTML = this.params.selector.options[this.selectedIndex].label;
8686
this.dom.setAttribute(
8787
'aria-label',
88-
`Change confidence. Current value: ${this.params.selector.options[this.selectedIndex].value}`
88+
`Change confidence. Current value: ${this.params.selector.options[this.selectedIndex].value}`,
8989
);
9090
}
9191

src/scripts/components/panel-list/panel/feedback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class Feedback {
1414
constructor(params = {}) {
1515
this.params = Util.extend({
1616
chosenFeedback: '',
17-
notChosenFeedback: ''
17+
notChosenFeedback: '',
1818
}, params);
1919

2020
this.dom = document.createElement('div');

src/scripts/components/panel-list/panel/option-button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class OptionButton {
1717

1818
this.callbacks = Util.extend({
1919
onClicked: () => {},
20-
onGotFocus: () => {}
20+
onGotFocus: () => {},
2121
}, callbacks);
2222

2323
this.dom = document.createElement('button');
@@ -28,8 +28,8 @@ export default class OptionButton {
2828
this.params.dictionary
2929
.get('a11y.markAnswerAs')
3030
.replace(
31-
/@status/, this.params.dictionary.get('a11y.' + this.params.type)
32-
)
31+
/@status/, this.params.dictionary.get(`a11y.${ this.params.type}`),
32+
),
3333
);
3434
this.dom.setAttribute('disabled', 'disabled');
3535

0 commit comments

Comments
 (0)