Leen172 commited on
Commit
32ef794
·
verified ·
1 Parent(s): f3e6e14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -279,13 +279,12 @@ textarea{min-height:120px}
279
  # ------------------ JS: ربط Submit بعد الرندر (مع Output مخفي لضمان التنفيذ) ------------------
280
  ATTACH_LISTENERS_JS = """
281
  () => {
282
- // اربط مرة واحدة فقط على مستوى الوثيقة (تفويض أحداث)
283
- if (window.__q_submit_bound_multi) { return 'already'; }
284
- window.__q_submit_bound_multi = true;
285
 
286
  document.addEventListener('click', function(e){
287
- if (!e.target || !e.target.classList) return;
288
- if (!e.target.classList.contains('q-submit')) return;
289
 
290
  const card = e.target.closest('.q-card');
291
  if (!card) return;
@@ -303,28 +302,30 @@ ATTACH_LISTENERS_JS = """
303
 
304
  const chosenLabel = chosen.closest('.opt');
305
 
306
- // حالة صحيحة: لوّن أخضر واقفل السؤال كاملاً
307
  if (chosen.value === correct) {
308
  chosenLabel.classList.add('ok');
309
  if (badge){ badge.hidden=false; badge.className='q-badge ok'; badge.textContent='Correct!'; }
 
310
  card.querySelectorAll('input[type="radio"]').forEach(i => i.disabled = true);
311
  e.target.disabled = true;
312
  if (note) note.textContent = '';
313
  return;
314
  }
315
 
316
- // حالة خاطئة: لوّن أحمر واقفل هذا الخيار فقط، واترك باقي الخيارات/الزر فعالة للمحاولة مرة أخرى
317
- chosenLabel.classList.add('err');
318
- chosen.disabled = true; // قفل هذا الخيار الخاطئ فقط
319
  if (badge){ badge.hidden=false; badge.className='q-badge err'; badge.textContent='Incorrect.'; }
320
- if (note) note.textContent = ''; // امسح تنبيه "اختر إجابة أولاً" إن كان موجودًا
 
321
  });
322
 
323
- return 'wired-multi';
324
  }
325
  """
326
 
327
 
 
328
  # ------------------ واجهة Gradio ------------------
329
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
330
  gr.Markdown("<h2 class='top'>Question Generator</h2>")
 
279
  # ------------------ JS: ربط Submit بعد الرندر (مع Output مخفي لضمان التنفيذ) ------------------
280
  ATTACH_LISTENERS_JS = """
281
  () => {
282
+ // اربط مرة واحدة فقط
283
+ if (window.__q_submit_bound_multi2) { return 'already'; }
284
+ window.__q_submit_bound_multi2 = true;
285
 
286
  document.addEventListener('click', function(e){
287
+ if (!e.target || !e.target.classList || !e.target.classList.contains('q-submit')) return;
 
288
 
289
  const card = e.target.closest('.q-card');
290
  if (!card) return;
 
302
 
303
  const chosenLabel = chosen.closest('.opt');
304
 
305
+ // حالة صحيحة: لوّن أخضر وأقفل السؤال كاملاً
306
  if (chosen.value === correct) {
307
  chosenLabel.classList.add('ok');
308
  if (badge){ badge.hidden=false; badge.className='q-badge ok'; badge.textContent='Correct!'; }
309
+ // أقفل هذا السؤال فقط بعد الصح
310
  card.querySelectorAll('input[type="radio"]').forEach(i => i.disabled = true);
311
  e.target.disabled = true;
312
  if (note) note.textContent = '';
313
  return;
314
  }
315
 
316
+ // حالة خاطئة: لوّن أحمر فقط، ولا تعطل أي شيء ليقدر يجرّب خيار آخر
317
+ chosenLabel.classList.add('err'); // اتركه أحمر
 
318
  if (badge){ badge.hidden=false; badge.className='q-badge err'; badge.textContent='Incorrect.'; }
319
+ if (note) note.textContent = '';
320
+ // مهم: لا تعطّل الراديو ولا الزر
321
  });
322
 
323
+ return 'wired-multi2';
324
  }
325
  """
326
 
327
 
328
+
329
  # ------------------ واجهة Gradio ------------------
330
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
331
  gr.Markdown("<h2 class='top'>Question Generator</h2>")