Jake Vanderwerf
2025-11-04 42fa8304ddb811b0f725f245130f70c0f5e86a6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * FAQ Block - Frontend Interactions
 * Handles accordion functionality for FAQ items
 */
 
document.addEventListener('DOMContentLoaded', () => {
    const faqBlocks = document.querySelectorAll('.faq-block');
 
    faqBlocks.forEach((block) => {
        const faqItems = block.querySelectorAll('.faq-item');
 
        faqItems.forEach((item) => {
            const button = item.querySelector('.faq-item__question');
            const answer = item.querySelector('.faq-item__answer');
 
            if (!button || !answer) return;
 
            button.addEventListener('click', () => {
                const isExpanded = button.getAttribute('aria-expanded') === 'true';
 
                // Toggle this item
                button.setAttribute('aria-expanded', !isExpanded);
 
                if (isExpanded) {
                    // Collapse
                    answer.style.height = answer.scrollHeight + 'px';
                    // Force reflow
                    answer.offsetHeight;
                    answer.style.height = '0';
 
                    setTimeout(() => {
                        answer.style.display = 'none';
                        answer.style.height = '';
                    }, 300);
 
                    item.classList.remove('faq-item--expanded');
                } else {
                    // Expand
                    answer.style.display = 'block';
                    answer.style.height = '0';
                    // Force reflow
                    answer.offsetHeight;
                    answer.style.height = answer.scrollHeight + 'px';
 
                    setTimeout(() => {
                        answer.style.height = 'auto';
                    }, 300);
 
                    item.classList.add('faq-item--expanded');
                }
            });
 
            // Handle keyboard navigation
            button.addEventListener('keydown', (e) => {
                // Space or Enter triggers the button
                if (e.key === ' ' || e.key === 'Enter') {
                    e.preventDefault();
                    button.click();
                }
            });
        });
    });
 
    // Optional: Add URL hash navigation
    // If URL has #faq-123, open that specific FAQ
    if (window.location.hash) {
        const hash = window.location.hash.substring(1);
        const targetItem = document.querySelector(`[data-faq-id="${hash}"]`);
 
        if (targetItem) {
            const button = targetItem.querySelector('.faq-item__question');
            const isExpanded = button.getAttribute('aria-expanded') === 'true';
 
            if (!isExpanded) {
                button.click();
            }
 
            // Scroll to item after a short delay
            setTimeout(() => {
                targetItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
            }, 350);
        }
    }
});