-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.html
More file actions
263 lines (233 loc) · 11.5 KB
/
quiz.html
File metadata and controls
263 lines (233 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en" x-data="darkMode()" x-init="init()" :class="{ 'dark': isDark }">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Yoga Quiz Frames</title>
<!-- Tailwind CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Tell Tailwind to use class-based dark mode -->
<script>
tailwind.config = {
darkMode: 'class',
}
</script>
<!-- Alpine -->
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
</head>
<body class="bg-gray-100 dark:bg-gray-900 p-4 sm:p-6 transition-colors duration-300">
<!-- Top bar with Dark Mode Switch -->
<header class="flex justify-between items-center max-w-4xl mx-auto mb-6">
<h1 class="text-2xl sm:text-xl font-bold text-gray-900 dark:text-gray-100">🧘 Yoga Learning System</h1>
<button @click="toggle()"
class="p-2 rounded-full bg-gray-200 dark:bg-gray-700 hover:scale-110 transition"
x-tooltip="Toggle Dark Mode">
<!-- Sun Icon -->
<!-- Sun Icon (Light Mode) -->
<svg x-show="!isDark" xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6 text-yellow-500" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 3.75a.75.75 0 01.75-.75h.75a.75.75 0 010 1.5h-.75A.75.75 0 0112 3.75zM6.22 6.22a.75.75 0 011.06 0l.53.53a.75.75 0 01-1.06 1.06l-.53-.53a.75.75 0 010-1.06zm11.31 0a.75.75 0 010 1.06l-.53.53a.75.75 0 01-1.06-1.06l.53-.53a.75.75 0 011.06 0zM12 6.75a5.25 5.25 0 110 10.5 5.25 5.25 0 010-10.5zm8.25 5.25a.75.75 0 01-.75.75h-.75a.75.75 0 010-1.5h.75a.75.75 0 01.75.75zM6.75 12a.75.75 0 01-.75-.75v-.75a.75.75 0 011.5 0v.75a.75.75 0 01-.75.75zM17.78 17.78a.75.75 0 01-1.06 0l-.53-.53a.75.75 0 111.06-1.06l.53.53a.75.75 0 010 1.06zM6.22 17.78a.75.75 0 010-1.06l.53-.53a.75.75 0 111.06 1.06l-.53.53a.75.75 0 01-1.06 0zM12 19.5a.75.75 0 01.75.75v.75a.75.75 0 01-1.5 0v-.75a.75.75 0 01.75-.75z"/>
</svg>
<!-- Moon Icon (Dark Mode) -->
<svg x-show="isDark" xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6 text-gray-200" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round"
d="M21 12.79A9 9 0 1111.21 3
7 7 0 0021 12.79z" />
</svg>
</button>
</header>
<div x-data="quizApp()" x-init="loadQuestions()"
class="max-w-4xl mx-auto space-y-6">
<!-- Frames Loop -->
<template x-for="frame in frames" :key="frame.id">
<div x-show="activeFrame === frame.id && !completed"
class="bg-white dark:bg-gray-800 p-4 sm:p-6 rounded-xl shadow-md transition-colors duration-300">
<!-- STEP 1: Frame Content -->
<div x-show="phase === 'content'">
<h2 class="text-lg sm:text-xl font-bold mb-4 text-gray-900 dark:text-gray-100 text-center">
📖 Frame <span x-text="frame.id"></span>
</h2>
<!-- Frame Content Loaded Dynamically -->
<div x-html="frameContent" class="text-gray-700 dark:text-gray-300"></div>
<button @click="phase = 'questions'"
class="mt-4 w-full sm:w-auto bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
Next: Questions
</button>
</div>
<!-- STEP 2: Frame Questions -->
<div x-show="phase === 'questions'">
<h3 class="text-xl sm:text-lg font-semibold mb-4 text-center text-gray-900 dark:text-gray-100">
Questions for Frame <span x-text="frame.id"></span>
</h3>
<template x-for="q in getQuestions(frame.id)" :key="q.id">
<div class="mb-6 border-b pb-4 border-gray-200 dark:border-gray-700">
<p class="font-semibold mb-2 text-gray-800 dark:text-gray-200" x-text="q.question"></p>
<!-- Options -->
<template x-for="opt in ['ans1','ans2','ans3','ans4']">
<label class="block cursor-pointer p-2 rounded-lg mb-1 transition"
:class="getOptionClass(q, opt)">
<input type="radio"
:name="'q-'+q.id"
:value="opt"
x-model="answers[q.id]"
class="mr-2"
:disabled="q.locked"
@change="autoSubmit(q)">
<span class="text-gray-700 dark:text-gray-300" x-text="q[opt]"></span>
</label>
</template>
<!-- Show feedback -->
<template x-if="q.locked && answers[q.id]">
<p class="mt-2 text-sm"
:class="answers[q.id] === q.correct ? 'text-green-600' : 'text-red-500'">
<span x-text="q['context' + answers[q.id].slice(-1)]"></span>
</p>
</template>
</div>
</template>
<!-- Buttons -->
<div class="flex flex-col sm:flex-row gap-3 mt-6">
<button @click="resetWrongAnswers(frame.id)"
class="flex-1 sm:flex-none bg-yellow-500 hover:bg-yellow-600 text-white px-4 py-2 rounded-lg transition">
Reset Wrong Answers
</button>
<button @click="nextFrame()"
class="flex-1 sm:flex-none bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition disabled:opacity-50"
:disabled="!allCorrect(frame.id)">
Next Frame
</button>
</div>
</div>
</div>
</template>
<!-- Final Result -->
<div x-show="completed"
class="bg-white dark:bg-gray-800 p-6 sm:p-8 rounded-xl shadow-xl text-center transition-colors duration-300">
<h2 class="text-xl sm:text-2xl font-bold mb-4 text-gray-900 dark:text-gray-100">🎉 Quiz Completed!</h2>
<p class="text-lg text-gray-700 dark:text-gray-300 mb-4">
Thank you for participating in the <strong>Yoga Learning System</strong>. 🌿
Your dedication to learning and self-growth is truly appreciated!
</p>
<p class="text-md text-gray-600 dark:text-gray-400">
Keep practicing, stay curious, and continue your journey of knowledge. 🙏
</p>
</div>
</div>
<!-- Footer -->
<footer class="mt-10 text-center text-gray-600 dark:text-gray-400 text-sm">
<p class="flex items-center justify-center space-x-2">
<span>Developed with</span>
<svg class="w-5 h-5 text-red-600 animate-pulse" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd"
d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4
4 0 115.656 5.656L10 18.657l-6.828-6.829a4
4 0 010-5.656z" clip-rule="evenodd" />
</svg>
<span>by <a href="https://vijaygoswami.com" target="_blank"
class="underline hover:text-blue-600 dark:hover:text-blue-400">Vijay Goswami</a> &
<a href="https://attrixtech.com" target="_blank"
class="underline hover:text-blue-600 dark:hover:text-blue-400">Attrix Technologies</a></span>
</p>
</footer>
<script>
// 🌙 Dark Mode Controller
function darkMode() {
return {
isDark: false,
init() {
this.isDark = localStorage.getItem('darkMode') === 'true' ||
(!('darkMode' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
},
toggle() {
this.isDark = !this.isDark;
localStorage.setItem('darkMode', this.isDark);
}
}
}
// 🧩 Quiz App Logic
function quizApp() {
return {
frames: Array.from({length: 21}, (_, i) => ({id: i + 1})),
questions: [],
answers: {},
activeFrame: 1,
phase: 'content',
completed: false,
frameContent: "",
correctCount: 0,
wrongCount: 0,
totalQuestions: 0,
async loadQuestions() {
const res = await fetch('questions.json');
this.questions = await res.json();
this.totalQuestions = this.questions.length;
this.questions.forEach(q => q.locked = false);
const params = new URLSearchParams(window.location.search);
const frameParam = parseInt(params.get('frame'));
if (frameParam && frameParam >= 1 && frameParam <= this.frames.length) {
this.activeFrame = frameParam;
}
this.loadFrameContent();
},
async loadFrameContent() {
try {
let res = await fetch(`frames/frame${this.activeFrame}.html`);
this.frameContent = await res.text();
const url = new URL(window.location);
url.searchParams.set("frame", this.activeFrame);
window.history.replaceState({}, "", url);
} catch (e) {
console.error("Error loading frame:", e);
this.frameContent = `<p class="text-red-600">Frame ${this.activeFrame} could not be loaded.</p>`;
}
},
getQuestions(frameId) {
return this.questions.filter(q => q.frame_id === frameId);
},
getOptionClass(q, opt) {
if (!q.locked) return 'hover:bg-gray-100 dark:hover:bg-gray-700 rounded px-2 py-1';
if (this.answers[q.id] === opt && this.answers[q.id] !== q.correct) {
return 'bg-red-100 text-red-800 font-semibold rounded px-2 py-1';
}
return 'opacity-70 px-2 py-1';
},
autoSubmit(q) {
if (q.locked) return;
if (!this.answers[q.id]) return;
if (this.answers[q.id] === q.correct) {
this.correctCount++;
} else {
this.wrongCount++;
}
q.locked = true;
},
resetWrongAnswers(frameId) {
let frameQs = this.getQuestions(frameId);
frameQs.forEach(q => {
if (q.locked && this.answers[q.id] !== q.correct) {
this.answers[q.id] = null;
q.locked = false;
this.wrongCount = Math.max(0, this.wrongCount - 1);
}
});
},
allCorrect(frameId) {
let frameQs = this.getQuestions(frameId);
return frameQs.every(q => this.answers[q.id] === q.correct);
},
async nextFrame() {
this.phase = 'content';
if (this.activeFrame < this.frames.length) {
this.activeFrame++;
await this.loadFrameContent();
} else {
this.completed = true;
}
}
}
}
</script>
</body>
</html>