PageSourceSearch

https://landrover.decarie.com/js/shiftdigital-click-tracking.js

js decarie.com collected 2026-10-08 08:15:18 UTC 7,828 bytes, 220 lines download raw bytes

1var action = 1;
2
3$(document).on('ready', function() {
4    // initScheduleServiceClick ()
5    //
6    // /**
7    //  * Initial Schedule Service Click ()
8    //  */
9    // function initScheduleServiceClick (){
10    //     const ctas = document.querySelectorAll('a[href$="/5"]')
11    //     ctas.forEach(cta => {
12    //         hrefMatchRegex(cta);
13    //     })
14    // }
15    //
16    // /**
17    //  * Check if button contains form reference = 5 & Add Click Event
18    //  */
19    // function hrefMatchRegex(element) {
20    //     let regex = /\bform.*\b5\b$/;
21    //     const regexCondition = element.href.match(regex);
22    //
23    //     if(regexCondition){
24    //         element.addEventListener("click", (e) => {
25    //             sendScheduleServiceClick();
26    //         }, false);
27    //     }
28    // }
29
30    /**
31     * Verify if the given element is visible inside the viewport
32     * @param { Element } elem - A DOM element.
33     * @return {boolean}
34     */
35    function isInViewport(elem) {
36        var bounding = elem[0].getBoundingClientRect();
37        return (
38            elem.style.display !== 'none' &&
39            !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length) && // Prevent element do be seen as in viewport when not visible/displayed on screen
40            bounding.top >= 0 &&
41            bounding.left >= 0 &&
42            bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
43            bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
44        );
45    }
46
47    /**
48     * Retrieve a form id by selecting its input bearing its id.
49     * @param { Element } form - A form element.
50     * @return { String }
51     */
52    function getFormIdFromInput(form) {
53        return form.querySelector('input[name=formTypeId]').value;
54    }
55
56    /**
57     * Handle when a Shift Digital form appears in viewport.
58     * @param { Element } form - A form element.
59     */
60    function handleShiftDigitalFormInViewport(form) {
61        var formId = getFormIdFromInput(form);
62        if (isInViewport(form) && form.getAttribute('data-scroll-event') == null && formId) {
63            form.setAttribute('data-scroll-event', 'true');
64            sendFormShowEvent(formId);
65        }
66    }
67
68    /**
69     * Add event listeners on a Shift Digital form.
70     * @param { Element } form - A form element.
71     */
72    function addShiftDigitalListenersOnInputs(form) {
73        var formId = getFormIdFromInput(form);
74        var formInputs = form.querySelectorAll('input, textarea, button[type="submit"], button.submit');
75
76        Array.prototype.slice.call(formInputs).forEach(function (input) {
77           input.addEventListener('focus', function () {
78               sendFormInitEvent(formId);
79           })
80        });
81    }
82
83    var forms = document.forms;
84    for (var i = 0; i < forms.length; i++) {
85        if(forms[i].querySelector('input[name=formTypeId]') && !forms[i].closest('.voyager-widget')) {
86            handleShiftDigitalFormInViewport(forms[i]);
87            addShiftDigitalListenersOnInputs(forms[i]);
88        }
89    }
90
91    var newsletterWidgets = document.querySelectorAll('[data-newsletter]');
92    Array.prototype.slice.call(newsletterWidgets).forEach(function (newsletter) {
93        var inputs = newsletter.querySelectorAll('[data-newsletter-input], [data-newsletter-submit]');
94
95        Array.prototype.slice.call(inputs).forEach(function (input) {
96            input.addEventListener('focus', function () {
97                sendFormInitEvent('900');
98            });
99        });
100    });
101
102    window.addEventListener('scroll', function () {
103        for (var i = 0; i < forms.length; i++) {
104            if(forms[i].querySelector('input[name=formTypeId]') && !forms[i].closest('.voyager-widget')) {
105                handleShiftDigitalFormInViewport(forms[i]);
106            }
107        }
108    }, false);
109
110    if($('.form-footer [data-multi-form="true"]').length>0){
111        $('.form-footer [data-multi-form="true"]').each(function(){
112            var radio = $(this);
113            radio.find('+label').on('click', function(){
114                if(!radio.prop('checked')){
115                    action = 1;
116                    radio.parents('.form-footer').on('click', 'form .form-field__label-input-text', function(){
117                        var formId = $(".form-footer input[name=formTypeId]").val();
118                        sendFormInitEvent(formId);
119                    });
120                }
121            });
122        });
123    }
124
125    if($('[data-form-id][data-reveal-btn]').length > 0){
126        $('[data-reveal]').on('open.zf.reveal', function() {
127            var formInput = $(this).find('form [name="formTypeId"]');
128            if(formInput.length > 0) {
129                sendFormShowEvent(formInput.val());
130            }
131        });
132
133        $('[data-form-id][data-reveal-btn]').on('click', function() {
134            action = 1;
135        });
136
137        $('[data-yeti-box="vdpModal"] [data-close]').on('click', function(){
138            action = 1;
139        });
140        $('[data-yeti-box="vdpModal"]').parent('.reveal-overlay').on('click', function(e){
141            if(!e.target.closest('[data-reveal]')){
142                action = 1;
143            }
144        });
145        $('.reveal-body').on('click', 'form .form-field__label-input-text', function(){
146            var formId = $(this).parents('form').find("input[name=formTypeId]").val();
147            sendFormInitEvent(formId);
148        });
149    }
150});
151
152$('.shiftdigital-event').click(function(e){
153    e.preventDefault();
154    var eventType=$(this).attr('data-shiftdigital-event').toLowerCase();
155
156    if(eventType=='carousel'){
157        var index=$(this).attr('data-shiftdigital-index');
158        var title=$(this).attr('data-shiftdigital-title');
159        var gotoURL=$(this).attr('data-shiftdigital-url');
160        carouselEvent(index,title);
161        if (gotoURL.indexOf('http') >= 0){
162            window.open(gotoURL, '_blank');
163        }
164        else{
165            document.location.href = gotoURL;
166        }
167    }
168    else if(eventType=='offer') {
169        e.preventDefault();
170        var index = $(this).attr('data-shiftdigital-index');
171        var title = $(this).attr('data-shiftdigital-title');
172        var url = $(this).attr('data-shiftdigital-url');
173        var category = $(this).attr('data-shiftdigital-offer-category');
174        var offerExpire = $(this).attr('data-shiftdigital-offer-expire');
175        var departmentId = $(this).parents('[data-shiftdigital-departmentid]').attr('data-shiftdigital-departmentid');
176        offerEvent(index, title, departmentId, url, offerExpire, category);
177    }
178    else if(eventType=='clicktocall'){
179        var title=$(this).attr('data-shiftdigital-title');
180        var gotoURL=$(this).attr('data-shiftdigital-url').replace(/\(|\)/g,'');
181        clickToCallEvent(title);
182        if($(this).attr('href')){
183            gotoURL = $(this).attr('href');
184        }
185        document.location.href = gotoURL;
186    }
187});
188
189document.addEventListener('DOMContentLoaded', () => {
190    const searchInput = document.querySelector('[data-search-input]');
191    if (searchInput) {
192        // Triggered by pressing the "Enter" key
193        searchInput.addEventListener('keydown', (event) => {
194            if (event.key === 'Enter') {
195                const searchValue = searchInput.value.trim();
196                if (searchValue) {
197                    searchSubmitEvent(searchValue);
198                }
199            }
200        });
201    }
202});
203
204function clickToCallEvent(clickToCallDepartment){
205    sd('dataLayer', {
206        clickToCallDepartment: clickToCallDepartment,
207        events: 'clickToCall'
208    });
209    sd('send');
210}
211
212/**
213 * Send Schedule Service Click Event
214 */
215// function sendScheduleServiceClick (){
216//     sd('dataLayer', {
217//         events: 'scheduleServiceClick'
218//     });
219//     sd('send');
220// }

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.