MediaWiki:Gadget-wix-quiz.js: Difference between revisions

Content deleted Content added
Created page with "/* ================================================================ WIX-QUIZ.JS — Wiki Interactive Experience: Quiz Engine ================================================================ Depends on: ext.gadget.wix-core (window.wix must exist) Finds every container with data-wix-module="quiz", reads the question blocks from the DOM, and manages the full lifecycle: sequencing → answer selection → feedback → next → results. Content-blind:..."
 
No edit summary
 
Line 14:
─────────────────────────────────
Container: [data-wix-module="quiz"]
Question: [data-wix-question="...question text..."] one per question
data-wix-correct letter of correct answer (a/b/c/d)
data-wix-topic topic label (optional)
Line 68:
return {
topic: wix.data( block, 'wix-topic', '' ),
question: wixblock.datagetAttribute( block, 'data-wix-question', ) || '' ),
correct: ( wix.data( block, 'wix-correct', 'a' ) ).toLowerCase(),
explanation: wix.data( block, 'wix-explanation', '' ),
Line 141:
var feedback = wix.buildFeedback( card );
 
// Nav bar — Next button hidden until answer chosen
var isLast = state.step === questions.length - 1;
var nav = wix.buildNav( container, {
Line 151:
} );
 
// Hold answer data locally — committing to state triggers a full
// Answer handler
// re-render, so we only do that when the user clicks Next.
var answered = false;
var pendingScore = state.score;
var newAnswerspendingAnswers = state.answers.concatslice( [ {);
 
wix.on( optionsList, 'click', '.wix-option', function ( target ) {
if ( answered ) {
Line 162 ⟶ 166:
var isCorrect = chosen === q.correct;
 
// DisableRecord allanswer optionslocally
pendingScore score: = state.score + ( isCorrect ? 1 : 0 ),;
pendingAnswers = state.answers.concat( [ {
step: state.step,
chosen: chosen,
correct: isCorrect
} ] );
 
// Disable all options and highlight correct / chosen-wrong
wix.qsa( '.wix-option', optionsList ).forEach( function ( btn ) {
btn.disabled = true;
Line 185 ⟶ 197:
}
 
// RecordReveal answerNext and show Nextbutton
var newAnswers = state.answers.concat( [ {
step: state.step,
chosen: chosen,
correct: isCorrect
} ] );
container._wixQuizState.set( {
score: state.score + ( isCorrect ? 1 : 0 ),
answers: newAnswers
} );
nav.show( 'next' );
} );
 
// Next: commit accumulated state and advance step
nav.on( 'next', function () {
container._wixQuizState.set( { step: state.step + 1 } );
step: state.step + 1,
score: pendingScore,
answers: newAnswerspendingAnswers
} );
} );
}