// Shipping pretest: register a clicked Company A / Company B choice, plus its // timing, then (on ChoiceSet only, detected by #ratings-panel being present) // walk through a confidence rating before submitting. No voice, no // live_method, no network wait, so there is nothing to show a spinner for. (function () { var pageLoadEl = document.getElementById('dec-ts-page-load'); if (pageLoadEl) pageLoadEl.value = Date.now(); var choiceEl = document.getElementById('dec-choice'); var choiceTsEl = document.getElementById('dec-ts-choice'); var btnA = document.getElementById('choice-a'); var btnB = document.getElementById('choice-b'); var submitButton = document.getElementById('submit_button'); var ratingsPanel = document.getElementById('ratings-panel'); if (!btnA || !btnB || !choiceEl || !submitButton) return; // ── Ratings (ChoiceSet only) ──────────────────────────────────────────── var RATINGS = [ { id: 'dec-rating-confidence', q: 'How confident are you in your decision?', lo: 'Not at all confident', hi: 'Very confident' }, ]; var currentRating = 0; function showRatings() { currentRating = 0; renderRatingStep(); ratingsPanel.classList.add('visible'); } function renderRatingStep() { var r = RATINGS[currentRating]; document.getElementById('ratings-progress-fill').style.width = (currentRating / RATINGS.length) * 100 + '%'; document.getElementById('ratings-question').textContent = r.q; document.getElementById('ratings-anchor-lo').textContent = r.lo; document.getElementById('ratings-anchor-hi').textContent = r.hi; document.querySelectorAll('.rating-btn').forEach(function (b) { b.classList.remove('selected'); }); } function selectRating(val) { document.getElementById(RATINGS[currentRating].id).value = val; document.querySelectorAll('.rating-btn').forEach(function (b) { b.classList.toggle('selected', parseInt(b.dataset.val, 10) === val); }); setTimeout(function () { currentRating++; if (currentRating < RATINGS.length) { renderRatingStep(); } else { ratingsPanel.classList.remove('visible'); submitButton.click(); } }, 160); } if (ratingsPanel) { document.getElementById('ratings-scale').addEventListener('click', function (e) { var btn = e.target.closest('.rating-btn'); if (btn) selectRating(parseInt(btn.dataset.val, 10)); }); } // ── Choice buttons ─────────────────────────────────────────────────────── function chooseCompany(choice) { choiceEl.value = choice; if (choiceTsEl) choiceTsEl.value = Date.now(); btnA.classList.toggle('selected', choice === 'A'); btnB.classList.toggle('selected', choice === 'B'); btnA.disabled = true; btnB.disabled = true; if (ratingsPanel) { setTimeout(showRatings, 250); } else { setTimeout(function () { submitButton.click(); }, 250); } } btnA.addEventListener('click', function () { chooseCompany('A'); }); btnB.addEventListener('click', function () { chooseCompany('B'); }); })();