PageSourceSearch

https://classicracingschool.com/wp-content/plugins/spdrive-options//assets/js/date-selector.js?ver=1762198690

js classicracingschool.com collected 2026-10-10 00:42:28 UTC 5,108 bytes, 116 lines download raw bytes

1jQuery(document).ready(function($) {
2    // Store the previously selected formula when date changes
3    let storedFormula = null;
4    
5    // Function to check and update available dates
6    function checkAvailableDates() {
7        const $elementorSelect = $('.spd-elementor-date-select');
8        const $nativeSelect = $('form.variations_form select[name="attribute_pa_date"]');
9
10        if ($elementorSelect.length && $nativeSelect.length) {
11            // Get all available dates from native select
12            const availableDates = [];
13            $nativeSelect.find("option").each(function () {
14                if ($(this).val()) {
15                    availableDates.push($(this).val());
16                }
17            });
18            // Update Elementor select options
19            $elementorSelect.find("option").each(function () {
20                const $option = $(this);
21                const dateValue = $option.val();
22                if (dateValue && !availableDates.includes(dateValue)) {
23                    $option.prop("disabled", true);
24                    $option.addClass("disabled");
25                } else {
26                    $option.prop("disabled", false);
27                    $option.removeClass("disabled");
28                }
29            });
30        }
31    }
32
33    // Sync Elementor date select -> native WooCommerce select with formula preservation
34    $(document).on('change', '.spd-elementor-date-select', function() {
35        const value = $(this).val();
36        const $variationForm = $('form.variations_form');
37        const $nativeDate = $variationForm.find('select[name="attribute_pa_date"]');
38        const $nativeFormula = $variationForm.find('select[name="attribute_pa_type_stage"]');
39        
40        // Store current formula before changing date
41        if ($nativeFormula.length) {
42            storedFormula = $nativeFormula.val();
43            console.log('Stored formula before date change:', storedFormula);
44        }
45        
46        // Reset formula selector to empty
47        if ($nativeFormula.length) {
48            $nativeFormula.val('').trigger('change');
49        }
50        // Also reset the radio buttons
51        $('.formula-radio').prop('checked', false);
52        $('.formula-option').removeClass('selected');
53        
54        // Change date
55        if ($nativeDate.length) {
56            $nativeDate.val(value).trigger('change');
57            
58            // Listen for WooCommerce to finish updating variations
59            let formulaRestored = false;
60            const restoreFormulaHandler = function() {
61                if (formulaRestored) return;
62                formulaRestored = true;
63                
64                if (storedFormula && $nativeFormula.length) {
65                    // Check if the stored formula is available
66                    const $formulaOption = $nativeFormula.find('option[value="' + storedFormula + '"]');
67                    const formulaIsAvailable = $formulaOption.length > 0 && !$formulaOption.prop('disabled');
68                    
69                    if (formulaIsAvailable) {
70                        console.log('Restoring previously selected formula:', storedFormula);
71                        $nativeFormula.val(storedFormula).trigger('change');
72                        // Also update the radio button
73                        $(`.formula-radio[value="${storedFormula}"]`).prop('checked', true)
74                            .closest('.formula-option').addClass('selected');
75                    } else {
76                        console.log('Previous formula not available with new date, keeping empty');
77                    }
78                    
79                    // Clear stored formula
80                    storedFormula = null;
81                }
82                
83                // Remove the event listener
84                $variationForm.off('woocommerce_update_variation_values.restore_formula');
85            };
86            
87            // Use WooCommerce event to know when variations are updated
88            $variationForm.one('woocommerce_update_variation_values.restore_formula', function() {
89                setTimeout(restoreFormulaHandler, 100);
90            });
91            
92            // Fallback with timeout
93            setTimeout(restoreFormulaHandler, 800);
94        }
95    });
96
97    // On load, sync Elementor select with WooCommerce select value
98    const $variationForm = $('form.variations_form');
99    const $select = $variationForm.find('select[name="attribute_pa_date"]');
100    if ($select.length) {
101        $('.date-select').val($select.val());
102    }
103
104    // Check available dates on page load (with delay to ensure WooCommerce is ready)
105    setTimeout(checkAvailableDates, 1000);
106
107    // Check available dates when formula changes
108    $(document).on('change', '.formula-radio, select[name="attribute_pa_type_stage"]', function() {
109        setTimeout(checkAvailableDates, 100);
110    });
111
112    // Check available dates when WooCommerce updates variations
113    $variationForm.on('check_variations woocommerce_update_variation_values', function() {
114        setTimeout(checkAvailableDates, 100);
115    });
116});

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.