-
Notifications
You must be signed in to change notification settings - Fork 4
/
checkItem.js
58 lines (50 loc) · 1.64 KB
/
checkItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
import { lastQuestionSetter } from './lastQuestionSetter.js';
import { logger } from '../../lib/logger.js';
/**
* takes care of the Bootstrap carousel component and creates the UI
*
*/
export function checkitem() {
const carouselLength = $('.carousel-item').length;// -1
// if there is more than one item
if (carouselLength) {
$('.carousel-control-next').removeClass('d-none');
}
$('.carousel').carousel({
interval: false,
wrap: false
}).on('slide.bs.carousel', function (e) {
// first one
if (e.to == 0) {
$('.carousel-control-next').removeClass('d-none');
}
// last one
else if (e.to == carouselLength - 1) {
/*
last question: remove the button and add a new one,
that will show the final results when triggered
*/
$('.carousel-control-next').remove();
const lastQuestion = document.createElement("button");
const text = document.createTextNode("End Quiz");
lastQuestion.appendChild(text);
lastQuestion.classList.add("carousel-control-next");
const btnContainer = document.getElementById("buttonContainer");
btnContainer.appendChild(lastQuestion);
/*
we create an id to select it
and we add an event listener to it
*/
lastQuestion.id = 'endQuiz';
lastQuestionSetter(lastQuestion.id);
}
// the rest
else {
$('.carousel-control-next').removeClass('d-none');
}
});
};
logger.add({
logic: 'checkitem'
});