Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MACAO Hugo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MACAO
MACAO Hugo
Commits
3018e1c5
Commit
3018e1c5
authored
Jun 17, 2024
by
Eliott Sammier
Browse files
Options
Downloads
Patches
Plain Diff
Fix answer checking regression
parent
0e2a804d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
macao/assets/quiz.js
+8
-4
8 additions, 4 deletions
macao/assets/quiz.js
with
8 additions
and
4 deletions
macao/assets/quiz.js
+
8
−
4
View file @
3018e1c5
...
...
@@ -31,8 +31,10 @@ let gapfillSelectWidget = {
// The gap-fill text is made of segments, which are either plain pieces
// of text (strings) or "gaps" with a few options to select (string arrays).
// We append these to build the text, turning strings into <span>s and
// gaps into <select>s
// gaps into <select>
dropdown
s
let
nbGaps
=
0
;
let
segmentElems
=
new
DocumentFragment
();
// a bit faster than mutating the DOM all the time
let
selectTemplate
=
document
.
getElementById
(
"
template-select
"
).
content
.
firstChild
;
for
(
segment
of
question
.
jsonObj
.
segments
)
{
if
(
typeof
segment
===
'
string
'
||
segment
instanceof
String
)
{
segmentElem
=
document
.
createElement
(
"
span
"
);
...
...
@@ -40,7 +42,7 @@ let gapfillSelectWidget = {
}
else
if
(
segment
instanceof
Array
)
{
// It's a gap
// Create the <select> element
segmentElem
=
document
.
getElementById
(
"
template-select
"
).
content
.
firstChild
.
cloneNode
(
true
);
segmentElem
=
selectTemplate
.
cloneNode
(
true
);
segmentElem
.
setAttribute
(
"
data-index
"
,
nbGaps
);
// The node knows its index
// Create and append options
for
(
opt
of
segment
)
{
...
...
@@ -51,14 +53,16 @@ let gapfillSelectWidget = {
// Add listener to update the question's value when the selector's value changes
segmentElem
.
addEventListener
(
"
change
"
,
(
e
)
=>
{
// The select node knows its index, therefore is able to update the question value at the correct index
this
.
question
.
value
[
parseInt
(
e
.
target
.
getAttribute
(
"
data-index
"
))]
=
e
.
target
.
value
;
question
.
value
[
parseInt
(
e
.
target
.
getAttribute
(
"
data-index
"
))]
=
e
.
target
.
value
;
});
nbGaps
++
;
}
// Add segment
el
.
appendChild
(
segmentElem
);
segmentElems
.
appendChild
(
segmentElem
);
}
question
.
value
=
new
Array
(
nbGaps
);
// Finally add everything to the DOM
el
.
appendChild
(
segmentElems
);
},
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment