Skip to content

Commit

Permalink
refactor FOUC strategy with wf-cloak attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
learyjk committed Jan 10, 2025
1 parent d020541 commit 69a991d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
88 changes: 87 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/components/mc-quiz/mc-quiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export class MultipleChoiceQuiz {
return;
}

// Hide feedback elements initially
this.correctWrapperElement.style.display = 'none';
this.incorrectWrapperElement.style.display = 'none';

// Attach event listener
this.submitButton?.addEventListener('click', () => this.checkAnswer());
}
Expand Down Expand Up @@ -79,14 +75,14 @@ export class MultipleChoiceQuiz {

private showFeedback(isCorrect: boolean): void {
// Show the correct or incorrect wrapper based on the answer
this.questionWrapperElement.style.display = 'none';
this.correctWrapperElement.style.display = isCorrect ? 'block' : 'none';
this.incorrectWrapperElement.style.display = isCorrect ? 'none' : 'block';
this.questionWrapperElement.setAttribute('wf-cloak', '1');

if (this.quizParentElement) {
if (isCorrect) {
this.correctWrapperElement.removeAttribute('wf-cloak');
this.quizParentElement.classList.add(MultipleChoiceQuiz.CORRECT_ANSWER_CLASS_COMBO);
} else {
this.incorrectWrapperElement.removeAttribute('wf-cloak');
this.quizParentElement.classList.add(MultipleChoiceQuiz.INCORRECT_ANSWER_CLASS_COMBO);
}
}
Expand Down

0 comments on commit 69a991d

Please sign in to comment.