PageSourceSearch

https://www.nvisioncenters.com/wp-content/themes/nvision-v2/assets/js/form-tracking.js?ver=1790204035

js nvisioncenters.com collected 2026-09-24 19:36:44 UTC 5,045 bytes, 120 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function () {
2    // console.log('Form tracking script loaded');
3    // console.log('ajaxurl:', ajaxurl);
4
5    // Keep track of forms we've already set up tracking for
6    const trackedForms = new WeakSet();
7
8    function setupFormTracking(form) {
9        // Skip if already tracked
10        if (trackedForms.has(form)) {
11            return;
12        }
13        trackedForms.add(form);
14
15        // console.log('Setting up form tracking for:', form.getAttribute('data-type'));
16
17        // Listen for the form's success event
18        form.addEventListener('form-submit-success', function (e) {
19            // console.log('Form submit success event fired');
20            const formType = this.getAttribute('data-type') || 'general';
21            // console.log('Form type:', formType);
22
23            // Track the submission after successful form submission
24            fetch(ajaxurl.url, {
25                method: 'POST',
26                headers: {
27                    'Content-Type': 'application/x-www-form-urlencoded',
28                },
29                body: new URLSearchParams({
30                    'action': 'nv_form_submission',
31                    'form_type': formType
32                })
33            })
34                .then(response => response.json())
35                .then(data => {
36                    // console.log('Form tracking response:', data);
37                    if (data.success) {
38                        // console.log('✅ Tracking saved successfully:', data.data);
39                    } else {
40                        console.error('❌ Tracking failed:', data.data);
41                    }
42                })
43                .catch(error => {
44                    console.error('Form tracking error:', error);
45                });
46        });
47    }
48
49    // Track all existing forms
50    const forms = document.querySelectorAll('[data-plugin="nv-form"]');
51    // console.log('Found forms:', forms.length);
52    forms.forEach(setupFormTracking);
53
54    // Watch for dynamically added forms (e.g., modals loaded via AJAX)
55    const observer = new MutationObserver((mutations) => {
56        mutations.forEach((mutation) => {
57            mutation.addedNodes.forEach((node) => {
58                if (node.nodeType === 1) { // Element node
59                    // Check if the added node is a form
60                    if (node.matches && node.matches('[data-plugin="nv-form"]')) {
61                        // console.log('New form detected in DOM');
62                        setupFormTracking(node);
63                    }
64                    // Check if the added node contains a form
65                    if (node.querySelectorAll) {
66                        const newForms = node.querySelectorAll('[data-plugin="nv-form"]');
67                        if (newForms.length > 0) {
68                            // console.log('Found', newForms.length, 'new forms in added content');
69                            newForms.forEach(setupFormTracking);
70                        }
71                    }
72                }
73            });
74        });
75    });
76
77    // Start observing the document body for added nodes
78    observer.observe(document.body, {
79        childList: true,
80        subtree: true
81    });
82
83    // console.log('Form tracking observer setup complete');
84
85    // Fetch real-time count for form submission counters
86    const counters = document.querySelectorAll('[data-fetch-count="true"]');
87    if (counters.length > 0) {
88        fetch(ajaxurl.url + '?action=get_form_count')
89            .then(response => response.json())
90            .then(data => {
91                if (data.success) {
92                    counters.forEach(counter => {
93                        const numberSpan = counter.querySelector('.form-count-number');
94                        const textSpan = counter.querySelector('.form-count-text');
95
96                        if (numberSpan && textSpan) {
97                            // Only update if the count has changed
98                            const currentCount = numberSpan.textContent.replace(/,/g, '');
99                            const newCount = data.data.formatted;
100
101                            if (currentCount !== newCount) {
102                                // Fade out, update, fade in
103                                numberSpan.style.opacity = '0.5';
104                                setTimeout(() => {
105                                    numberSpan.textContent = newCount;
106                                    textSpan.textContent = ' ' + data.data.text;
107                                    numberSpan.style.opacity = '1';
108                                    // console.log('✅ Updated form count from', currentCount, 'to', newCount);
109                                }, 150);
110                            }
111                        }
112                    });
113                }
114            })
115            .catch(error => {
116                console.error('Form count fetch error:', error);
117                // Silently fail - keep showing cached count
118            });
119    }
120});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.