-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwriting_part1.html
More file actions
466 lines (407 loc) · 20.3 KB
/
writing_part1.html
File metadata and controls
466 lines (407 loc) · 20.3 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Writing - Part 1</title>
<link rel="stylesheet" href="css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="icon" href="img/favicon.png" type="image/x-icon">
<!-- 1. Tích hợp CSS của Driver.js -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/driver.css"/>
<style>
/* CSS cho nút Help/Tour */
.tour-btn {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #fff;
border: 1px solid #ddd;
color: #333;
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
z-index: 999;
font-size: 24px;
transition: transform 0.2s, background-color 0.2s;
}
.tour-btn:hover {
transform: scale(1.1);
background-color: #f8f9fa;
}
/* Tùy chỉnh giao diện Popover của Driver.js */
.driver-popover.driverjs-theme {
background-color: #fff;
color: #333;
border-radius: 8px;
padding: 15px;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
max-width: 300px;
}
.driver-popover.driverjs-theme .driver-popover-title {
font-size: 18px;
font-weight: 700;
margin-bottom: 8px;
color: var(--primary-blue, #007bff);
}
.driver-popover.driverjs-theme .driver-popover-description {
font-size: 14px;
line-height: 1.5;
color: #555;
}
.driver-popover.driverjs-theme button {
background-color: var(--primary-blue, #007bff);
color: #fff;
text-shadow: none;
border: none;
border-radius: 4px;
padding: 6px 12px;
}
/* CSS cho phần Sample Answer */
.sample-answer-wrapper {
margin-top: 20px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #28a745;
font-size: 0.95em;
}
.sample-answer-item {
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.sample-answer-item:last-child {
border-bottom: none;
margin-bottom: 0;
padding-bottom: 0;
}
.sample-answer-item strong {
color: #155724;
display: block;
margin-bottom: 4px;
}
.card-actions {
margin-top: 20px;
text-align: center;
border-top: 1px dashed #dee2e6;
padding-top: 20px;
}
.show-sample-btn {
background-color: #6c757d;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
font-weight: 500;
}
.show-sample-btn:hover {
background-color: #5a6268;
}
</style>
</head>
<body>
<header id="header-placeholder"></header>
<!-- 2. Nút kích hoạt lại Tour -->
<div class="tour-btn" id="restart-tour" title="Hướng dẫn sử dụng">❓</div>
<div class="content-pusher">
<div class="container">
<div class="page-intro">
<h1>Writing - Part 1</h1>
<p>Chọn một chủ đề và bắt đầu luyện tập</p>
</div>
<!-- HỘP GIẢI THÍCH MỚI -->
<div class="explanation-box">
<h3>💡 Phương pháp học & Lưu ý</h3>
<p>Bạn có 3 phút để trả lời 5 câu hỏi. <strong>Lưu ý quan trọng:</strong> Hệ thống thi thật sẽ <strong>ngăn bạn nhập tiếp</strong> khi số từ vượt quá giới hạn (thường là 5 từ, ở đây là 10 từ).</p>
<p><strong>Tính năng:</strong> Đồng hồ sẽ <strong>tự động chạy</strong> ngay khi bạn gõ ký tự đầu tiên. Hệ thống cũng tự động lưu bài làm và cắt bớt nếu viết quá dài.</p>
</div>
<!-- BẢNG ĐIỀU KHIỂN CHỌN CHỦ ĐỀ -->
<div id="topic-selector-grid" class="topic-grid">
<!-- Các nút chọn chủ đề sẽ được chèn vào đây -->
</div>
<main id="writing-container">
<!-- Chỉ một bài tập được hiển thị tại một thời điểm -->
</main>
</div>
<footer id="footer-placeholder"></footer>
</div>
<script src="js/main.js"></script>
<script src="js/data-writing-part1.js"></script>
<!-- 3. Tích hợp Script của Driver.js -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/driver.js.iife.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const selectorContainer = document.getElementById('topic-selector-grid');
const contentContainer = document.getElementById('writing-container');
const topics = writingPart1Data;
if (!topics || topics.length === 0) {
contentContainer.innerHTML = `<p class="error">Không có dữ liệu cho Writing Part 1.</p>`;
return;
}
let activeTimerInterval; // Biến để lưu trữ timer đang chạy
// TẠO NÚT VÀ CARD CHO MỖI CHỦ ĐỀ
topics.forEach((topic, index) => {
// Tạo nút chọn
const button = document.createElement('button');
button.className = 'topic-selector-btn';
button.textContent = `Chủ đề ${index + 1}`;
button.dataset.target = `#${topic.id}`;
selectorContainer.appendChild(button);
// Tạo card nội dung
const card = document.createElement('div');
card.className = 'quiz-card writing-card';
card.id = topic.id;
const storageKey = `writing_part1_${topic.id}`;
let questionsHTML = `<div class="card-header"><h2>${topic.title}</h2></div>`;
let sampleAnswersHTML = ''; // Chuỗi HTML chứa các câu trả lời mẫu
// topic.questions bây giờ là mảng objects {question, sample}
topic.questions.forEach((qObj, i) => {
// Tạo ô nhập liệu
questionsHTML += `
<div class="writing-prompt">
<label for="${topic.id}-answer-${i}">${i + 1}. ${qObj.question}</label>
<textarea id="${topic.id}-answer-${i}" rows="2" data-index="${i}" placeholder="Your answer (1-10 words)..."></textarea>
<div class="word-count-container"><span class="word-count">0/10 words</span></div>
</div>
`;
// Tạo dòng đáp án mẫu tương ứng
sampleAnswersHTML += `
<div class="sample-answer-item">
<strong>Câu ${i + 1}: ${qObj.question}</strong>
<span style="color: #333;">Suggest: "${qObj.sample}"</span>
</div>
`;
});
card.innerHTML = `
<div class="writing-timer-bar">
<button class="action-btn start-writing-btn">Bắt đầu tính giờ (3 phút)</button>
<div class="timer-display">03:00</div>
</div>
<div class="writing-content">${questionsHTML}</div>
<!-- Phần hiển thị nút và đáp án mẫu -->
<div class="card-actions">
<button class="show-sample-btn">📖 Xem câu trả lời mẫu</button>
</div>
<div class="sample-answer-wrapper" style="display: none;">
<h4 style="margin-top:0; color:#28a745;">Câu trả lời tham khảo:</h4>
${sampleAnswersHTML}
</div>
`;
contentContainer.appendChild(card);
});
const allButtons = selectorContainer.querySelectorAll('.topic-selector-btn');
const allCards = contentContainer.querySelectorAll('.writing-card');
// HÀM HIỂN THỊ CHỦ ĐỀ
function showTopic(targetId) {
allCards.forEach(card => card.classList.remove('active'));
allButtons.forEach(btn => btn.classList.remove('active'));
const targetCard = document.querySelector(targetId);
const targetButton = selectorContainer.querySelector(`[data-target='${targetId}']`);
if (targetCard) targetCard.classList.add('active');
if (targetButton) targetButton.classList.add('active');
// Dừng timer cũ nếu có
if (activeTimerInterval) clearInterval(activeTimerInterval);
// Reset tất cả các timer bar
allCards.forEach(c => {
const btn = c.querySelector('.start-writing-btn');
const display = c.querySelector('.timer-display');
if (btn) {
btn.disabled = false;
btn.textContent = 'Bắt đầu tính giờ (3 phút)';
}
if (display) display.textContent = '03:00';
});
}
// LOGIC LƯU VÀ TẢI BÀI
function loadAnswers(card) {
const storageKey = `writing_part1_${card.id}`;
const savedAnswers = JSON.parse(localStorage.getItem(storageKey));
if (savedAnswers) {
savedAnswers.forEach((answer, index) => {
const textarea = card.querySelector(`#${card.id}-answer-${index}`);
if (textarea) {
textarea.value = answer;
// Trigger sự kiện input để cập nhật đếm từ ngay khi load
textarea.dispatchEvent(new Event('input', { bubbles: true }));
}
});
}
}
allCards.forEach(loadAnswers); // Tải bài làm cho tất cả các card
// GÁN SỰ KIỆN CHỌN CHỦ ĐỀ
selectorContainer.addEventListener('click', function (e) {
if (e.target.classList.contains('topic-selector-btn')) showTopic(e.target.dataset.target);
});
// GÁN SỰ KIỆN XỬ LÝ NHẬP LIỆU (Word count & Hard Limit & Auto-Start Timer)
contentContainer.addEventListener('input', function (e) {
if (e.target.tagName === 'TEXTAREA') {
const card = e.target.closest('.writing-card');
// === LOGIC MỚI: TỰ ĐỘNG BẮT ĐẦU TÍNH GIỜ KHI GÕ ===
const startBtn = card.querySelector('.start-writing-btn');
// Kiểm tra nếu nút tồn tại và chưa bị disable (nghĩa là chưa chạy)
if (startBtn && !startBtn.disabled) {
startBtn.click(); // Kích hoạt sự kiện click để bắt đầu timer
}
// =================================================
const storageKey = `writing_part1_${card.id}`;
const MAX_WORDS = 10; // Giới hạn cứng số từ (mô phỏng bài thi thật)
let val = e.target.value;
let words = val.trim().split(/\s+/).filter(word => word.length > 0);
// --- LOGIC CHẶN NHẬP LIỆU (HARD LIMIT) ---
if (words.length > MAX_WORDS) {
// Nếu vượt quá, cắt lấy đúng số từ quy định và gán ngược lại
// Điều này sẽ ngăn người dùng gõ thêm từ thứ 11
e.target.value = words.slice(0, MAX_WORDS).join(" ");
// Cập nhật lại mảng words để hiển thị đúng số lượng
words = e.target.value.trim().split(/\s+/).filter(word => word.length > 0);
}
// Cập nhật đếm từ
const wordCountSpan = e.target.nextElementSibling.querySelector('.word-count');
wordCountSpan.textContent = `${words.length}/${MAX_WORDS} words`;
// Style cảnh báo khi đạt giới hạn
if (words.length >= MAX_WORDS) {
wordCountSpan.style.color = '#dc3545'; // Màu đỏ
wordCountSpan.style.fontWeight = 'bold';
} else {
wordCountSpan.style.color = '';
wordCountSpan.style.fontWeight = '';
}
// Lưu bài
const allTextareas = card.querySelectorAll('textarea');
const answersToSave = Array.from(allTextareas).map(ta => ta.value);
localStorage.setItem(storageKey, JSON.stringify(answersToSave));
}
});
// GÁN SỰ KIỆN CLICK (Timer & Show Sample)
contentContainer.addEventListener('click', function (e) {
// Xử lý nút Timer
if (e.target.classList.contains('start-writing-btn')) {
if (activeTimerInterval) clearInterval(activeTimerInterval); // Dừng timer khác nếu đang chạy
const button = e.target;
const timerBar = button.closest('.writing-timer-bar');
const timerDisplay = timerBar.querySelector('.timer-display');
const card = button.closest('.writing-card');
button.disabled = true;
button.textContent = 'Đang tính giờ...';
let timeInSeconds = 180;
activeTimerInterval = setInterval(() => {
timeInSeconds--;
const minutes = Math.floor(timeInSeconds / 60);
const seconds = timeInSeconds % 60;
timerDisplay.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
if (timeInSeconds <= 0) {
clearInterval(activeTimerInterval);
timerDisplay.textContent = "Hết giờ!";
alert("Hết giờ làm bài!");
card.querySelectorAll('textarea').forEach(ta => ta.disabled = true);
}
}, 1000);
}
// Xử lý nút Xem đáp án mẫu
if (e.target.classList.contains('show-sample-btn')) {
const button = e.target;
const wrapper = button.closest('.card-actions').nextElementSibling;
const isVisible = wrapper.style.display === 'block';
wrapper.style.display = isVisible ? 'none' : 'block';
button.textContent = isVisible ? '📖 Xem câu trả lời mẫu' : '🙈 Ẩn câu trả lời mẫu';
}
});
// HIỂN THỊ CHỦ ĐỀ ĐẦU TIÊN
if (allButtons.length > 0) showTopic(allButtons[0].dataset.target);
// --- KÍCH HOẠT TOUR HƯỚNG DẪN ---
setTimeout(initWritingPart1Tour, 800);
});
// HÀM KHỞI TẠO TOUR CHO WRITING PART 1
function initWritingPart1Tour() {
const driver = window.driver.js.driver;
const driverObj = driver({
showProgress: true,
animate: true,
doneBtnText: 'Đã hiểu',
nextBtnText: 'Tiếp theo',
prevBtnText: 'Quay lại',
popoverClass: 'driverjs-theme',
steps: [
{
element: '.explanation-box',
popover: {
title: 'Phương pháp & Lưu ý',
description: 'Bạn có 3 phút cho 5 câu hỏi. Hệ thống sẽ **tự động ngăn** không cho bạn nhập thêm khi đã đủ số từ (mô phỏng thi thật).',
side: "bottom",
align: 'center'
}
},
{
element: '#topic-selector-grid',
popover: {
title: 'Chọn đề bài',
description: 'Danh sách các chủ đề luyện tập Writing Part 1.',
side: "top",
align: 'center'
}
},
{
element: '.writing-card.active .writing-content',
popover: {
title: 'Khu vực làm bài',
description: 'Nhập câu trả lời ngắn gọn vào đây. Đồng hồ sẽ **tự động chạy** ngay khi bạn gõ ký tự đầu tiên.',
side: "top",
align: 'center'
}
},
{
element: '.writing-card.active .word-count-container',
popover: {
title: 'Giới hạn từ',
description: 'Bộ đếm này sẽ chuyển sang màu đỏ khi bạn đạt giới hạn (10 từ). Khi đó bạn sẽ không thể gõ thêm từ mới được nữa.',
side: "left",
align: 'center'
}
},
{
element: '.writing-card.active .start-writing-btn',
popover: {
title: 'Đồng hồ',
description: 'Đồng hồ đếm ngược 3 phút. Khi hết giờ, các ô nhập liệu sẽ bị khóa.',
side: "bottom",
align: 'center'
}
},
{
element: '.writing-card.active .show-sample-btn',
popover: {
title: 'Đáp án mẫu',
description: 'Nếu bí ý tưởng, bạn có thể bấm vào đây để xem các câu trả lời ngắn gọn đạt chuẩn.',
side: "top",
align: 'center'
}
},
{
element: '#restart-tour',
popover: {
title: 'Hỗ trợ',
description: 'Bấm vào đây để xem lại hướng dẫn.',
side: "left",
align: 'center'
}
}
]
});
// Logic tự động chạy lần đầu
showTourHint('hasSeenWritingPart1Tour', () => driverObj.drive());
// Gán sự kiện cho nút ?
document.getElementById('restart-tour').addEventListener('click', () => {
driverObj.drive();
});
}
</script>
</body>
</html>