PageSourceSearch

https://www.tomkadlec.com/app/themes/dv-framework/media/js/srp-ajax.js?ver=1.776.838

js tomkadlec.com collected 2026-10-01 15:39:55 UTC 11,920 bytes, 312 lines download raw bytes

1/**
2 * Created by Josh on 7/2/2018.
3 */
4function getCTAForm(vehicle_id, vehicle_vin, discountMatrix, form_id){
5    jQuery.post(get_srp_form.ajax_url, {
6        "action": "get_srp_form", 
7        "form_id": form_id,
8        "vehicle_id": vehicle_id,
9        "vehicle_vin": vehicle_vin,
10        "discountMatrix": discountMatrix,
11        "referrer_url": window.location.href
12    }, function(response) {
13        jQuery(".popup_form").show();
14        var form_container = jQuery("#srp_form_container");
15        form_container.html(response);
16        var selected_form_title = jQuery(".gform_title", form_container).text();
17        jQuery("#popup_left_title").html(selected_form_title);
18        jQuery(".gform_title", form_container).hide();
19        jQuery(".gform_description", form_container).hide();        //document.write(response);
20    });
21    // console.log(get_srp_cta.ajaxurl);
22    // console.log("ajax called");
23    // $.ajax({
24    //     type: 'POST',
25    //     dataType: 'json',
26    //     url: get_srp_cta.ajaxurl ,
27    //     data: {
28    //         'action': 'srpcta', //calls wp_ajax_nopriv_ajaxlogin
29    //         'form_id': 123,
30    //         'vehicle_id': 123
31    //     },
32    //     success : function(response){
33    //         console.log(response);
34    //     }
35    // });
36}
37
38function _quickFormEventHandler(data, lockedPricing, form) {
39    const event = new CustomEvent('form:quick-form-submit', {
40        detail: {data, form}
41    });
42
43    document.dispatchEvent(event);
44
45    if(lockedPricing == 'true') {
46        setTimeout(function() {
47            
48            jQuery(".gform_confirmation_wrapper").remove();
49            jQuery(".da-quick-form").remove();
50            jQuery("#vdp-pricingheader-container").remove();
51            jQuery(".da-quick-form-unlocked").show();
52            jQuery("#da-quick-form-unlocked").show();
53            
54        }, 3000);
55
56        
57    }
58
59}
60
61function getAutoCheckReport(vehicle_id){
62
63    jQuery.post(get_srp_form.ajax_url, {
64        'action': 'get_autocheck_report',
65        'vehicle_id': vehicle_id,
66        'referrer_url': window.location.href
67    }, function(response) {
68        jQuery(".popup_form").show();
69        var form_container = jQuery("#srp_form_container");
70        form_container.html(response);
71        var selected_form_title = jQuery(".gform_title").text(TEST);
72        $("#popup_left_title").html(selected_form_title);
73        $(".gform_title", form_container).hide();
74        $(".gform_description", form_container).hide();
75        $('link[rel=stylesheet][href="https://www.autocheck.com/members/common/bootstrap.css"]').remove();
76        $('link[rel=stylesheet][href="https://www.experian.com/common-styles/master.css"]').remove();
77        $('link[rel=stylesheet][href="https://www.experian.com/corporate/style/corporate.css"]').remove();
78        $('link[rel=stylesheet][href="https://www.autocheck.com/members/common/dealers.css"]').remove();
79        $('link[rel=stylesheet][href="https://www.autocheck.com/members/common/autocheck.css"]').remove();
80        $('link[rel=stylesheet][href="https://www.autocheck.com/members/common/dealers.css"]').remove();
81        $('link[rel=stylesheet][href="https://www.autocheck.com/members/report/scoreReport/stylesheet/report_print.css"]').remove();
82        $('link[rel=stylesheet][href="https://www.autocheck.com/members/common/base.css"]').remove();
83    });
84}
85
86function getFuseForm(vehicle_id, vehicle_vin, discountMatrix, form_id, disclaimer){
87    jQuery.post(get_srp_form.ajax_url, {
88        "action": "get_srp_form",
89        "form_id": form_id,
90        "vehicle_id": vehicle_id,
91        "vehicle_vin": vehicle_vin,
92        "discountMatrix": discountMatrix,
93        "referrer_url": window.location.href
94    }, function(response) {
95        jQuery(".popup_form").show();
96        var form_container = jQuery("#srp_form_container");
97        form_container.html(response);
98        var selected_form_title = jQuery(".gform_title", form_container).text();
99        jQuery("#popup_left_title").html(selected_form_title);
100        jQuery(".gform_title", form_container).hide();
101        jQuery(".gform_description", form_container).hide();
102
103        if (disclaimer) {
104            var formBodySelector = ".gform_body";
105            jQuery(formBodySelector).append('<div class="dv-gform-disclaimers">' + disclaimer + '</div>');
106            jQuery(formBodySelector).show();
107        }
108    });
109}
110
111function getFuseFormVDP(vehicle_id, vehicle_vin, discountMatrix, form_id, disclaimer){
112    jQuery.post(get_srp_form.ajax_url, {
113        "action": "get_srp_form",
114        "form_id": form_id,
115        "vehicle_id": vehicle_id,
116        "vehicle_vin": vehicle_vin,
117        "discountMatrix": discountMatrix,
118        "referrer_url": window.location.href
119    }, function(response) {
120        jQuery("#vdp_form_container" ).show()
121        var form_container = jQuery("#vdp_form_container");
122        form_container.html(response);
123        var selected_form_title = jQuery(".gform_title", form_container).text();
124        jQuery("#popup_left_title").html(selected_form_title);
125        jQuery(".gform_title", form_container).hide();
126        jQuery(".gform_description", form_container).hide();
127
128        if (disclaimer) {
129            var formBodySelector = ".gform_body";
130            jQuery(formBodySelector).append('<div class="dv-gform-disclaimers">' + disclaimer + '</div>');
131            jQuery(formBodySelector).show();
132        }
133    });
134}
135
136
137/**
138 * Get the page type based on the body attributes
139 *
140 * @returns {string}
141 * @private
142 */
143function _getPageType() {
144    const body = document.body;
145
146    if (body.classList.contains('srp_main')) {
147        return 'srp';
148    } else if (body.classList.contains('vdp_main') || body.hasAttribute('data-vehicle')) {
149        return 'vdp';
150    } else {
151        return '';
152    }
153}
154
155function _setCookie(name, value, days) {
156    const date = new Date();
157    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
158    const expires = "expires=" + date.toUTCString();
159    document.cookie = name + "=" + value + ";" + expires + ";path=/";
160}
161
162
163function submitQuickForm(qfData, $form) {
164
165    // Check if qfData.condition is defined and has the necessary value
166    if (!qfData.condition) {
167        const url = window.top.location.pathname;
168        if (url.includes('/new-vehicles/')) {
169            qfData.condition = 'New';
170        } else if (url.includes('/used-vehicles/')) {
171            qfData.condition = 'Used';
172        }
173    }
174
175    const $formWrapper = $form.parent('.da-quick-form');
176    const lockedPricing = $formWrapper.attr('data-locked-pricing');
177    const condition = qfData.condition.toLowerCase();
178    const location = qfData.formLocation;
179
180    if (lockedPricing === 'true') {
181        // Set the "all" cookie when price is unlocked
182        _setCookie(`quickFormUnlocked_all_${condition}`, "true", 1);
183    } else {
184        // Set the VIN-specific cookie
185        _setCookie(`quickFormUnlocked_${qfData.vin}`, "true", 1);
186    }
187
188    let vehicleUrl = "";
189
190    if(location === 'VDP') {
191        vehicleUrl = window.location.href;
192    } else {
193        vehicleUrl = window.location.origin + qfData.vehicleUrl;
194    }
195
196    
197    let ajaxData = {
198        "action": "get_quick_form",
199        "lockedPricing": lockedPricing,
200        "security": qfData.security,
201        "form_id": qfData.formId,
202        "vehicle_id": qfData.id,
203        "status": qfData.status,
204        "vin": qfData.vin,
205        "name": qfData.name,
206        "phone": qfData.phone,
207        "email": qfData.email,
208        "stock_number": qfData.stockNumber,
209        "year": qfData.year,
210        "make": qfData.make,
211        "model": qfData.model,
212        "trim": qfData.trim,
213        "msrp": qfData.msrp,
214        "final_price": qfData.finalPrice,
215        "dealer_name": qfData.dealerName,
216        "discountMatrix": qfData.discountMatrix,
217        "discount_matrix_value": qfData.discountMatrixValue,
218        "internet_price": qfData.internetPrice,
219        "condition": qfData.condition,
220        "vehicle_url": vehicleUrl,
221        "referrer_url": window.location.href,
222        "form_location": qfData.formLocation,
223    }
224
225    jQuery.post(get_srp_form.ajax_url, ajaxData, function(response) {
226        let mergedData = {};
227
228        if (response.success) {
229            let data = {
230                formWrapper: $form,
231                url: window.location.href,
232                pageType: _getPageType()
233            }
234
235            // Merge ajaxData, data, and response.data into a single object
236            mergedData = { ...ajaxData, ...data, ...response.data};
237
238            // save the height of the form wrapper with the form so the vehicle card
239            // stays the same height after submission
240            let quickFormHeight = $formWrapper.outerHeight();
241
242            if (response.data.redirect) {
243                window.location.href = response.data.redirect;
244            } else if (response.data.confirmation_type === 'message') {
245                console.log("Success:", response.data.message);
246                if (response.data.message) {
247                    $formWrapper.css({
248                        height: `${quickFormHeight}px`,
249                        display: "flex",
250                        "align-items": "center",
251                        "justify-content": "center",
252                        "text-align": "center"
253                    }).html('<div class="gform_confirmation_wrapper">' + response.data.message + '</div>');
254                }
255            } else {
256                console.log("Success:", response.data.message);
257                if (response.data.confirmation) {
258                    $formWrapper.html('<div class="gform_confirmation_wrapper">' + response.data.confirmation + '</div>');
259                }
260            }
261        } else {
262            console.error("Error:", response.data);
263            $formWrapper.find("input, button").prop("disabled", false);
264        }
265
266        // fire an event after the form has been submitted
267        // pass the native DOM element of the form, not the jQuery wrapper
268        _quickFormEventHandler(qfData, lockedPricing, $form[0]);
269    });
270}
271
272
273//pull incentives for on srp conditional incentives slideout
274function getIncentivesForm(vehicle_id, vehicle_vin, price, form_id, vdpUrl){
275    jQuery.post(get_srp_form.ajax_url, {
276        "action": "get_srp_form",
277        "form_id": form_id,
278        "vehicle_id": vehicle_id,
279        "vehicle_vin": vehicle_vin,
280        "price": price,
281        "referrer_url": window.location.href + vdpUrl
282    }, function(response) {
283        jQuery(".popup_form").show();
284        var form_container = jQuery("#srp_form_container");
285        form_container.html(response);
286        var selected_form_title = jQuery(".gform_title", form_container).text();
287        jQuery("#popup_left_title").html(selected_form_title);
288        jQuery(".gform_title", form_container).hide();
289        jQuery(".gform_description", form_container).hide();
290    });
291}
292
293function registerSmartpathCTAOverrides(parentContainer) {
294    jQuery(parentContainer).on('click', 'a[class^=vdp-button-smartpath], a[class^=srp-cta-smartpath]', function(e){
295        let href = e.target.href;
296        if (href) {
297            let url = URL.parse(href);
298            if (url.pathname === '/inventory/details' && url.host.startsWith('smartpath') && DGDataHub) {
299                let vin = e.target.getAttribute('data-vehicle-vin');
300                let salesClass = e.target.getAttribute('data-vehicle-condition').toLowerCase();
301
302                if (url.searchParams.get('contact') && DGDataHub.showContactDealer) {
303                    DGDataHub.showContactDealer(vin, salesClass);
304                    e.preventDefault();
305                } else if (url.searchParams.get('availability') && DGDataHub.showConfirmAvailability) {
306                    DGDataHub.showConfirmAvailability(vin, salesClass);
307                    e.preventDefault();
308                }
309            }
310        }
311    })
312}

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.