PageSourceSearch

https://infiniteauto.co.za/wp-content/themes/motors/assets/js/app.js?ver=1790257394

js infiniteauto.co.za collected 2026-09-24 13:44:29 UTC 60,173 bytes, 1,625 lines download raw bytes

1"use strict";
2
3(function ($) {
4    $.fn.parallax = function () {
5        var window_width = $(window).width();
6        // Parallax Scripts
7        return this.each(function (i) {
8            var $this = $(this);
9            $this.addClass('parallax');
10
11            function updateParallax(initial) {
12                var container_height;
13                if (window_width < 601) {
14                    container_height = ($this.height() > 0) ? $this.height() : $this.children("img").height();
15                } else {
16                    container_height = ($this.height() > 0) ? $this.height() : 500;
17                }
18                var $img = $this.children("img").first();
19                var img_height = $img.height();
20                var parallax_dist = img_height - container_height + 100;
21                var bottom = $this.offset().top + container_height;
22                var top = $this.offset().top;
23                var scrollTop = $(window).scrollTop();
24                var windowHeight = window.innerHeight;
25                var windowBottom = scrollTop + windowHeight;
26                var percentScrolled = (windowBottom - top) / (container_height + windowHeight);
27                var parallax = Math.round((parallax_dist * percentScrolled));
28
29                if (initial) {
30                    $img.css('display', 'block');
31                }
32                if ((bottom > scrollTop) && (top < (scrollTop + windowHeight))) {
33                    $img.css('transform', "translate3D(-50%," + parallax + "px, 0)");
34                }
35
36            }
37
38            // Wait for image load
39            $this.children("img").one("load", function () {
40                updateParallax(true);
41            }).each(function () {
42                if (this.complete) $(this).load();
43            });
44
45            $(document).ready(function () {
46                updateParallax(false);
47            });
48
49            $(window).on('scroll', function () {
50                window_width = $(window).width();
51                updateParallax(false);
52            });
53
54            $(window).on('resize', function () {
55                window_width = $(window).width();
56                updateParallax(false);
57            });
58
59        });
60
61    };
62
63    // swipe events using vanilla js
64    var SwipeEvent = (function () {
65        function SwipeEvent(element) {
66            this.xDown = null;
67            this.yDown = null;
68            this.element = typeof (element) === 'string' ? document.querySelector(element) : element;
69            this.element.addEventListener('touchstart', function (evt) {
70                this.xDown = evt.touches[0].clientX;
71                this.yDown = evt.touches[0].clientY;
72            }.bind(this), false);
73        }
74
75        SwipeEvent.prototype.onLeft = function (callback) {
76            this.onLeft = callback;
77            return this;
78        };
79        SwipeEvent.prototype.onRight = function (callback) {
80            this.onRight = callback;
81            return this;
82        };
83        SwipeEvent.prototype.onUp = function (callback) {
84            this.onUp = callback;
85            return this;
86        };
87        SwipeEvent.prototype.onDown = function (callback) {
88            this.onDown = callback;
89            return this;
90        };
91
92        SwipeEvent.prototype.handleTouchMove = function (evt) {
93            if (!this.xDown || !this.yDown) {
94                return;
95            }
96            var xUp = evt.touches[0].clientX;
97            var yUp = evt.touches[0].clientY;
98            this.xDiff = this.xDown - xUp;
99            this.yDiff = this.yDown - yUp;
100
101            if (Math.abs(this.xDiff) !== 0) {
102                if (this.xDiff > 2) {
103                    typeof (this.onLeft) === "function" && this.onLeft();
104                } else if (this.xDiff < -2) {
105                    typeof (this.onRight) === "function" && this.onRight();
106                }
107            }
108
109            if (Math.abs(this.yDiff) !== 0) {
110                if (this.yDiff > 2) {
111                    typeof (this.onUp) === "function" && this.onUp();
112                } else if (this.yDiff < -2) {
113                    typeof (this.onDown) === "function" && this.onDown();
114                }
115            }
116            // Reset values.
117            this.xDown = null;
118            this.yDown = null;
119        };
120
121        SwipeEvent.prototype.run = function () {
122            this.element.addEventListener('touchmove', function (evt) {
123                this.handleTouchMove(evt);
124            }.bind(this), false);
125        };
126
127        return SwipeEvent;
128    }());
129
130    // all in one price block - smoothly scroll to div
131    $(".stm_all_in_one_price_block .contact-btn").on('click', function (e) {
132        e.preventDefault();
133        var id = $(this).attr("href")
134        $('html, body').animate({
135            scrollTop: $(id).offset().top
136        }, 2000);
137    });
138
139    // EV dealer demo home footer contact scripts
140    function ev_home_footer_contact() {
141        // collapse the input
142        if ($(window).width() > 991) {
143            $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form input:not(.wpcf7-submit), .stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form textarea').css('height', '10px');
144        } else {
145            $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form input:not(.wpcf7-submit)').css('height', '43px');
146            $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form textarea').css('height', '100px');
147        }
148
149        // release on focus
150        $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form input:not(.wpcf7-submit)').on('focus', function () {
151            $(this).css({'height': '43px'});
152        });
153        $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form textarea').on('focus', function () {
154            $(this).css({'height': '100px'});
155        });
156
157        // return collapsed state if input is empty
158        $('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form input:not(.wpcf7-submit), .stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form textarea').on('focusout', function () {
159            let input_val = $(this).val();
160            if (input_val.length === 0 && $(window).width() > 991) {
161                $(this).css({'height': '10px'});
162            }
163        });
164    }
165
166    $(document).ready(function () {
167
168        var shareTimer;
169        var currentSelect;
170
171        $(document).on('click', '.language-switcher-unit', function () {
172            $(this).toggleClass('open');
173        });
174
175        $('[data-toggle="tooltip"]').tooltip();
176
177        $('body').on('click', '.c-l-test-drive', function () {
178            var carName = $('.carName').text();
179            $('.test-drive-car-name').text(carName);
180            $('input[name="vehicle_name"]').val(carName);
181            $('input[name="vehicle_id"]').val(0);
182        });
183
184        $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
185            $('img').trigger('appear');
186        });
187
188        if ($('body').hasClass('stm-boxed') && $('body').hasClass('stm-inventory-map-body')) {
189
190            var width = parseInt($('#main').width()) + 30;
191
192        }
193
194        $('.stm-more').on('click', function (e) {
195            e.preventDefault();
196            $(this).toggleClass('active');
197
198            $(this).closest('.stm_single_class_car, .stm_rental_option').find('.more').slideToggle();
199        });
200
201        stm_stretch_image();
202
203        if ($('.stm-simple-parallax').length) {
204            $('.stm-simple-parallax').append('<div class="stm-simple-parallax-gradient"><div class="stm-simple-parallax-vertical"></div></div>');
205            jQuery(window).on('scroll', function () {
206                var currentScrollPos = $(window).scrollTop();
207                var scrollOn = 400 - parseFloat(currentScrollPos / 1.2);
208                if (scrollOn < -200) {
209                    scrollOn = -200;
210                }
211                $('.stm-simple-parallax').css('background-position', '0 ' + scrollOn + 'px');
212            });
213        }
214
215        if ($('.stm-single-car-page').length && !$('body').hasClass('stm-template-car_dealer_two')) {
216            jQuery(window).on('scroll', function () {
217                var currentScrollPos = $(window).scrollTop();
218                var scrollOn = 200 - parseFloat(currentScrollPos / 1.2);
219                if (scrollOn < -200) {
220                    scrollOn = -200;
221                }
222
223                $('.stm-single-car-page').css('background-position', '0 ' + scrollOn + 'px');
224            });
225        }
226
227        stm_footer_selection();
228        stm_listing_mobile_functions();
229        if ($('.listing-nontransparent-header').length > 0) {
230            //$('#wrapper').css('padding-top', $('.listing-nontransparent-header').outerHeight() + 'px');
231        }
232
233        if ($('.stm-banner-image-filter').length > 0) {
234            var top = $('.stm-banner-image-filter').closest('.wpb_wrapper').offset().top;
235
236            if ($('body').hasClass('has_envato_iframe')) {
237                top = top - 54;
238                $('.stm-banner-image-filter').css('top', top + 'px');
239            }
240        }
241
242        $(document).on('click', '.stm_motorcycle_pp', function () {
243            $(this).toggleClass('active');
244            $(this).find('ul').toggleClass('activated');
245        });
246
247        $('.stm-material-parallax').parallax();
248
249        //Custom functions
250        stm_widget_color_first_word();
251        stm_widget_instagram();
252        footerToBottom();
253        stmFullwidthWithParallax();
254        stmMobileMenu();
255
256        stmShowListingIconFilter();
257
258        $('body').on('click', '.stm-after-video', function (e) {
259            var $this = $(this).closest('.stm-video-link-unit-wrap');
260            stm_listing_add_video_input($this, 2);
261        })
262
263        var $current_video_count = 1;
264
265        function stm_listing_add_video_input($video_unit, stm_restrict) {
266            var hasEmptyCount = 0;
267            var hasInputs = 0;
268            $('.stm-video-units .stm-video-link-unit-wrap').each(function () {
269                hasInputs++;
270                var stmVal = $(this).find('input').val();
271                if (stmVal.length !== 0) {
272                    hasEmptyCount++;
273                }
274            });
275
276            var $enable = (hasInputs - hasEmptyCount);
277
278            if ($enable < stm_restrict || hasInputs == 1) {
279                $current_video_count++;
280                var $video_label = $video_unit.find('.video-label').text();
281
282                var $new_item_string =
283                    '<div class="stm-video-link-unit-wrap">' +
284                    '<div class="heading-font">' +
285                    '<span class="video-label">' + $video_label + '</span>' +
286                    ' <span class="count">' + $current_video_count + '</span>' +
287                    '</div> ' +
288                    '<div class="stm-video-link-unit"> ' +
289                    '<input type="text" name="stm_video[]"> ' +
290                    '<div class="stm-after-video"></div> ' +
291                    '</div> ' +
292                    '</div>'
293
294                var new_item = $($new_item_string).hide();
295                $('.stm-video-units').append(new_item);
296                new_item.slideDown('fast');
297            }
298        }
299
300        function stmIsValidURL(str) {
301            var a = document.createElement('a');
302            a.href = str;
303            return (a.host && a.host != window.location.host) ? true : false;
304        }
305
306        $('body').on('input', '.stm-video-link-unit input[type="text"]', function (e) {
307            if ($(this).val().length > 0) {
308                if (stmIsValidURL($(this).val())) {
309                    $(this).closest('.stm-video-link-unit').find('.stm-after-video').addClass('active');
310                    var $this = $(this).closest('.stm-video-link-unit-wrap');
311                    stm_listing_add_video_input($this, 1);
312                }
313            } else {
314                $(this).closest('.stm-video-link-unit').find('.stm-after-video').removeClass('active');
315            }
316        });
317
318
319        if ($('.stm_automanager_features_list').length > 0) {
320            $('.wpb_tabs_nav li').on('click', function () {
321                var data_tab = $(this).attr('aria-controls');
322
323                if ($('#' + data_tab).find('.stm_automanager_features_list').length > 0) {
324                    $('.stm_automanager_features_list').isotope({
325                        // main isotope options
326                        itemSelector: '.stm_automanager_single'
327                    })
328                }
329            });
330        }
331
332        disableFancyHandy();
333
334        // Is on screen
335        $.fn.is_on_screen = function () {
336            var win = $(window);
337            var viewport = {
338                top: win.scrollTop(),
339                left: win.scrollLeft()
340            };
341            viewport.right = viewport.left + win.width();
342            viewport.bottom = viewport.top + win.height();
343
344            var bounds = this.offset();
345            bounds.right = bounds.left + this.outerWidth();
346            bounds.bottom = bounds.top + this.outerHeight();
347
348            return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
349        };
350
351        $('.stm-customize-page .wpb_tabs').remove();
352
353        //Default plugins
354
355
356        $('img.lazy').lazyload({
357            effect: "fadeIn",
358            failure_limit: Math.max('img'.length - 1, 0)
359        });
360
361        $('.owl-stage, .stm-single-image, .boat-gallery, .equip-gallery').lightGallery({
362            selector: '.stm_fancybox',
363            mode: 'lg-fade',
364            download: false
365        });
366
367        $('.owl-stage').lightGallery({
368            selector: '.fancy-iframe',
369            mode: 'lg-fade',
370            download: false
371        })
372
373        $('.fancy-iframe').lightGallery({
374            selector: 'this',
375            iframeMaxWidth: '80%',
376            mode: 'lg-fade',
377            download: false
378        })
379
380        $('#stm-google-map').lightGallery({
381            selector: 'this',
382            iframeMaxWidth: '80%',
383            mode: 'lg-fade',
384            download: false
385        })
386
387        $('#top-bar-address').lightGallery({
388            selector: 'this',
389            iframeMaxWidth: '80%',
390            mode: 'lg-fade',
391            download: false
392        })
393
394        $('.stm-carousel').lightGallery({
395            selector: '.stm_fancybox',
396            mode: 'lg-fade',
397            download: false
398        });
399
400        $('a.stm_fancybox').lightGallery({
401            selector: 'this',
402            mode: 'lg-fade',
403            download: false
404        });
405
406        $('#searchModal').on('shown.bs.modal', function (e) {
407            $('#searchform .search-input').trigger('focus');
408        });
409
410
411        $('p').each(function () {
412            if ($(this).html() == '') {
413                $(this).addClass('stm-hidden');
414            }
415        });
416
417        $('.calculated_shipping').on('DOMSubtreeModified', function (e) {
418        });
419
420        var pixelRatio = window.devicePixelRatio || 1;
421
422        if (typeof pixelRatio != 'undefined' && pixelRatio > 1) {
423            $('img').each(function () {
424                var stm_retina_image = $(this).data('retina');
425
426                if (typeof stm_retina_image != 'undefined') {
427                    $(this).attr('src', stm_retina_image);
428                }
429            })
430        }
431
432        $('body').on('click', '.car-action-unit.add-to-compare.disabled, a.stm_fancybox', function (e) {
433            e.preventDefault();
434            e.stopPropagation();
435        })
436
437        // Quantity actions
438        $('body').on('click', '.quantity_actions span', function () {
439            var quantityContainer = $(this).closest('.quantity'),
440                quantityInput = quantityContainer.find('.qty'),
441                quantityVal = quantityInput.attr('value');
442
443            $('.button.update-cart').removeAttr('disabled');
444
445            if ($(this).hasClass('plus')) {
446                quantityInput.attr('value', parseInt(quantityVal) + 1);
447            } else if ($(this).hasClass('minus')) {
448                if (quantityVal > 1) {
449                    quantityInput.attr('value', parseInt(quantityVal) - 1);
450                }
451            }
452        });
453
454        $('body').on('click', '.stm-modern-filter-unit-images .stm-single-unit-image', function () {
455
456            var stmHasChecked = false;
457            $('.stm-modern-filter-unit-images .stm-single-unit-image .image').addClass('non-active');
458            $('.stm-modern-filter-unit-images .stm-single-unit-image').each(function () {
459                var checked = $(this).find('input[type=checkbox]').prop('checked');
460                if (checked) {
461                    $(this).find('.image').removeClass('non-active');
462                    stmHasChecked = true;
463                }
464            });
465
466            if (!stmHasChecked) {
467                $('.stm-modern-filter-unit-images .stm-single-unit-image .image').removeClass('non-active');
468            }
469
470        })
471
472        $('.stm-modern-view-others').on('click', function (e) {
473            e.preventDefault();
474            $(this).closest('.stm-single-unit-wrapper').find('.stm-modern-filter-others').slideToggle('fast');
475        })
476
477        $('.header-help-bar-trigger').on('click', function () {
478            $(this).toggleClass('active');
479            $('.header-help-bar ul').slideToggle();
480        })
481
482        $('.header-menu').on('click', function (e) {
483            var link = $(this).attr('href');
484            if (link == '#') {
485                e.preventDefault();
486            }
487        })
488
489        $('#main .widget_search form.search-form input[type=search]').on('focus', function () {
490            $(this).closest('form').addClass('focus');
491        });
492
493        $('#main .widget_search form.search-form input[type=search]').on('focusout', function () {
494            $(this).closest('form').removeClass('focus');
495        });
496
497        $('body').on('change', '.stm-file-realfield', function () {
498            var length = $(this)[0].files.length;
499
500            if (length == 1) {
501                var uploadVal = $(this).val();
502                $(this).closest('.stm-pseudo-file-input').find(".stm-filename").text(uploadVal);
503            } else if (length == 0) {
504                $(this).closest('.stm-pseudo-file-input').find(".stm-filename").text('Choose file...');
505            } else if (length > 1) {
506                $(this).closest('.stm-pseudo-file-input').find(".stm-filename").text(length + ' files chosen');
507            }
508        });
509
510        $(".rev_slider_wrapper").each(function () {
511            var $this = $(this);
512            $this.on('revolution.slide.onloaded', function () {
513                setTimeout(function () {
514                    $('.stm-template-boats .wpb_revslider_element .button').addClass('loaded');
515                }, 1000);
516            });
517        });
518
519        $('.stm-share').on('click', function (e) {
520            e.preventDefault();
521        });
522
523        $('.stm-shareble').on({
524            mouseenter: function () {
525                $(this).parent().find('.stm-a2a-popup').addClass('stm-a2a-popup-active');
526            },
527            mouseleave: function () {
528                $(this).parent().find('.stm-a2a-popup').removeClass('stm-a2a-popup-active');
529            }
530        });
531
532        $('.unit-stm-moto-icon-share').on({
533            mouseenter: function () {
534                $(this).find('.stm-a2a-popup').addClass('stm-a2a-popup-active');
535            },
536            mouseleave: function () {
537                $(this).find('.stm-a2a-popup').removeClass('stm-a2a-popup-active');
538            }
539        });
540
541        $('.stm-gallery-action-unit').on({
542            mouseenter: function () {
543                if (shareTimer) {
544                    clearTimeout(shareTimer);
545                }
546                $(this).find('.stm-a2a-popup').addClass('stm-a2a-popup-active');
547            },
548            mouseleave: function () {
549                shareTimer = setTimeout(function () {
550                    if ($('.stm-a2a-popup-active:hover').length == 0) {
551                        $('.stm-a2a-popup').removeClass('stm-a2a-popup-active');
552                    }
553                }, 500);
554
555                $('.stm-a2a-popup-active').mouseleave(function () {
556                    $('.stm-a2a-popup').removeClass('stm-a2a-popup-active');
557                });
558            }
559        });
560
561        $('body').on('click', '.archive_request_price', function () {
562            var title = $(this).data('title');
563            var id = $(this).data('id');
564
565            $('#get-car-price form').find('.test-drive-car-name').text(title);
566            $('#get-car-price form').find('input[name="vehicle_id"]').val(id);
567        });
568
569        $('body').on(
570            'click',
571            '.listing-car-item-meta .price[data-target="#get-car-price"], .stm_moto_hover_unit .price [data-target="#get-car-price"], #listings-result .image .price [data-target="#get-car-price"]',
572            function (e) {
573                if ($(e.target).closest('a').length) {
574                    e.preventDefault()
575                }
576            }
577        )
578
579        if ($('.stm-hoverable-interactive-galleries .interactive-hoverable .hoverable-wrap').length > 0) {
580            // on desktop, hover
581            $(document).on('mousemove', '.interactive-hoverable .hoverable-wrap .hoverable-unit', function () {
582                var index = $(this).index();
583                if ($(this).parent().siblings('.hoverable-indicators').find('.indicator.active').index() !== index) {
584                    $(this).parent().siblings('.hoverable-indicators').find('.indicator.active').removeClass('active');
585                    $(this).parent().siblings('.hoverable-indicators').find('.indicator').eq(index).addClass('active');
586                }
587
588                $(this).siblings().removeClass('active');
589                $(this).addClass('active');
590            });
591
592            $(document).on('mouseleave', '.interactive-hoverable', function () {
593                $(this).find('.hoverable-indicators .indicator.active').removeClass('active');
594                $(this).find('.hoverable-indicators .indicator:first-child').addClass('active');
595
596                $(this).find('.hoverable-wrap .hoverable-unit.active').removeClass('active');
597                $(this).find('.hoverable-wrap .hoverable-unit:first-child').addClass('active');
598            });
599
600            // on mobile, swipe
601            stm_init_hoverable_swipe();
602        }
603
604        $('.mobile-contacts-trigger').on('click', function () {
605            $(this).toggleClass('open');
606            $('.header-top-info').toggleClass('open');
607
608            if ($('.mobile-menu-trigger').hasClass('opened')) {
609                $('html').trigger('removeNoScroll')
610                $('.mobile-menu-trigger').removeClass('opened');
611                $('.mobile-menu-holder').slideToggle();
612            }
613
614            if ($('.header-top-info').hasClass('open')) {
615                $('#stm-overlay').show();
616            } else {
617                $('#stm-overlay').hide();
618            }
619        });
620
621        // hoverable gallery preview using Brazzers Carousel library
622        var brazzers_carousel = $('.brazzers-carousel');
623        if (brazzers_carousel.length > 0) {
624            brazzers_carousel.brazzersCarousel();
625
626            brazzers_carousel.each(function () {
627                // remaining number of photos
628                if (typeof $(this).data('remaining') !== undefined && $(this).data('remaining') > 0) {
629                    let remaining_number = parseInt($(this).data('remaining'));
630                    var remaining_label = remaining_number + ' ' + photo_remaining_singular;
631                    if (remaining_number > 1) {
632                        var remaining_label = remaining_number + ' ' + photo_remaining_plural;
633                    }
634
635                    $(this).find('.tmb-wrap').append('<div class="remaining"><i class="stm-icon-album"></i><p>' + remaining_label + '</p></div>');
636                }
637            });
638
639            $('.brazzers-carousel .tmb-wrap-table >
639 div:nth-child(5)').on('mouseenter', function () {
640                $(this).parent().siblings('.remaining').addClass('active');
641            });
642
643            $('.brazzers-carousel .tmb-wrap-table > div:nth-child(5)').on('mouseleave', function () {
644                $(this).parent().siblings('.remaining').removeClass('active');
645            });
646
647            $('.brazzers-carousel .tmb-wrap').on('mouseleave', function () {
648                $(this).find('.tmb-wrap-table > div').removeClass('active');
649                $(this).find('.tmb-wrap-table > div:first-child').trigger('mouseenter');
650            });
651        }
652
653        $(document).on('mouseenter', '.select2-selection__rendered', function () {
654            $(this).attr('title', $.trim($(this).attr('title')));
655        });
656
657    }); // end of "document ready"
658
659    function stm_init_hoverable_swipe() {
660        if ($('.stm-hoverable-interactive-galleries .interactive-hoverable .hoverable-wrap').length > 0) {
661            $('.stm-hoverable-interactive-galleries .interactive-hoverable .hoverable-wrap').each((index, el) => {
662                let galleryPreviewSwiper = new SwipeEvent(el);
663
664                galleryPreviewSwiper.onRight(function () {
665                    let active_index = $(this.element).find('.hoverable-unit.active').index();
666                    $(this.element).find('.hoverable-unit').removeClass('active');
667                    $(this.element).siblings('.hoverable-indicators').find('.indicator.active').removeClass('active');
668                    if (active_index === 0) {
669                        $(this.element).find('.hoverable-unit:last-child').addClass('active');
670                        $(this.element).siblings('.hoverable-indicators').find('.indicator:last-child').addClass('active');
671                    } else {
672                        $(this.element).find('.hoverable-unit').eq(active_index - 1).addClass('active');
673                        $(this.element).siblings('.hoverable-indicators').find('.indicator').eq(active_index - 1).addClass('active');
674                    }
675                });
676
677                galleryPreviewSwiper.onLeft(function () {
678                    let active_index = $(this.element).find('.hoverable-unit.active').index();
679                    let total_items = $(this.element).find('.hoverable-unit');
680                    $(this.element).find('.hoverable-unit').removeClass('active');
681                    $(this.element).siblings('.hoverable-indicators').find('.indicator.active').removeClass('active');
682                    if (active_index === parseInt(total_items.length - 1)) {
683                        $(this.element).find('.hoverable-unit:first-child').addClass('active');
684                        $(this.element).siblings('.hoverable-indicators').find('.indicator:first-child').addClass('active');
685                    } else {
686                        $(this.element).find('.hoverable-unit').eq(active_index + 1).addClass('active');
687                        $(this.element).siblings('.hoverable-indicators').find('.indicator').eq(active_index + 1).addClass('active');
688                    }
689                });
690
691                galleryPreviewSwiper.run();
692            });
693        }
694    }
695
696    $(window).on('load', function () {
697        footerToBottom();
698        stmFullwidthWithParallax();
699
700        stm_stretch_image();
701        $('.stm-blackout-overlay').addClass('stm-blackout-loaded');
702
703        // if preloader_timer empty
704        if (preloader_timer === undefined || preloader_timer === null || preloader_timer === '') {
705            stmPreloader();
706        }
707
708        if ($('.stm-banner-image-filter').length > 0) {
709            var top = $('.stm-banner-image-filter').closest('.wpb_wrapper').offset().top;
710
711            if ($('body').hasClass('has_envato_iframe')) {
712                top = top - 54;
713                $('.stm-banner-image-filter').css('top', top + 'px');
714            }
715        }
716
717        // ev dealer demo home footer contact
718        if ($('.stm-template-ev_dealer .ev_footer_contact_block .wpcf7-form').length > 0) {
719            ev_home_footer_contact();
720        }
721
722    }); // end of "window on load"
723
724    $(window).on('resize', function () {
725        footerToBottom();
726        stmFullwidthWithParallax();
727
728        stm_stretch_image();
729
730        disableFancyHandy();
731        if ($('.stm-banner-image-filter').length > 0) {
732            var top = $('.stm-banner-image-filter').closest('.wpb_wrapper').offset().top;
733
734            if ($('body').hasClass('has_envato_iframe')) {
735                top = top - 54;
736                $('.stm-banner-image-filter').css('top', top + 'px');
737            }
738        }
739
740        // ev dealer demo home footer contact
741        ev_home_footer_contact();
742
743    });
744
745    //if preloader timer not empty
746    if (preloader_timer !== undefined || preloader_timer !== null || preloader_timer !== '') {
747        setTimeout(function () {
748            stmPreloader();
749        }, preloader_timer);
750    }
751
752    function loadVisible($els, trigger) {
753        $els.filter(function () {
754            var rect = this.getBoundingClientRect();
755            return rect.top >= 0 && rect.top <= window.innerHeight;
756        }).trigger(trigger);
757    }
758
759    function footerToBottom() {
760        var windowH = $(window).height();
761        var footerH = $('#footer').outerHeight();
762        $('#wrapper').css('min-height', (windowH - footerH) + 'px');
763    };
764
765    function stm_widget_color_first_word() {
766        // don't apply for electric vehicle layout
767        if ($('body').hasClass('stm-template-ev_dealer')) {
768            return false;
769        }
770
771			// go ahead for other layouts
772			$('.stm_wp_widget_text .widget-title h6').each(function () {
773				var html = $(this).html()
774				var spaceIndex = html.indexOf(' ')
775
776				if (spaceIndex === -1) {
777					$(this).html($('<span/>').html(html).addClass('colored'))
778				} else {
779					var word = html.substr(0, spaceIndex)
780					var rest = html.substr(spaceIndex)
781					$(this)
782						.html(rest)
783						.prepend($('<span/>').html(word).addClass('colored'))
784				}
785			})
786		}
787
788    function stm_widget_instagram() {
789        $('#sb_instagram').closest('.widget-wrapper').addClass('stm-instagram-unit');
790    }
791
792    function stmFullwidthWithParallax() {
793        var screenWidth = $(window).width();
794        if (screenWidth < 1140) {
795            var defaultWidth = screenWidth - 30;
796        } else {
797            var defaultWidth = 1140 - 30;
798        }
799        var marginLeft = (screenWidth - defaultWidth) / 2;
800
801        if ($('body').hasClass('rtl')) {
802            $('.stm-fullwidth-with-parallax').css({
803                'position': 'relative',
804                'left': (marginLeft - 15) + 'px'
805            })
806        }
807
808        $('.stm-fullwidth-with-parallax').css({
809            'width': screenWidth + 'px',
810            'margin-left': '-' + marginLeft + 'px',
811            'padding-left': (marginLeft - 15) + 'px',
812            'padding-right': (marginLeft - 15) + 'px'
813        })
814    }
815
816    function stmMobileMenu() {
817
818        let mobile_menu_holder = $('.mobile-menu-trigger')
819
820        mobile_menu_holder.on('click', function () {
821
822            let $this = $(this)
823            if ($this.hasClass('opened')) {
824                $('html').trigger('removeNoScroll')
825            } else {
826                $('html').trigger('addNoScroll')
827            }
828
829            $this.toggleClass('opened');
830            $('.mobile-menu-holder').slideToggle();
831
832
833            // close the contacts dropdown
834            if ($('.mobile-contacts-trigger').length > 0) {
835                $('.mobile-contacts-trigger').removeClass('open');
836                $('.header-top-info').removeClass('open');
837            }
838
839            if ($('.header-top-info').hasClass('open')) {
840                $('#stm-overlay').show();
841            } else {
842                $('#stm-overlay').hide();
843            }
844        });
845
846
847        $(".mobile-menu-holder .header-menu li.menu-item-has-children > a")
848            .after('<span class="arrow"><i class="fas fa-angle-right"></i></span>');
849
850        $(".magazine-menu-mobile > li.menu-item-has-children > a")
851            .after('<span class="arrow"><i class="fas fa-angle-right"></i></span>');
852
853        let arrow = $('.mobile-menu-holder .header-menu .arrow')
854        arrow.parents('.stm_megamenu').find('> ul.sub-menu').hide();
855        arrow.on('click', function () {
856
857            $(this).toggleClass('active');
858
859            $(this).closest('li').toggleClass('opened');
860
861            if (!$(this).parent().hasClass('stm_megamenu')) {
862
863                $(this).closest('li').find('> ul.sub-menu').slideToggle(300);
864
865                // hide any existing subs
866                if ($(this).closest('li').find('> ul.sub-menu').has('.sub-menu').length > 0) {
867                    $(this).closest('li').find('> ul.sub-menu').find('ul.sub-menu').hide();
868                    $(this).closest('li').find('> ul.sub-menu').find('.arrow').removeClass('active');
869                }
870            } else {
871                // if contains megamenu
872                $(this).closest('li').find('> ul.sub-menu').slideToggle(300);
873            }
874        });
875
876        // if menu item with "#" link is clicked
877        $(".mobile-menu-holder .header-menu > li.menu-item-has-children > a").on('click', function (e) {
878
879            if ($(this).attr('href') == '#') {
880
881                e.preventDefault();
882
883                $(this).closest('li').find(' > ul.sub-menu').slideToggle(300);
884
885                $(this).closest('li').toggleClass('opened');
886
887                $(this).closest('li').find(' > .arrow').toggleClass('active');
888
889                // hide any existing subs
890                if ($(this).closest('li').find('> ul.sub-menu').has('.sub-menu').length > 0) {
891                    $(this).closest('li').find('> ul.sub-menu').find('ul.sub-menu').hide();
892                    $(this).closest('li').find('> ul.sub-menu').find('.arrow').removeClass('active');
893                }
894            }
895        });
896
897        $('body').on('click', '.magazine-menu-mobile > li.menu-item-has-children >.arrow', function (e) {
898            $(this).parent().toggleClass('active');
899        });
900
901        let html = $('html');
902        html.on('addNoScroll', addNoScroll)
903        html.on('removeNoScroll', removeNoScroll);
904
905    }
906
907    function addNoScroll(el) {
908        if (!el) {
909            el = $('html')
910        }
911
912        if (typeof el === 'object' && el.hasOwnProperty('currentTarget')) {
913            el = $(el.currentTarget)
914        }
915
916        el.addClass('no-scroll');
917    }
918
919    function removeNoScroll(el) {
920        if (!el) {
921            el = $('html')
922        }
923
924        if (typeof el === 'object' && el.hasOwnProperty('currentTarget')) {
925            el = $(el.currentTarget)
926        }
927
928        el.removeClass('no-scroll');
929    }
930
931    let is_header = {
932            car_magazine: false,
933            dealer: false,
934        },
935        body = $('body')
936
937    if (body.hasClass('stm-layout-header-car_magazine')) {
938        is_header.car_magazine = true
939    }
940
941    if (body.hasClass('stm-layout-header-car_dealer')) {
942        is_header.dealer = true
943    }
944
945    $(window).ready(setMobileMenuHeight);
946    $(window).resize(setMobileMenuHeight);
947    $(window).scroll(setMobileMenuHeight);
948
949    function setMobileMenuHeight() {
950        let header_main = $('#header > div.header-main, #header > div.header-listing'),
951            mobile_menu_holder = $('.mobile-menu-holder')
952
953        if (is_header.car_magazine) {
954            header_main = $('#header > div.header-magazine')
955            mobile_menu_holder = $('.stm-opened-menu-magazine')
956        }
957
958        if (window.innerWidth > 1025 || !header_main.length || !mobile_menu_holder.length) {
959            return
960        }
961
962        let top_bar = $('#top-bar'),
963            top_bar_height = top_bar.outerHeight(),
964            header_main_height = header_main.outerHeight(),
965            _top_bar_offset = 0, _header_main_offset = 0;
966
967        //don't calculate top-bar if menu is fixed
968        if (header_main.hasClass('stm-fixed')) {
969            top_bar_height = 0
970        }
971
972        if (!top_bar_height) {
973            top_bar_height = 0
974        }
975
976        if (!header_main_height) {
977            header_main_height = 0
978        }
979
980        if (top_bar.length) {
981            _top_bar_offset = top_bar.offset().top
982        }
983
984        _header_main_offset = header_main.offset().top
985
986        let top_bar_offset = _top_bar_offset,
987            top_bar_visible_height = calculateVisibleHeight(top_bar_height, top_bar_offset),
988            header_main_offset = _header_main_offset,
989            header_main_visible_height = calculateVisibleHeight(header_main_height, header_main_offset)
990
991        let calculated_height = window.innerHeight - top_bar_visible_height - header_main_visible_height
992        mobile_menu_holder.css('height', calculated_height)
993
994        if (is_header.dealer) {
995            mobile_menu_holder.css('top', header_main_height)
996        }
997    }
998
999    function calculateVisibleHeight(elHeight, elOffset) {
1000        if (!elHeight) {
1001            elHeight = 0
1002        }
1003
1004        if (!elOffset) {
1005            elOffset = 0
1006        }
1007
1008        let scrollY = window.scrollY,
1009            visible_height = elHeight
1010
1011        if (scrollY > elOffset) {
1012            visible_height = (elOffset + elHeight) - scrollY
1013        }
1014
1015        if ((elOffset + scrollY) < elHeight) {
1016            visible_height = elHeight - (elOffset + scrollY)
1017        }
1018
1019        if ((elOffset + scrollY) < elHeight && elOffset > scrollY) {
1020            visible_height = elHeight
1021        }
1022
1023        if ((elOffset + elHeight) < scrollY) {
1024            visible_height = 0
1025        }
1026
1027        return visible_height
1028    }
1029
1030    function disableFancyHandy() {
1031        var winWidth = $(window).width();
1032        if (winWidth < 1025) {
1033            $('.media-carousel-item .stm_fancybox').on('click', function (e) {
1034                e.preventDefault();
1035                e.stopPropagation();
1036            })
1037        }
1038    }
1039
1040    function stmPreloader() {
1041        if ($('html').hasClass('stm-site-preloader')) {
1042            $('html').addClass('stm-site-loaded');
1043
1044            if (preloader_timer === undefined || preloader_timer === null || preloader_timer === '') { // if preloader timer is not set
1045                setTimeout(function () {
1046                    $('html').removeClass('stm-site-preloader stm-site-loaded');
1047                }, 250);
1048                var prevent = false;
1049                $('a[href^=mailto], a[href^=skype], a[href^=tel]').on('click', function (e) {
1050                    prevent = true;
1051                    $('html').removeClass('stm-site-preloader stm-after-hidden');
1052                });
1053
1054                $(window).on('beforeunload', function (e, k) {
1055                    if (!prevent) {
1056                        $('html').addClass('stm-site-preloader stm-after-hidden');
1057                    } else {
1058                        prevent = false;
1059                    }
1060                });
1061            } else { // if preloader timer is set
1062                $('html').removeClass('stm-site-preloader stm-site-loaded');
1063            }
1064        }
1065    }
1066
1067    function stmShowListingIconFilter() {
1068        $('.stm_icon_filter_label').on('click', function () {
1069
1070            if (!$(this).hasClass('active')) {
1071                $(this).closest('.stm_icon_filter_unit').find('.stm_listing_icon_filter').toggleClass('active');
1072                $(this).closest('.stm_icon_filter_unit').find('.stm_listing_icon_filter .image').hide();
1073
1074                $(this).addClass('active');
1075            } else {
1076                $(this).closest('.stm_icon_filter_unit').find('.stm_listing_icon_filter').toggleClass('active');
1077                $(this).closest('.stm_icon_filter_unit').find('.stm_listing_icon_filter .image').show();
1078
1079                $(this).removeClass('active');
1080            }
1081
1082        });
1083    }
1084
1085    function stm_footer_selection() {
1086        if (typeof stm_footer_terms !== 'undefined') {
1087            var substringMatcher = function (strs) {
1088                return function findMatches(q, cb) {
1089                    var matches, substringRegex;
1090
1091                    // an array that will be populated with substring matches
1092                    matches = [];
1093
1094                    // regex used to determine if a string contains the substring `q`
1095                    var substrRegex = new RegExp(q, 'i');
1096
1097                    // iterate through the pool of strings and for any string that
1098                    // contains the substring `q`, add it to the `matches` array
1099                    $.each(strs, function (i, str) {
1100                        if (substrRegex.test(str)) {
1101                            matches.push(str);
1102                        }
1103                    });
1104
1105                    cb(matches);
1106                };
1107            };
1108
1109            var $input = $('.stm-listing-layout-footer .stm-footer-search-inventory input');
1110
1111            var selectedValue = '';
1112
1113            $input.typeahead({
1114                hint: true,
1115                highlight: true,
1116                minLength: 1
1117            }, {
1118                name: 'stm_footer_terms',
1119                source: substringMatcher(stm_footer_terms)
1120            });
1121
1122            $input.typeahead('val', stm_default_search_value).trigger('keyup');
1123            $input.typeahead('close');
1124
1125            $input.on('keydown', function () {
1126                selectedValue = $(this).val();
1127            })
1128
1129            $input.on('typeahead:select', function (ev, suggestion) {
1130                selectedValue = suggestion;
1131            });
1132
1133            var enableSubmission = false;
1134            $('.stm-footer-search-inventory form').on('submit', function (e) {
1135                if (!enableSubmission) {
1136                    e.preventDefault();
1137                }
1138                var keyChosen = $.inArray(selectedValue, stm_footer_terms);
1139                if (keyChosen != -1) {
1140                    var slug = stm_footer_terms_slugs[keyChosen];
1141                    var taxonomy = stm_footer_taxes[keyChosen];
1142                    if (typeof (taxonomy) != 'undefined' && typeof (slug) != 'undefined' && !enableSubmission) {
1143                        $input.attr('name', taxonomy);
1144                        $input.val(slug);
1145                        enableSubmission = true;
1146                        $(this).trigger('submit');
1147                    }
1148                } else {
1149                    if (!enableSubmission) {
1150                        enableSubmission = true;
1151                        $(this).trigger('submit');
1152                    }
1153                }
1154
1155            });
1156        }
1157    }
1158
1159    $('.stm-form-1-end-unit input[type="text"]').on('blur', function () {
1160        if ($(this).val() == '') {
1161            $(this).removeClass('stm_has_value');
1162        } else {
1163            $(this).addClass('stm_has_value');
1164        }
1165    });
1166
1167    function stm_listing_mobile_functions() {
1168        $('.listing-menu-mobile > li.menu-item-has-children > a').append('<span class="stm_frst_lvl_trigger"></span>');
1169        $('body').on('click', '.stm_frst_lvl_trigger', function (e) {
1170            e.preventDefault();
1171            $(this).closest('li').find('ul.sub-menu').slideToggle();
1172            $(this).closest('li').toggleClass('show_submenu');
1173            $(this).closest('li').toggleClass('active');
1174            $(this).toggleClass('active');
1175        });
1176
1177        $('.boats-menu-ipad > li.menu-item-has-children > a').addClass('has-child');
1178        $('body').on('click', 'a.has-child', function (e) {
1179
1180            if ($(this).hasClass('active')) {
1181                $(this).parent().trigger('blur');
1182                $(this).toggleClass('active');
1183            } else {
1184                e.preventDefault();
1185                $(this).toggleClass('active');
1186            }
1187        });
1188
1189        $('.boats-menu-ipad > li.menu-item-has-children > a.has-child').each(function () {
1190            $(this).parent().on('focusout', function () {
1191                $('.boats-menu-ipad > li.menu-item-has-children > a.has-child').removeClass('active');
1192            });
1193        });
1194
1195        $('.lOffer-account-dropdown.stm-login-form-unregistered form input').on('focus', function () {
1196
1197            $('.lOffer-account-unit').find('.lOffer-account').addClass('active');
1198            $('.lOffer-account-unit').find('.lOffer-account-dropdown.stm-login-form-unregistered').addClass('active');
1199
1200        })
1201
1202        $('.lOffer-account-dropdown.stm-login-form-unregistered form input').on('blur', function () {
1203            $('.lOffer-account-unit').find('.lOffer-account').removeClass('active');
1204            $('.lOffer-account-unit').find('.lOffer-account-dropdown.stm-login-form-unregistered').removeClass('active');
1205        })
1206
1207        $('.stm-menu-trigger').on('click', function () {
1208
1209            $('.lOffer-account').removeClass('active');
1210            $('.stm-user-mobile-info-wrapper').removeClass('active');
1211
1212            $('.stm-opened-menu-listing').toggleClass('opened');
1213            $('.stm-opened-menu-magazine').toggleClass('opened');
1214
1215            let $this = $(this);
1216            if ($this.hasClass('opened')) {
1217                $('html').trigger('removeNoScroll');
1218            } else {
1219                $('html').trigger('addNoScroll');
1220            }
1221
1222            $this.toggleClass('opened');
1223
1224        });
1225
1226        $('.lOffer-account').on('click', function (e) {
1227            e.preventDefault();
1228
1229            let $this = $(this),
1230                html = $('html');
1231
1232            $('.stm-opened-menu-listing').removeClass('opened');
1233            $('.stm-opened-menu-magazine').removeClass('opened');
1234            html.trigger('removeNoScroll');
1235            $('.stm-menu-trigger').removeClass('opened');
1236
1237            if (window.matchMedia("(max-width: 990px)").matches) {
1238                if ($this.hasClass('active')) {
1239                    html.trigger('removeNoScroll');
1240                } else {
1241                    html.trigger('addNoScroll');
1242                }
1243            }
1244
1245            $(this).toggleClass('active');
1246
1247            $(this).closest('.lOffer-account-unit').find('.stm-user-mobile-info-wrapper').toggleClass('active');
1248        });
1249
1250
1251        $('.stm-rent-lOffer-account').on('click', function (e) {
1252            e.preventDefault();
1253
1254            $('.stm-opened-menu-listing').removeClass('opened');
1255            $('.stm-opened-menu-magazine').removeClass('opened');
1256            $('html').trigger('removeNoScroll');
1257            $('.stm-menu-trigger').removeClass('opened');
1258
1259            $(this).toggleClass('active');
1260
1261            $(this).closest('.stm-rent-lOffer-account-unit').find('.stm-user-mobile-info-wrapper').toggleClass('active');
1262        });
1263
1264
1265        $(document).ready(function () {
1266            function updateCarListing() {
1267                var selectedOption = $('.stm-select-sorting select').val()
1268
1269                if (selectedOption === 'popular') {
1270                    $('.user-listings-wrapper#popular').addClass('active')
1271                    $('.user-listings-wrapper#recent').removeClass('active')
1272                } else {
1273                    $('.user-listings-wrapper#popular').removeClass('active')
1274                    $('.user-listings-wrapper#recent').addClass('active')
1275                }
1276            }
1277
1278            updateCarListing()
1279
1280            $('.stm-select-sorting select').on('change', function () {
1281                updateCarListing()
1282            })
1283        })
1284
1285
1286
1287        $(document).ready(function () {
1288            function updateCarListing() {
1289                var selectedOption = $('.stm-select-sorting select').val()
1290
1291                if (selectedOption === 'popular') {
1292                    $('.user-listings-wrapper#popular').addClass('active')
1293                    $('.user-listings-wrapper#recent').removeClass('active')
1294                } else {
1295                    $('.user-listings-wrapper#popular').removeClass('active')
1296                    $('.user-listings-wrapper#recent').addClass('active')
1297                }
1298            }
1299
1300            updateCarListing()
1301
1302            $('.stm-select-sorting select').on('change', function () {
1303                updateCarListing()
1304            })
1305        })
1306
1307
1308        $('body').on('click', function (e) {
1309            if ($(e.target).closest('#header').length === 0) {
1310                $('.lOffer-account').removeClass('active');
1311                $('.stm-user-mobile-info-wrapper').removeClass('active');
1312                $('.stm-login-form-unregistered').removeClass('active');
1313                $('.stm-opened-menu-listing').removeClass('opened');
1314                $('.stm-opened-menu-magazine').removeClass('opened');
1315                $('html').trigger('removeNoScroll');
1316                $('.stm-menu-trigger').removeClass('opened');
1317            }
1318        });
1319
1320
1321        /*Boats*/
1322        $('.stm-menu-boats-trigger').on('click', function () {
1323            let $this = $(this);
1324            if ($this.hasClass('opened')) {
1325                setTimeout(removeNoScroll)
1326            } else {
1327                setTimeout(addNoScroll)
1328            }
1329            $this.toggleClass('opened');
1330            $('.stm-boats-mobile-menu').toggleClass('opened');
1331        });
1332
1333        $('.stm-boats-mobile-menu .listing-menu > li.menu-item-has-children > a').append('<span class="stm-boats-menu-first-lvl"></span>');
1334
1335        $('body').on('click', '.stm-boats-menu-first-lvl', function (e) {
1336            e.preventDefault();
1337            $(this).closest('li').find('ul.sub-menu').toggle();
1338            $(this).parent().parent().toggleClass('active');
1339            $(this).toggleClass('active');
1340        });
1341    }
1342
1343    function shortenText(element, maxLength) {
1344        element.each(function() {
1345            var text = $(this).text();
1346
1347            if (text.length > maxLength) {
1348                $(this).text(text.slice(0, maxLength) + "...");
1349            }
1350        });
1351    }
1352
1353    shortenText($('.lOffer-account-dropdown .name a'), 15);
1354    shortenText($('.stm-dealer-mail .mail a'), 27);
1355
1356    var lazyTimeout;
1357
1358    $('#stm-dealer-view-type').on('change', function () {
1359        var tabId = $(this).val();
1360        $('a[href=#' + tabId + ']').tab('show');
1361        $('.select-listing-type select').trigger('change');
1362
1363        if (lazyTimeout) clearTimeout(lazyTimeout);
1364        setTimeout(function () {
1365            $("img.lazy").show().lazyload();
1366        }, 200);
1367    });
1368
1369    $('.service-mobile-menu-trigger').on('click', function () {
1370        $('.header-service .header-menu').slideToggle();
1371        let $this = $(this);
1372        if ($this.hasClass('active')) {
1373            $('html').trigger('removeNoScroll');
1374        } else {
1375            $('html').trigger('addNoScroll');
1376        }
1377        $(this).toggleClass('active');
1378    });
1379
1380    updateGridItemTitles();
1381
1382})(jQuery);
1383
1384function updateGridItemTitles() {
1385    var $ = jQuery;
1386
1387    $('.car-title').each(function () {
1388        var $title = $(this);
1389        var maxChar = parseInt($title.attr('data-max-char'));
1390        var $labels = $title.find('.labels');
1391
1392        if ($labels.length > 0 && ($(this).text().length > maxChar)) {
1393            var originalLabels = $labels.clone();
1394            $labels.remove();
1395            var originalText = $title.contents().filter(function () {
1396                return this.nodeType === 3;
1397            }).text().trim();
1398
1399            if (originalText.length > maxChar) {
1400                var truncatedText = originalText.substr(0, maxChar) + '...';
1401
1402                $title.html('').append(originalLabels).append(truncatedText);
1403            } else {
1404                $title.html(originalText).prepend($labels)
1405            }
1406        } else {
1407            if ($(this).attr('data-max-char') != 'undefined' && $(this).text().length > $(this).attr('data-max-char')) {
1408                $(this).text($(this).text().trim().substr(0, $(this).attr('data-max-char')) + '...');
1409            }
1410        }
1411    });
1412}
1413
1414function stm_stretch_image() {
1415    var $ = jQuery;
1416    var position = '.stm-stretch-image-right';
1417
1418    if ($(position).length) {
1419        var windowW = $(document).width();
1420        var containerW = $('.header-main .container').width();
1421
1422        var marginW = (windowW - containerW) / 2;
1423
1424        $(position + ' .vc_column-inner').css({
1425            'margin-right': '-' + marginW + 'px'
1426        });
1427    }
1428
1429    position = '.stm-stretch-image-left';
1430
1431    if ($(position).length) {
1432        var windowW = $(document).width();
1433        var containerW = $('.header-main .container').width();
1434
1435        var marginW = (windowW - containerW) / 2;
1436
1437        $(position + ' .vc_column-inner').css({
1438            'margin-left': '-' + marginW + 'px'
1439        });
1440    }
1441}
1442
1443function stm_isotope_sort_function(currentChoice) {
1444
1445    var $ = jQuery;
1446    var stm_choice = currentChoice;
1447    var $container = $('.stm-isotope-sorting');
1448    switch (stm_choice) {
1449        case 'price_low':
1450            $container.isotope({
1451                getSortData: {
1452                    price: function (itemElem) {
1453                        var price = $(itemElem).data('price');
1454                        return parseFloat(price);
1455                    }
1456                },
1457                sortBy: 'price',
1458                sortAscending: true
1459            });
1460            break;
1461        case 'price_high':
1462            $container.isotope({
1463                getSortData: {
1464                    price: function (itemElem) {
1465                        var price = $(itemElem).data('price');
1466                        return parseFloat(price);
1467                    }
1468                },
1469                sortBy: 'price',
1470                sortAscending: false
1471            });
1472            break;
1473        case 'date_low':
1474            $container.isotope({
1475                getSortData: {
1476                    date: function (itemElem) {
1477                        var date = $(itemElem).data('date');
1478                        return parseFloat(date);
1479                    },
1480                },
1481                sortBy: 'date',
1482                sortAscending: true
1483            });
1484            break;
1485        case 'date_high':
1486            $container.isotope({
1487                getSortData: {
1488                    date: function (itemElem) {
1489                        var date = $(itemElem).data('date');
1490                        return parseFloat(date);
1491                    },
1492                },
1493                sortBy: 'date',
1494                sortAscending: false
1495            });
1496            break;
1497        case 'mileage_low':
1498            $container.isotope({
1499                getSortData: {
1500                    mileage: function (itemElem) {
1501                        var mileage = $(itemElem).data('mileage');
1502                        return parseFloat(mileage);
1503                    }
1504                },
1505                sortBy: 'mileage',
1506                sortAscending: true
1507            });
1508            break;
1509        case 'mileage_high':
1510            $container.isotope({
1511                getSortData: {
1512                    mileage: function (itemElem) {
1513                        var mileage = $(itemElem).data('mileage');
1514                        return parseFloat(mileage);
1515                    }
1516                },
1517                sortBy: 'mileage',
1518                sortAscending: false
1519            });
1520            break;
1521        case 'distance':
1522            $container.isotope({
1523                getSortData: {
1524                    distance: function (itemElem) {
1525                        var distance = $(itemElem).data('distance');
1526                        return parseFloat(distance);
1527                    }
1528                },
1529                sortBy: 'distance',
1530                sortAscending: true
1531            });
1532            break;
1533        default:
1534    }
1535
1536    $container.isotope('updateSortData').isotope();
1537}
1538
1539
1540var stmMotorsCaptcha = function () {
1541    jQuery('.g-recaptcha').each(function (index, el) {
1542        var $ = jQuery;
1543        grecaptcha.render(el, {'sitekey': $(el).data('sitekey')});
1544    });
1545};
1546
1547function stm_check_mobile() {
1548    var isMobile = false; //initiate as false
1549    if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
1550        || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|
1550sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) isMobile = true;
1551    return isMobile;
1552}
1553
1554(function ($) {
1555    window.STMCascadingSelect = function STMCascadingSelect(container, relations) {
1556        let self = this;
1557
1558        self.relations = relations;
1559        self.ctx = container;
1560        self.options = {
1561            selectBoxes: []
1562        };
1563
1564        if (self.relations && Object.keys(self.relations).length) {
1565            let selectBoxes = [];
1566
1567            $.each(self.relations, function (slug, options) {
1568                let selectBox = self.selectbox(slug, options);
1569
1570                if (selectBox && typeof selectBox === 'object') {
1571                    selectBoxes.push(selectBox);
1572                }
1573            });
1574
1575            if (selectBoxes.length) {
1576                self.options.selectBoxes = self.options.selectBoxes.concat(selectBoxes);
1577            }
1578        }
1579
1580        $(container).cascadingDropdown(self.options);
1581    };
1582
1583    STMCascadingSelect.prototype.selectbox = function (slug, config) {
1584        var parent = config.dependency;
1585
1586        if (!$(this.selector(slug), this.ctx).length || (parent && !$(this.selector(parent), this.ctx).length)) {
1587            return null;
1588        }
1589
1590        var $select = $(this.selector(slug), this.ctx);
1591        var selected = $select.data('selected');
1592
1593        if ($select.prop('multiple')) {
1594            selected = selected ? selected.split(',') : [];
1595        }
1596
1597        return {
1598            selector: this.selector(slug),
1599            paramName: slug,
1600            requires: parent ? [this.selector(parent)] : null,
1601            allowAll: config.allowAll,
1602            selected: selected,
1603            source: function (request, response) {
1604                var selected = request[parent];
1605                var options = [];
1606                $.each(config.options, function (i, option) {
1607                    if ((config.allowAll && !selected) || (option.deps && option.deps.indexOf(selected) >= 0)) {
1608                        options.push(option);
1609                    }
1610                });
1611
1612                response(options);
1613            }
1614        };
1615    };
1616
1617    STMCascadingSelect.prototype.selector = function (slug) {
1618        if (this.relations[slug].selector) {
1619            return this.relations[slug].selector;
1620        }
1621
1622        return '[name="' + slug + '"]';
1623    }
1624
1625})(jQuery);

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.