Skip to content
Snippets Groups Projects
Commit a20aa7f1 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Merge branch '3-qcu-features'

parents 37c08da8 c0265c28
No related branches found
No related tags found
No related merge requests found
#correct-indic {
border-radius: 8px;
padding: 16px;
transition: opacity 0.1s ease-in-out;
&.hidden {
display: block;
opacity: 0;
}
p {
margin: 0;
}
.label {
font-weight: bold;
}
&.correct {
background: #dfd;
.label {
color: var(--sd-rating-good-color);
}
}
&.incorrect {
background: #fdd;
}
.label {
color: var(--sd-rating-bad-color);
}
}
#sv-nav-complete {
display: none;
}
p#gapfill-container {
white-space: pre-wrap;
line-height: 3em;
}
select.sd-dropdown.inline-dropdown {
display: inline-block;
width: fit-content;
padding: 8px;
}
\ No newline at end of file
function showCorrectIndic(correct) { /**
let indic = document.getElementById("correct-indic"); * Checks whether a question is correct, and update the correct indicator accordingly.
if (correct === undefined) { */
indic.innerText = ""; function checkQuestion(question) {
} else if (correct) { if (question.isAnswerCorrect()) {
indic.innerText = "Correct"; correctIndic.node.className = "correct"
indic.classList.add("correct"); correctIndic.labelNode.innerText = "Correct";
correctIndic.commentNode.innerText = question.getPropertyValue("correctComment", "");
} else { } else {
indic.innerText = "Incorrect"; correctIndic.node.className = "incorrect";
indic.classList.remove("correct"); correctIndic.labelNode.innerText = "Incorrect";
correctIndic.commentNode.innerText = question.getPropertyValue("incorrectComment", "");
} }
console.log("question = ", question);
console.log(" correct = ", question.isAnswerCorrect());
}
function clearQuestion(question) {
question.value = undefined;
correctIndic.node.className = "hidden";
} }
let correctIndic;
$(function () { $(function () {
correctIndic = {
node: document.getElementById("correct-indic"),
commentNode: document.querySelector("#correct-indic .comment"),
labelNode: document.querySelector("#correct-indic .label")
};
// Register our custom question types // Register our custom question types
Survey.CustomWidgetCollection.Instance.add(gapfillSelectWidget, gapfillSelectWidget.name); Survey.CustomWidgetCollection.Instance.add(gapfillSelectWidget, gapfillSelectWidget.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 // Load survey model from JSON
const survey = new Survey.Model(jsonStatic); const survey = new Survey.Model(jsonStatic);
// Add "Check answers" button // Add "Check answers" button
survey.addNavigationItem({ survey.addNavigationItem({
id: "sv-nav-clear-page", id: "sv-nav-check",
title: "Check", title: "Vérifier",
action: () => { action: () => {
survey.currentPage.questions.forEach((question) => { checkQuestion(survey.currentPage.questions[0]);
console.log("question = ", question); },
console.log(" correct = ", question.isAnswerCorrect()); css: "nav-button",
showCorrectIndic(question.isAnswerCorrect()); 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]);
}, },
css: "nav-button", css: "nav-button",
innerCss: "sd-btn nav-input" innerCss: "sd-btn nav-input"
......
#correct-indic {
color: var(--sd-rating-bad-color);
font-weight: bold;
}
#correct-indic.correct {
color: var(--sd-rating-good-color);
}
p#gapfill-container {
white-space: pre-wrap;
line-height: 3em;
}
select.sd-dropdown.inline-dropdown {
display: inline-block;
width: fit-content;
padding: 8px;
}
\ No newline at end of file
{{/* Included by the theme in the <head> tag */}} {{/* Included by the theme in the <head> tag */}}
{{/* Get CSS as resource and minify */}}
{{- $css := resources.Get "style.css" | resources.Minify }}
<link rel="stylesheet" href="{{- $css.RelPermalink -}}">
{{/* if a quiz.json exists in the page resources, load SurveyJS */}} {{/* if a quiz.json exists in the page resources, load SurveyJS */}}
{{ with .Resources.GetMatch "quiz.json" }} {{ with .Resources.GetMatch "quiz.json" }}
......
...@@ -3,7 +3,10 @@ and inserts a SurveyJS quiz using this JSON */ -}} ...@@ -3,7 +3,10 @@ and inserts a SurveyJS quiz using this JSON */ -}}
{{ with $.Page.Resources.GetMatch "quiz.json" }} {{ with $.Page.Resources.GetMatch "quiz.json" }}
<div id="surveyContainer"></div> <div id="surveyContainer"></div>
<p id="correct-indic"></p> <div id="correct-indic" class="hidden">
<p class="label"></p>
<p class="comment"></p>
</div>
<script type="text/javascript"> <script type="text/javascript">
const jsonStatic = {{ .Content | safeJS }}; const jsonStatic = {{ .Content | safeJS }};
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment