This repository was archived by the owner on Jun 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtimedmc.js
More file actions
134 lines (128 loc) · 4.21 KB
/
timedmc.js
File metadata and controls
134 lines (128 loc) · 4.21 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import MultipleChoice from "./mchoice.js";
export default class TimedMC extends MultipleChoice {
constructor(opts) {
super(opts);
$(this.containerDiv).addClass("alert alert-warning runestone");
this.needsReinitialization = true;
this.renderTimedIcon(this.containerDiv);
this.hideButtons(); // Don't show per-question buttons in a timed assessment
}
renderTimedIcon(component) {
// renders the clock icon on timed components. The component parameter
// is the element that the icon should be appended to.
var timeIconDiv = document.createElement("div");
timeIconDiv.className = "timeTip";
timeIconDiv.title = "";
$(component).prepend(timeIconDiv);
}
hideButtons() {
//Just hiding the buttons doesn't prevent submitting the form when entering is clicked
//We need to completely disable the buttons
$(this.submitButton).attr("disabled", "true");
$(this.submitButton).hide();
$(this.compareButton).hide();
}
// These methods override the methods in the base class. Called from renderFeedback()
//
renderMCMAFeedBack() {
this.feedbackTimedMC();
}
renderMCMFFeedback(whatever, whateverr) {
this.feedbackTimedMC();
}
feedbackTimedMC() {
for (var i = 0; i < this.indexArray.length; i++) {
var tmpindex = this.indexArray[i];
$(this.feedBackEachArray[i]).text(
String.fromCharCode(65 + i) + ". " + this.feedbackList[i]
);
var tmpid = this.answerList[tmpindex].id;
if (this.correctList.indexOf(tmpid) >= 0) {
this.feedBackEachArray[i].classList.add(
"alert",
"alert-success"
);
} else {
this.feedBackEachArray[i].classList.add(
"alert",
"alert-danger"
);
}
}
}
renderMCFormOpts() {
super.renderMCFormOpts();
this.feedBackEachArray = [];
for (var j = 0; j < this.answerList.length; j++) {
var k = this.indexArray[j];
var feedBackEach = document.createElement("div");
feedBackEach.id = this.divid + "_eachFeedback_" + k;
feedBackEach.classList.add("eachFeedback");
this.feedBackEachArray.push(feedBackEach);
this.optsForm.appendChild(feedBackEach);
}
}
checkCorrectTimedMCMA() {
if (
this.correctCount === this.correctList.length &&
this.correctList.length === this.givenArray.length
) {
this.correct = true;
} else if (this.givenArray.length !== 0) {
this.correct = false;
} else {
// question was skipped
this.correct = null;
}
switch (this.correct) {
case true:
return "T";
case false:
return "F";
default:
return null;
}
}
checkCorrectTimedMCMF() {
// Returns if the question was correct, incorrect, or skipped (return null in the last case)
switch (this.correct) {
case true:
return "T";
case false:
return "F";
default:
return null;
}
}
checkCorrectTimed() {
if (this.multipleanswers) {
return this.checkCorrectTimedMCMA();
} else {
return this.checkCorrectTimedMCMF();
}
}
hideFeedback() {
for (var i = 0; i < this.feedBackEachArray.length; i++) {
$(this.feedBackEachArray[i]).hide();
}
}
reinitializeListeners() {
let self = this;
let answerFunc = function () {
self.isAnswered = true;
};
for (let opt of this.optionArray) {
opt.input.onclick = answerFunc;
}
}
}
if (typeof window.component_factory === "undefined") {
window.component_factory = {};
}
window.component_factory.multiplechoice = function (opts) {
if (opts.timed) {
return new TimedMC(opts);
} else {
return new MultipleChoice(opts);
}
};