Spaces:
Running
Running
| window.addEventListener('DOMContentLoaded', function () { | |
| // Modal open/close logic (event delegation for reliability) | |
| const modal = document.getElementById('user-modal'); | |
| const closeModalBtn = document.getElementById('close-modal'); | |
| document.body.addEventListener('click', function(e) { | |
| const target = e.target.closest('.open-user-modal'); | |
| if (target) { | |
| e.preventDefault(); | |
| if (modal) modal.classList.remove('hidden'); | |
| } | |
| }); | |
| if (closeModalBtn) { | |
| closeModalBtn.addEventListener('click', function() { | |
| modal.classList.add('hidden'); | |
| }); | |
| } | |
| // Close modal when clicking outside the modal content | |
| if (modal) { | |
| modal.addEventListener('click', function(e) { | |
| if (e.target === modal) { | |
| modal.classList.add('hidden'); | |
| } | |
| }); | |
| } | |
| // Handle user info form submission (profile creation in frontend) | |
| const userInfoForm = document.getElementById('user-info-form'); | |
| if (userInfoForm) { | |
| userInfoForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const profile = { | |
| name: userInfoForm.name.value, | |
| qualification: userInfoForm.qualification.value, | |
| ielts: userInfoForm.ielts.value, | |
| cgpa: userInfoForm.cgpa.value, | |
| interest: userInfoForm.interest.value | |
| }; | |
| localStorage.setItem('scholargpt_profile', JSON.stringify(profile)); | |
| if (modal) modal.classList.add('hidden'); | |
| // Optionally, show a toast or redirect here | |
| }); | |
| } | |
| }); |