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
David Beniamine
MACAO Hugo
Commits
3292408c
Commit
3292408c
authored
7 months ago
by
David Rouquet
Browse files
Options
Downloads
Patches
Plain Diff
Make quiz.js work with several questions
parent
12460eec
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
+28
-48
28 additions, 48 deletions
macao/assets/quiz.js
with
28 additions
and
48 deletions
macao/assets/quiz.js
+
28
−
48
View file @
3292408c
/**
* Checks whether a question
is
correct
,
an
d update the correct indicator accordingly
.
* Checks whether a
ll
question
s are
correct
ly
an
swered and displays the overall feedback
.
*/
function
checkQuestion
(
question
)
{
if
(
question
.
isAnswerCorrect
())
{
correctIndic
.
node
.
className
=
"
correct
"
// FIXME: this inserts raw HTML (see onTextMarkdown callback)
correctIndic
.
commentNode
.
innerHTML
=
question
.
getPropertyValue
(
"
correctComment
"
,
""
);
function
checkAllQuestions
(
questions
,
surveyConfig
)
{
let
allCorrect
=
true
;
questions
.
forEach
((
question
)
=>
{
if
(
!
question
.
isAnswerCorrect
())
{
allCorrect
=
false
;
}
});
if
(
allCorrect
)
{
correctIndic
.
node
.
className
=
"
correct
"
;
correctIndic
.
commentNode
.
innerHTML
=
surveyConfig
.
correctComment
||
"
All answers are correct!
"
;
}
else
{
correctIndic
.
node
.
className
=
"
incorrect
"
;
correctIndic
.
commentNode
.
innerHTML
=
question
.
getPropertyValue
(
"
incorrectComment
"
,
""
)
;
correctIndic
.
commentNode
.
innerHTML
=
surveyConfig
.
incorrectComment
||
"
Some answers are incorrect!
"
;
}
console
.
log
(
"
question =
"
,
question
);
console
.
log
(
"
correct =
"
,
question
.
isAnswerCorrect
());
}
function
clearQuestion
(
question
)
{
/**
* Clears all answers and resets the feedback indicator.
*/
function
clearAllQuestions
(
questions
)
{
questions
.
forEach
((
question
)
=>
{
question
.
value
=
undefined
;
});
correctIndic
.
node
.
className
=
"
hidden
"
;
correctIndic
.
commentNode
.
innerHTML
=
""
;
}
let
correctIndic
;
...
...
@@ -27,66 +39,34 @@ $(function () {
commentNode
:
document
.
querySelector
(
"
#correct-indic .comment
"
),
};
// Register our custom question types
Survey
.
CustomWidgetCollection
.
Instance
.
add
(
gapfillSelectWidget
,
gapfillSelectWidget
.
name
);
Survey
.
CustomWidgetCollection
.
Instance
.
add
(
gapfillOpenWidget
,
gapfillOpenWidget
.
name
);
// Register custom properties for quiz correction comments
Survey
.
Serializer
.
addProperty
(
"
question
"
,
{
name
:
"
correctComment
"
,
type
:
"
text
"
});
Survey
.
Serializer
.
addProperty
(
"
question
"
,
{
name
:
"
incorrectComment
"
,
type
:
"
text
"
});
// Load survey model from JSON
const
survey
=
new
Survey
.
Model
(
jsonStatic
);
// Instantiate `markdown-it`
const
converter
=
markdownit
({
html
:
true
// Support HTML tags in the source (unsafe, see documentation)
});
survey
.
onTextMarkdown
.
add
((
_
,
options
)
=>
{
console
.
log
(
"
On text markdown
"
)
// Convert Markdown to HTML
let
str
=
converter
.
renderInline
(
options
.
text
);
// ...
// Sanitize the HTML markup using a third-party library here
// ...
// Set HTML markup to render
options
.
html
=
str
;
});
// Add "Check answers" button
survey
.
addNavigationItem
({
id
:
"
sv-nav-check
"
,
title
:
"
Vérifier
"
,
action
:
()
=>
{
checkQuestion
(
survey
.
currentPage
.
questions
[
0
]
);
check
All
Question
s
(
survey
.
currentPage
.
questions
,
jsonStatic
);
},
css
:
"
nav-button
"
,
innerCss
:
"
sd-btn sd-btn--action nav-input
"
});
// Add "Clear answers" button
survey
.
addNavigationItem
({
id
:
"
sv-nav-clear
"
,
title
:
"
Effacer
"
,
action
:
()
=>
{
clearQuestion
(
survey
.
currentPage
.
questions
[
0
]
);
clear
All
Question
s
(
survey
.
currentPage
.
questions
);
},
css
:
"
nav-button
"
,
innerCss
:
"
sd-btn nav-input
"
});
survey
.
onValueChanged
.
add
((
_
,
options
)
=>
{
console
.
log
(
options
)
});
// Apply theme
survey
.
applyTheme
(
SurveyTheme
.
DefaultLightPanelless
);
// Inflate the survey in the page
$
(
"
#surveyContainer
"
).
Survey
({
model
:
survey
});
});
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
sign in
to comment