|
| 1 | +document.addEventListener('DOMContentLoaded', () => { |
| 2 | + // --- Mobile Redirect for Projects Link --- |
| 3 | + // This code checks if the user is on a mobile device. |
| 4 | + const isMobile = /Mobi|Android/i.test(navigator.userAgent); |
| 5 | + const projectsLink = document.getElementById('projects-link'); |
| 6 | + |
| 7 | + if (isMobile && projectsLink) { |
| 8 | + projectsLink.href = "https://github.com/eudk"; |
| 9 | + projectsLink.target = "_blank"; |
| 10 | + projectsLink.rel = "noopener noreferrer"; |
| 11 | + } |
| 12 | + |
| 13 | + // --- Typewriter Effect Logic --- |
| 14 | + const typewriterTextElement = document.getElementById('typewriter-text'); |
| 15 | + if (typewriterTextElement) { |
| 16 | + const phrases = [ |
| 17 | + "IT security student DK .", |
| 18 | + "Learning governance, risk and compliance.", |
| 19 | + "Hands-on with threat modeling and vuln management.", |
| 20 | + "Building small tools to automate tasks.", |
| 21 | + "Getting into cloud security and infrastructure as code.", |
| 22 | + "Open for internship opportunities." |
| 23 | +]; |
| 24 | + let phraseIndex = 0; |
| 25 | + let charIndex = 0; |
| 26 | + let isDeleting = false; |
| 27 | + |
| 28 | + function typeWriter() { |
| 29 | + const currentPhrase = phrases[phraseIndex]; |
| 30 | + let typeSpeed = 70; |
| 31 | + if (isDeleting) { |
| 32 | + typeSpeed = 40; |
| 33 | + typewriterTextElement.textContent = currentPhrase.substring(0, charIndex - 1); |
| 34 | + charIndex--; |
| 35 | + } else { |
| 36 | + typewriterTextElement.textContent = currentPhrase.substring(0, charIndex + 1); |
| 37 | + charIndex++; |
| 38 | + } |
| 39 | + if (!isDeleting && charIndex === currentPhrase.length) { |
| 40 | + isDeleting = true; |
| 41 | + typeSpeed = 2000; |
| 42 | + } else if (isDeleting && charIndex === 0) { |
| 43 | + isDeleting = false; |
| 44 | + phraseIndex = (phraseIndex + 1) % phrases.length; |
| 45 | + typeSpeed = 500; |
| 46 | + } |
| 47 | + setTimeout(typeWriter, typeSpeed); |
| 48 | + } |
| 49 | + if (phrases.length > 0) { |
| 50 | + typeWriter(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + // --- Formspree Success Message Handler --- |
| 55 | + const urlParams = new URLSearchParams(window.location.search); |
| 56 | + if (urlParams.has('submission') && urlParams.get('submission') === 'success') { |
| 57 | + const successBanner = document.getElementById('success-banner'); |
| 58 | + if (successBanner) { |
| 59 | + successBanner.classList.add('show'); |
| 60 | + setTimeout(() => { |
| 61 | + successBanner.classList.remove('show'); |
| 62 | + }, 5000); // Hide banner after 5 seconds |
| 63 | + } |
| 64 | + } |
| 65 | +}); |
| 66 | + |
| 67 | +const canvas = document.getElementById('matrix-canvas'); |
| 68 | +const ctx = canvas.getContext('2d'); |
| 69 | +let animationFrameId; |
| 70 | +function setupCanvas() { |
| 71 | + canvas.width = window.innerWidth; |
| 72 | + canvas.height = window.innerHeight; |
| 73 | + const columns = canvas.width / 14; |
| 74 | + const drops = []; |
| 75 | + for (let x = 0; x < columns; x++) drops[x] = 1; |
| 76 | + return { drops }; |
| 77 | +} |
| 78 | +let { drops } = setupCanvas(); |
| 79 | +function draw() { |
| 80 | + ctx.fillStyle = 'rgba(248, 248, 250, 0.08)'; |
| 81 | + ctx.fillRect(0, 0, canvas.width, canvas.height); |
| 82 | + ctx.fillStyle = '#e8e8ed'; |
| 83 | + ctx.font = '14px arial'; |
| 84 | + for (let i = 0; i < drops.length; i++) { |
| 85 | + const text = Math.random() > 0.5 ? '0' : '1'; |
| 86 | + ctx.fillText(text, i * 14, drops[i] * 14); |
| 87 | + if (drops[i] * 14 > canvas.height && Math.random() > 0.99) drops[i] = 0; |
| 88 | + drops[i]++; |
| 89 | + } |
| 90 | +} |
| 91 | +function animate() { |
| 92 | + draw(); |
| 93 | + animationFrameId = requestAnimationFrame(animate); |
| 94 | +} |
| 95 | +if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) { |
| 96 | + animate(); |
| 97 | +} |
| 98 | +window.addEventListener('resize', () => { |
| 99 | + if (animationFrameId) { |
| 100 | + cancelAnimationFrame(animationFrameId); |
| 101 | + ({ drops } = setupCanvas()); |
| 102 | + animate(); |
| 103 | + } |
| 104 | +}); |
| 105 | + |
| 106 | +// --- Accessible Modal & Form Logic --- |
| 107 | +const openModalBtn = document.getElementById('open-contact-modal'); |
| 108 | +const closeModalBtn = document.getElementById('close-contact-modal'); |
| 109 | +const modalOverlay = document.getElementById('contact-modal-overlay'); |
| 110 | +const consentCheckbox = document.getElementById('consent'); |
| 111 | +const submitButton = document.querySelector('#contact-form button[type="submit"]'); |
| 112 | +function updateSubmitButtonState() { |
| 113 | + submitButton.disabled = !consentCheckbox.checked; |
| 114 | +} |
| 115 | +consentCheckbox.addEventListener('change', updateSubmitButtonState); |
| 116 | +openModalBtn.addEventListener('click', (e) => { |
| 117 | + e.preventDefault(); |
| 118 | + modalOverlay.classList.add('show'); |
| 119 | + consentCheckbox.checked = false; |
| 120 | + updateSubmitButtonState(); |
| 121 | +}); |
| 122 | +const closeModal = () => { |
| 123 | + modalOverlay.classList.remove('show'); |
| 124 | +}; |
| 125 | +closeModalBtn.addEventListener('click', closeModal); |
| 126 | +modalOverlay.addEventListener('click', (e) => { |
| 127 | + if (e.target === modalOverlay) closeModal(); |
| 128 | +}); |
| 129 | +document.addEventListener('keydown', (e) => { |
| 130 | + if (e.key === "Escape" && modalOverlay.classList.contains('show')) closeModal(); |
| 131 | +}); |
| 132 | +updateSubmitButtonState(); |
| 133 | + |
0 commit comments