AB TECH Member Register

PrivacyModal() { privacyModal.classList.remove('active'); document.body.style.overflow = ''; } function acceptTerms() { if (btnAccept.classList.contains('ready')) { mainForm.submit(); } } // Scroll tracking privacyBody.onscroll = function() { const scrollPos = privacyBody.scrollTop + privacyBody.clientHeight; const totalHeight = privacyBody.scrollHeight; // If scrolled to bottom (with 20px tolerance) if (scrollPos >= totalHeight - 20) { btnAccept.classList.add('ready'); btnAccept.innerText = "ยอมรับเงื่อนไขและลงทะเบียน"; scrollHint.style.display = 'none'; } }; const sliderBtn = document.getElementById('sliderBtn'); const sliderTrack = document.getElementById('sliderTrack'); const puzzlePiece = document.getElementById('puzzlePiece'); const puzzleMain = document.getElementById('puzzleMain'); const puzzleBox = document.getElementById('puzzleBox'); const sliderText = sliderTrack.querySelector('.slider-text'); const puzzleXInput = document.getElementById('puzzle_x_input'); function initCaptcha() { puzzleBox.classList.remove('ready'); sliderText.innerText = "กำลังสร้างโจทย์..."; fetch('captcha_puzzle_api.php') .then(res => res.json()) .then(data => { puzzleMain.src = data.main; puzzlePiece.src = data.piece; // Ensure both are loaded in browser Promise.all([ new Promise(resolve => puzzleMain.onload = resolve), new Promise(resolve => puzzlePiece.onload = resolve) ]).then(() => { puzzleBox.classList.add('ready'); sliderText.innerText = "เลื่อนเพื่อยืนยัน >>>"; sliderBtn.style.left = '0'; puzzlePiece.style.left = '0'; puzzlePiece.style.transform = 'translateY(0)'; }); }) .catch(err => { sliderText.innerText = "เกิดข้อผิดพลาด กรุณาลองใหม่"; console.error(err); }); } initCaptcha(); let isDragging = false; let startX = 0; const maxSlide = sliderTrack.offsetWidth - sliderBtn.offsetWidth; const onStart = (e) => { if (!puzzleBox.classList.contains('ready')) return; isDragging = true; startX = (e.type === 'touchstart') ? e.touches[0].clientX : e.clientX; sliderBtn.style.transition = 'none'; puzzlePiece.style.transition = 'none'; }; const onMove = (e) => { if (!isDragging) return; const currentX = (e.type === 'touchmove') ? e.touches[0].clientX : e.clientX; let moveX = currentX - startX; if (moveX < 0) moveX = 0; if (moveX > maxSlide) moveX = maxSlide; sliderBtn.style.left = moveX + 'px'; const puzzleMoveX = (moveX / maxSlide) * (300 - 44); puzzlePiece.style.left = puzzleMoveX + 'px'; const progress = moveX / maxSlide; const curveY = Math.sin(progress * Math.PI) * 25; puzzlePiece.style.transform = `translateY(-${curveY}px)`; puzzleXInput.value = Math.round(puzzleMoveX); }; const onEnd = () => { isDragging = false; }; sliderBtn.addEventListener('mousedown', onStart); window.addEventListener('mousemove', onMove); window.addEventListener('mouseup', onEnd); sliderBtn.addEventListener('touchstart', onStart); window.addEventListener('touchmove', onMove); window.addEventListener('touchend', onEnd);