1"use strict"; 2(function($) { 3 4 function SearchBox (form) { 5 let body = $( 'body' ); 6 7 STMListings.SearchBox.form = form; 8 STMListings.SearchBox.listing = ( body.hasClass( 'stm-template-aircrafts' ) && ! body.hasClass( 'single-listings' ) ); 9 STMListings.SearchBox.prototype.init(); 10 } 11 12 SearchBox.prototype.init = function () { 13 var timer, self = this; 14 15 $( 'select:not(.hide)', STMListings.SearchBox.form ).select2().on( 16 'select2:selecting', 17 function ( event ) { 18 if ( timer ) { 19 clearTimeout( timer ); 20 } 21 22 STMListings.SearchBox.form = $( event.target ).closest( 'form' ); 23 24 timer = setTimeout( $.proxy( self.performAjax, self ), 300 ); 25 } 26 ); 27 28 $( document ).on( 29 'slidestop', 30 '.taxonomy_range_wrap .ui-slider-wrap', 31 function (event, ui) { 32 let min = ui.values.shift(), 33 max = ui.values.shift(), 34 $el = $( event.target ).closest( '.taxonomy_range_wrap' ); 35 36 if ( timer ) { 37 clearTimeout( timer ); 38 } 39 40 if ( min && max ) { 41 $( '.stm-min-value', $el ).val( min ); 42 $( '.stm-max-value', $el ).val( max ); 43 44 STMListings.SearchBox.form = $el.closest( 'form' ); 45 46 timer = setTimeout( $.proxy( self.performAjax, self ), 300 ); 47 } 48 } 49 ); 50 }; 51 52 SearchBox.prototype.fragments = function () { 53 return 'total' + ( ! STMListings.SearchBox.listing ? ',options' : '') + ( $( STMListings.SearchBox.form ).hasClass( 'stm-review-search-form' ) ? ',listings' : '' ); 54 }; 55 56 SearchBox.prototype.performAjax = function () { 57 let $_form = $( STMListings.SearchBox.form ), 58 noCascad = $_form.find( '.no-cascading' ), 59 stmUrl = $_form.attr( 'action' ); 60 61 //start if enable UserFriendlyURLs 62 if ( stm_theme_config.enable_friendly_urls.length > 0 ) { 63 var formPath = ''; 64 65 $_form.serializeArray().forEach( 66 function (val) { 67 let slug = val.name.replace( 'min_', '' ).replace( 'max_', '' ); 68 if ( ! stm_cats_conf[slug] && val.value !== '' && val.name !== 'posttype') { 69 formPath += val.value + '/'; 70 } 71 } 72 ); 73 74 $_form.serializeArray().forEach( 75 function (val) { 76 let slug = val.name.replace( 'min_', '' ).replace( 'max_', '' ); 77 if ( $_form.parents('.multilisting-search-tabs-wrap').length ) { 78 if ( stm_cats_conf[slug] && val.value !== '') { 79 formPath += formPath.indexOf( '?' ) < 0 ? '?' : '&'; 80 formPath += val.name + '=' + val.value; 81 } 82 } else { 83 if ( ( stm_cats_conf[slug] || val.name === 'posttype' ) && val.value !== '') { 84 formPath += formPath.indexOf( '?' ) < 0 ? '?' : '&'; 85 formPath += val.name + '=' + val.value; 86 } 87 } 88 } 89 ); 90 91 if ( ! $_form.hasClass( 'stm-review-search-form' ) ) { 92 $_form.attr( 'data-action', stmUrl + formPath ); 93 } 94 } 95 //end if enable UserFriendlyURLs 96 97 var fragments = ( ! $_form.closest( '.stm-vc-ajax-filter' ).hasClass( 'filter' )) ? '&fragments=' + STMListings.SearchBox.prototype.fragments() : ''; 98 99 noCascad.val( noCascad.attr( 'data-val' ) ); 100 101 $.ajax( 102 { 103 url: $_form.attr( 'action' ), 104 dataType: 'json', 105 context: this, 106 data: $_form.serialize() + '&ajax_action=listings-binding' + fragments + '&hide_empty=true&security=' + stm_security_nonce, 107 beforeSend: $.proxy( this.beforeAjax, STMListings.SearchBox.prototype ), 108 success: $.proxy( this.success, STMListings.SearchBox.prototype ), 109 complete: $.proxy( this.complete, STMListings.SearchBox.prototype ) 110 } 111 ); 112 113 //start if enable UserFriendlyURLs 114 if ( stm_theme_config.enable_friendly_urls.length > 0 && $_form[0].hasAttribute( 'data-action' ) && $_form.data( 'action' ) !== '' ) { 115 $_form.on( 116 'submit', 117 function (e) { 118 e.preventDefault(); 119 window.location = $_form.attr( 'data-action' ); 120 } 121 ); 122 } 123 //end if enable UserFriendlyURLs 124 }; 125 126 SearchBox.prototype.beforeAjax = function () { 127 let $body = $( 'body' ), 128 $_form = STMListings.SearchBox.form, 129 s_arrow = $( '.select2-container--default .select2-selection--single .select2-selection__arrow b', $_form ); 130 131 if ( ! STMListings.SearchBox.listing || $( $_form ).closest( '.stm-vc-ajax-filter' ).hasClass( 'filter' )) { 132 $( 'select, button[type="submit"]', $_form ).prop( "disabled", true ); 133 s_arrow.addClass( 'stm-preloader' ); 134 } 135 136 if ( $body.hasClass( 'stm-template-aircrafts' ) ) { 137 s_arrow.addClass( 'stm-preloader' ); 138 } 139 }; 140 141 SearchBox.prototype.success = function (data) { 142 let $body = $( 'body' ), 143 $_form = STMListings.SearchBox.form; 144 145 if ( ! STMListings.SearchBox.listing || $( $_form ).closest( '.stm-vc-ajax-filter' ).hasClass( 'filter' )) { 146 /* Disable options */ 147 if ( typeof data.options != 'undefined' ) { 148 $.each( 149 data.options, 150 function (key, options) { 151 $( 'select[name=' + key + '] > option', $_form ).each( 152 function () { 153 var slug = $( this ).val(); 154 if (options.hasOwnProperty( slug )) { 155 $( this ).prop( 'disabled', options[slug].disabled ); 156 } 157 } 158 ); 159 } 160 ); 161 } 162 163 $( 'select:not(.hide)', $_form ).select2( "destroy" ).select2(); 164
165 if ( $body.hasClass( 'stm-template-motorcycle' ) ) { 166 $( '.stm_mc-found .number-found', $_form ).text( data.total ); 167 } 168 } else if ( $body.hasClass( 'stm-template-aircrafts' ) ) { 169 $( '.select2-container--default .select2-selection--single .select2-selection__arrow b', $_form ).removeClass( 'stm-preloader' ); 170 } 171 172 var total_result = data.total; 173 174 if ( typeof data.listings !== 'undefined' && data.listings.length && typeof listings_with_reviews !== 'undefined' ) { 175 var listings_with_reviews_parsed = JSON.parse( listings_with_reviews ); 176 if ( listings_with_reviews_parsed ) { 177 var matched = listings_with_reviews_parsed.filter( 178 function (n) { 179 return data.listings.indexOf( n ) !== -1; 180 } 181 ); 182 total_result = matched.length; 183 } 184 } 185 186 $( 'button[type="submit"] span', $_form ).text( total_result ); 187 }; 188 189 SearchBox.prototype.complete = function () { 190 let $_form = STMListings.SearchBox.form; 191 192 if ( ! STMListings.SearchBox.listing || $( $_form ).closest( '.stm-vc-ajax-filter' ).hasClass( 'filter' )) { 193 $( '.select2-container--default .select2-selection--single .select2-selection__arrow b', $_form ).removeClass( 'stm-preloader' ); 194 $( 'select, button[type="submit"]', $_form ).prop( "disabled", false ); 195 } 196 }; 197 198 STMListings.SearchBox = SearchBox; 199 200 $.cookie.raw = true; 201 202 var Compare = STMListings.Compare = function () { 203 this.init(); 204 this.setCount(); 205 this.activateLinks(); 206 this.bind(); 207 }; 208 209 Compare.prototype.init = function () { 210 // used in Remove All popup button 211 var removal_post_type = ''; 212 213 var ids = {}; 214 if ( typeof compare_init_object !== 'undefined' ) { 215 this.ids = compare_init_object; 216 } 217 }; 218 219 Compare.prototype.setCount = function () { 220 let total_count = 0; 221 $.each( 222 this.ids, 223 function(key, val){ 224 total_count += val.length; 225 } 226 ); 227 228 $( '[data-contains=compare-count]' ).text( total_count ); 229 230 if ($( '.stm-current-cars-in-compare' ).length > 0) { 231 $( '.stm-current-cars-in-compare' ).html( total_count ); 232 } 233 }; 234 235 Compare.prototype.manageCookieAjax = function (e) { 236 console.log( 'CompareCookieAjax' ); 237 e.preventDefault(); 238 var target = $( e.target ).closest( '[data-id]' ); 239 var dataId = target.attr( 'data-id' ); 240 var dataAction = target.attr( 'data-action' ); 241 var post_type = target.attr( 'data-post-type' ); 242 var _compare_this = this; 243 244 if (typeof dataAction === 'undefined') { 245 dataAction = 'add'; 246 } 247 248 if (typeof dataId === 'undefined' || typeof post_type === 'undefined') { 249 return; 250 } 251 252 let single_compare = $( '.single-add-to-compare' ); 253 254 $.ajax( 255 { 256 url: ajaxurl, 257 type: "POST", 258 dataType: 'json', 259 data: '&post_id=' + dataId + '&post_action=' + dataAction + '&action=stm_ajax_add_to_compare&security=' + stm_security_nonce, 260 context: this, 261 beforeSend: () => { 262 target.addClass( 'disabled' );
263 single_compare.removeClass( [ 'success', 'danger', 'warning' ] ); 264 }, 265 success: function (data) { 266 single_compare.addClass( 'single-add-to-compare-visible' ); 267 268 if (typeof data.response != 'undefined') { 269 $( '.stm-title', single_compare ).text( data.response ); 270 } 271 272 if (typeof data.status != 'undefined') { 273 single_compare.addClass( data.status ); 274 } 275 276 if (typeof data.length != 'undefined') { 277 $( '.stm-current-cars-in-compare' ).text( data.length ); 278 } 279 280 setTimeout( 281 function () { 282 single_compare.removeClass( 'single-add-to-compare-visible' ); 283 }, 284 5000 285 ); 286 287 if (data.status === 'danger') { 288 return; 289 } 290 291 if (dataAction == 'add') { 292 _compare_this.ids[post_type].push( dataId ); 293 } else if (dataAction == 'remove') { 294 var index = _compare_this.ids[post_type].indexOf( dataId ); 295 _compare_this.ids[post_type].splice( index, 1 ); 296 } 297 298 if (!target.hasClass('single-listing-action')) { 299 target.hide().siblings('[data-id]').show(); 300 } else { 301 if (dataAction == 'add') { 302 target 303 .show() 304 .addClass('stm-added active') 305 .attr('title', stm_i18n.remove_from_compare) 306 .attr('data-action', 'remove') 307 .html('<i class="motors-icons-scales-ico"></i> ' + stm_i18n.remove_from_compare); 308 } else { 309 console.log( 'remove' ); 310 target 311 .removeClass('stm-added active') 312 .attr('data-action', 'add') 313 .html('<i class="motors-icons-scales-ico"></i> ' + stm_i18n.add_to_compare); 314 } 315 } 316 317 318 if (target.hasClass( 'stm_remove_after' )) { 319 window.location.reload(); 320 } 321 }, 322 complete: function () { 323 target.removeClass( 'disabled' ); 324 _compare_this.setCount(); 325 } 326 } 327 ); 328 }; 329 330 Compare.prototype.manageCookieLocal = function (e) { 331 console.log( 'CompareCookieLocal' ); 332 e.preventDefault(); 333 var $el = $( e.currentTarget ); 334 var id = $el.data( 'id' ).toString(); 335 var stm_car_title = $el.data( 'title' ); 336 var post_type = $el.data( 'post-type' ); 337 338 if ( typeof post_type == 'undefined' ) { 339 return; 340 } 341 342 let single_compare = $( '.single-add-to-compare' ); 343 344 if ( this.ids[post_type].indexOf( id ) === -1 ) { 345 if (this.ids[post_type].length < 3) { 346 $.cookie( cc_prefix + post_type + '[' + id + ']', id, {expires: 7, path: '/'} ); 347 this.ids[post_type].push( id ); 348 $el.addClass( 'active' ); 349 $( '.stm-listing-compare, .compare' ).attr( 'data-original-title', stm_i18n.remove_from_compare ); 350 $( '.stm-listing-compare, .compare' ).tooltip( 'hide' ); 351 352 // Added popup 353 $( '.single-add-to-compare .stm-title' ).text( stm_car_title + ' - ' + stm_added_to_compare_text ); 354 $( '.single-add-to-compare' ).addClass( 'single-add-to-compare-visible' ); 355 setTimeout( 356 function () { 357 $( '.single-add-to-compare' ).removeClass( 'single-add-to-compare-visible' ); 358 }, 359 5000 360 ); 361 // Added popup 362 } else { 363 // Already added 3 popup 364 $( '.single-add-to-compare .stm-title' ).text( stm_already_added_to_compare_text ); 365 $( '.single-add-to-compare' ).addClass( 'single-add-to-compare-visible' ); 366 setTimeout( 367 function () { 368 $( '.single-add-to-compare' ).removeClass( 'single-add-to-compare-visible' ); 369 $( '.single-add-to-compare' ).removeClass( 'overadded' ); 370 $( '.compare-remove-all' ).remove(); 371 }, 372 5000 373 ); 374 // Already added 3 popup 375 $( '.single-add-to-compare' ).addClass( 'overadded' ); 376 $( '.compare-remove-all' ).remove(); 377 $( '.single-add-to-compare .compare-fixed-link' ).before( '<a href="#" style="margin-left: 15px;" class="compare-fixed-link compare-remove-all pull-right heading-font">' + resetAllTxt + '</a>' ); 378 this.removal_post_type = post_type; 379 } 380 } else { 381 $.removeCookie( cc_prefix + post_type + '[' + id + ']', {path: '/'} ); 382 $( '.stm-listing-compare, .compare' ).attr( 'data-original-title', stm_i18n.add_to_compare ); 383 $( '.stm-listing-compare, .compare' ).tooltip( 'hide' ); 384 this.ids[post_type].splice( this.ids[post_type].indexOf( id ), 1 ); 385 $el.removeClass( 'active' ); 386 387 //Deleted from compare text 388 $( '.stm-title', single_compare ).text( stm_car_title + ' ' + stm_removed_from_compare_text ); 389 single_compare.addClass( 'single-add-to-compare-visible' ); 390 setTimeout( 391 function () { 392 single_compare.removeClass( 'single-add-to-compare-visible' ); 393 }, 394 5000 395 ); 396 //Deleted from compare text 397 398 $( '.single-add-to-compare' ).removeClass( 'overadded' ); 399 $( '.compare-remove-all' ).remove(); 400 } 401 this.setCount(); 402 }; 403 404 Compare.prototype.remove = function (e) { 405 e.preventDefault(); 406 var $el = $( e.currentTarget ); 407 var dataId = $el.attr( 'data-id' ); 408 var dataAction = $el.attr( 'data-action' );
409 var post_type = $el.attr( 'data-post-type' ); 410 var _compare_this = this; 411 412 if (typeof dataId === 'undefined' || typeof post_type === 'undefined') { 413 return; 414 } 415 416 $.ajax( 417 { 418 url: ajaxurl, 419 type: "POST", 420 dataType: 'json', 421 data: '&post_id=' + dataId + '&post_action=' + dataAction + '&action=stm_ajax_add_to_compare&security=' + stm_security_nonce, 422 context: this, 423 beforeSend: function (data) { 424 $el.addClass( 'loading' ); 425 426 if (parseFloat( $( '.stm-current-cars-in-compare' ).text() ) > 0) { 427 $( '.stm-current-cars-in-compare' ).text( parseFloat( $( '.stm-current-cars-in-compare:first' ).text() ) - 1 ); 428 } 429 430 $( '.car-listing-row .compare-col-stm-' + dataId ).hide( 431 'slide', 432 {direction: 'left'}, 433 function () { 434 $( '.car-listing-row .compare-col-stm-' + dataId ).remove(); 435 $( '.car-listing-row' ).append( $( '.compare-empty-car-top' ).html() ); 436 } 437 ); 438 439 $( '.stm-compare-row .compare-col-stm-' + dataId ).hide( 440 'slide', 441 {direction: 'left'}, 442 function () { 443 $( '.stm-compare-row .compare-col-stm-' + dataId ).remove(); 444 $( '.stm-compare-row' ).append( $( '.compare-empty-car-bottom' ).html() ); 445 } 446 ); 447 448 $( '.row-compare-features .compare-col-stm-' + dataId ).hide( 449 'slide', 450 {direction: 'left'}, 451 function () { 452 $( '.row-compare-features .compare-col-stm-' + dataId ).remove(); 453 if ($( '.row-compare-features .col-md-3' ).length < 2) { 454 $( '.row-compare-features' ).slideUp(); 455 } 456 } 457 ); 458 459 $( '.add-compare-mobile' ).addClass( 'add-compare-mobile-show' ); 460 461 // multilisting buttons decrease counter 462 if ( $( '.multilisting_compare_type_buttons .btn-primary' ).length > 0 ) { 463 var current_count = $( '.multilisting_compare_type_buttons .btn-primary span.badge' ).html(); 464 if ( typeof current_count !== undefined && parseInt( current_count ) > 0 ) { 465 var result = parseInt( current_count ) - 1; 466 $( '.multilisting_compare_type_buttons .btn-primary span.badge' ).html( result ); 467 } 468 } 469 }, 470 success: function (data) { 471 if (dataAction == 'add') { 472 _compare_this.ids[post_type].push( dataId ); 473 } else if (dataAction == 'remove') { 474 var index = _compare_this.ids[post_type].indexOf( dataId ); 475 _compare_this.ids[post_type].splice( index, 1 ); 476 } 477 }, 478 complete: function () { 479 _compare_this.setCount(); 480 } 481 } 482 ); 483 }; 484 485 Compare.prototype.removeAll = function (e) { 486 e.preventDefault(); 487 488 var post_type = this.removal_post_type; 489 490 if ( typeof post_type !== 'undefined' && post_type.length > 0 ) { 491 $.each( 492 this.ids[post_type], 493 function (i, id) { 494 $.removeCookie( cc_prefix + post_type + '[' + id + ']', {path: '/'} ); 495 } 496 ); 497 498 this.ids[post_type] = []; 499 this.activateLinks(); 500 this.setCount(); 501 location.reload(); 502 } 503 }; 504 505 Compare.prototype.activateLinks = function (ctx) { 506 $.each( 507 this.ids, 508 function (post_type, value) { 509 510 if (value.length == 0) { 511 return; 512 } 513 514 $.each( 515 value, 516 function(index, post_id){ 517 $( '[data-compare-id=' + post_id + ']', ctx ).each( 518 function () { 519 $( 'a', this ).eq( 0 ).show(); 520 $( 'a', this ).eq( 1 ).hide(); 521 } 522 ); 523 524 var data_placement = $( this ).data( 'placement' ); 525 if (typeof data_placement === undefined) { 526 var data_placement = 'auto'; 527 } 528 529 $( '.stm-compare-directory-new, .stm-listing-compare, .stm-gallery-action-unit.compare', ctx ) 530 .filter( '[data-id=' + post_id + ']' ) 531 .addClass( 'active' ) 532 .tooltip( 'destroy' ) 533 .attr( 'title', stm_i18n.remove_from_compare ) 534 .tooltip( {placement: data_placement} ); 535 } 536 ); 537 } 538 ); 539 }; 540 541 Compare.prototype.bind = function () { 542 $( document ).on( 'click', '.add-to-compare, .mvl-skins-add-to-compare', $.proxy( this.manageCookieAjax, this ) ); 543 $( document ).on( 'click', '.ev_add_compare_link, .stm-user-public-listing .stm-listing-compare, .image .stm-listing-compare, .listing-list-loop.stm-listing-directory-list-loop .stm-listing-compare, .stm-gallery-action-unit.compare, .stm-compare-directory-new', $.proxy( this.manageCookieLocal, this ) ); 544 $( document ).on( 'click', '.remove-from-compare', $.proxy( this.remove, this ) ); 545 $( document ).on( 'click', '.compare-remove-all', $.proxy( this.removeAll, this ) ); 546 }; 547 548 var Favorites = STMListings.Favorites = function () { 549 $( 'body.logged-in' ).on( 'click', '.stm-listing-favorite, .stm-listing-favorite-action', this.clickUser ); 550 $( 'body.stm-user-not-logged-in' ).on( 'click', '.stm-listing-favorite, .stm-listing-favorite-action', this.clickGuest ); 551 552 this.ids = $.cookie( 'stm_car_favourites' ); 553 554 if (this.ids) { 555 this.ids = this.ids.split( ',' ); 556 } else { 557 this.ids = []; 558 } 559 560 var _this = this; 561 if ($( 'body' ).hasClass( 'logged-in' )) { 562 $.getJSON( 563 ajaxurl, 564 {action: 'stm_ajax_get_favourites', security: stm_security_nonce}, 565 function (data) { 566 _this.ids = data; 567 _this.activateLinks(); 568 } 569 ); 570 } else { 571 this.activateLinks(); 572 } 573 }; 574 575 Favorites.prototype.clickUser = function (e) { 576 e.preventDefault(); 577 578 if ($(this).hasClass('disabled')) { 579 return false;
580 } 581 582 var $button = $( this ); 583 $button.tooltip( 'hide' ); 584 585 $button.toggleClass( 'active' ); 586 var stm_car_add_to = $button.data( 'id' ); 587 588 $.ajax( 589 { 590 url: ajaxurl, 591 type: "POST", 592 dataType: 'json', 593 data: '&car_id=' + stm_car_add_to + '&action=stm_ajax_add_to_favourites&security=' + stm_security_nonce, 594 context: this, 595 beforeSend: function (data) { 596 $button.addClass( 'disabled' ); 597 }, 598 success: function (data) { 599 if (data.count) { 600 $( '.stm-my-favourites span' ).text( data.count ); 601 } 602 $button.removeClass( 'disabled' ); 603 updateTooltip( $button ); 604 } 605 } 606 ); 607 }; 608 609 Favorites.prototype.clickGuest = function (e) { 610 e.preventDefault(); 611 612 var $button = $( this ); 613 614 $button.toggleClass( 'active' ); 615 616 $button.tooltip( 'hide' ); 617 618 var stm_cookies = $.cookie(); 619 var stm_car_add_to = $button.data( 'id' ); 620 var stm_car_favourites = []; 621 622 if (typeof (stm_cookies['stm_car_favourites']) !== 'undefined') { 623 stm_car_favourites = stm_cookies['stm_car_favourites'].split( ',' ); 624 var index = stm_car_favourites.indexOf( stm_car_add_to.toString() ); 625 if (index !== -1) { 626 stm_car_favourites.splice( index, 1 ); 627 } else { 628 stm_car_favourites.push( stm_car_add_to.toString() ); 629 } 630 631 stm_car_favourites = stm_car_favourites.join( ',' ); 632 $.cookie( 'stm_car_favourites', stm_car_favourites, {expires: 7, path: '/'} ); 633 634 } else { 635 $.cookie( 'stm_car_favourites', stm_car_add_to.toString(), {expires: 7, path: '/'} ); 636 } 637 638 updateTooltip( $button ); 639 }; 640 641 function updateTooltip($button) { 642 if ($button.hasClass( 'active' )) { 643 $button.attr( 'data-original-title', stm_i18n.remove_from_favorites ); 644 } else { 645 $button.attr( 'data-original-title', stm_i18n.add_to_favorites ); 646 } 647 } 648 649 Favorites.prototype.activateLinks = function (ctx) { 650 $.each( 651 this.ids, 652 function (key, value) { 653 if ( ! value) { 654 return; 655 } 656 657 $( '.stm-listing-favorite, .stm-listing-favorite-action', ctx ) 658 .filter( '[data-id=' + value + ']' ) 659 .addClass( 'active' ) 660 .tooltip( 'hide' ) 661 .attr( 'title', stm_i18n.remove_from_favorites ) 662 .tooltip( {placement: 'auto'} ); 663 664 $( '.stm-listing-favorite.active' ) 665 .tooltip( 'destroy' ) 666 .tooltip(); 667 668 $( '.stm-user-private-main' ).find( '.stm-listing-favorite.active' ) 669 .tooltip( 'destroy' ) 670 .tooltip() 671 .tooltip( {placement: 'auto'} ); 672 } 673 ); 674 }; 675 676 var stm_single_filter_link = false; 677 var stmIsotope; 678 var $container = $( '.stm-isotope-sorting' ); 679 680 $( document ).ready( 681 function () { 682 let $body = $( 'body' ); 683 684 /*Terms and conditions rental*/ 685 $( document ).on( 686 "click", 687 '.stm-template-car_rental .form-row.terms a', 688 function (event) { 689 event.preventDefault(); 690 691 } 692 ); 693 694 /*SHOW NOTIFICATION POPUP IF CAR NOT IN STOCK IN SELECTED OFFICE (STEP 1 RESERVATION)*/ 695 if ( $body.hasClass( 'stm-template-rental-daypicker-page' ) ) { 696 $( 'select[name="pickup_location"]' ).on( 697 'change', 698 function () { 699 var locationId = $( this ).select2( "val" ); 700 701 $.ajax( 702 { 703 url: ajaxurl, 704 type: "GET", 705 dataType: 'json', 706 context: this, 707 data: 'rental_office_id=' + locationId + '&action=stm_ajax_rental_check_car_in_current_office&security=' + stm_security_nonce, 708 success: function (data) { 709 $( "#select-vehicle-popup" ).attr( "href", $( "#select-vehicle-popup" ).attr( 'href' ).split( "?" )[0] + "?pickup_location=" + locationId ); 710 if (data == 'EMPTY') { 711 $( '.choose-another-class' ).addClass( 'single-add-to-compare-visible' ); 712 setTimeout( 713 function () { 714 $( '.choose-another-class' ).removeClass( 'single-add-to-compare-visible' ); 715 }, 716 5000 717 ); 718 } 719 } 720 } 721 ); 722 } 723 ); 724 725 } 726 727 stm_ajax_filter_remove_hidden(); 728 stm_ajax_add_test_drive(); 729 stm_ajax_add_trade_offer(); 730 clearFilter(); 731 clearMagazineFilter(); 732 stm_filter_links(); 733 734 stm_favourites(); 735 736 loadMoreDealerReviews(); 737 738 //Isotope 739 stm_sort_listing_cars(); 740 stm_modern_filter_isotope(); 741 742 //Clear select value from listing badge 743 $body.on( 744 'click', 745 '#modern-filter-listing .stm-clear-listing-one-unit', 746 function () { 747 let selectToClear = $( this ).data( 'select' ); 748 749 if ( typeof selectToClear !== "undefined" ) { 750 let $priceRange = $( '#stm-' + selectToClear + '-range' ); 751 752 if ( selectToClear !== 'price' && $( 'select[name=' + selectToClear + ']' ).length > 0 ) { 753 $( 'select[name=' + selectToClear + ']' ).val( '' ).trigger( 'change' ); 754 755 if ($priceRange.length > 0) { 756 $priceRange.slider( 'values', [stmOptionsObj.min, stmOptionsObj.max] ); 757 $( "#stm_filter_min_" + selectToClear ).val( stmOptionsObj.min ); 758 $( "#stm_filter_max_" + selectToClear ).val( stmOptionsObj.max ); 759 } 760 761 } else { 762 if ($priceRange.length > 0) { 763 $priceRange.slider( 'values', [stmOptions.min, stmOptions.max] ); 764 $( "#stm_filter_min_" + selectToClear ).val( stmOptions.min ); 765 $( "#stm_filter_max_" + selectToClear ).val( stmOptions.max ); 766 } 767 } 768 } 769 770 } 771 ); 772 773 $body.on( 774 'click', 775 '.stm-clear-listing-one-unit-classic', 776 function () { 777 var selectToClear = $( this ).data( 'select' ); // ! data-select not defined in badges.php 778 var clearLinkArg = $( this ).data( 'url' ); 779 780 if (typeof selectToClear != 'undefined') { 781 if (selectToClear.indexOf( '[' )) { 782 window.location = clearLinkArg; 783 return false;
784 } 785 if (selectToClear != 'price' && $( 'select[name=' + selectToClear + ']' ).length > 0) { 786 window.location = clearLinkArg; 787 } else { 788 var $priceRange = $( '#stm-price-range' ); 789 if ($priceRange.length > 0) { 790 $priceRange.slider( 'values', [stmOptions.min, stmOptions.max] ); 791 $( "#stm_filter_min_price" ).val( stmOptions.min ); 792 $( "#stm_filter_max_price" ).val( stmOptions.max ); 793 $( '.classic-filter-row form' ).trigger( 'submit' ); 794 } 795 } 796 } 797 } 798 ); 799 800 $body.on( 801 'click', 802 '#lmb-car-review', 803 function (e) { 804 e.preventDefault(); 805 stm_load_cars_with_review(); 806 } 807 ); 808 } 809 ); 810 811 function stm_ajax_filter_remove_hidden() { 812 let $filter = $( '.filter-listing.stm-vc-ajax-filter, .filter.stm-vc-ajax-filter, .multilisting-search-tabs-wrap' ), 813 $form = $( 'form', $filter ); 814 815 $form.each( 816 function () { 817 new SearchBox( this ); 818 } 819 ); 820 } 821 822 function stm_favourites() { 823 window.stm_compare = new Compare(); 824 } 825 826 function stm_ajax_add_test_drive() { 827 $( '#test-drive form' ).on( 828 "submit", 829 function (event) { 830 event.preventDefault(); 831 $.ajax( 832 { 833 url: ajaxurl, 834 type: "POST", 835 dataType: 'json', 836 context: this, 837 data: $( this ).serialize() + '&action=stm_ajax_add_test_drive&security=' + stm_security_nonce, 838 beforeSend: function () { 839 $( '.alert-modal' ).remove(); 840 $( this ).closest( 'form' ).find( 'input' ).removeClass( 'form-error' ); 841 $( this ).closest( 'form' ).find( '.stm-ajax-loader' ).addClass( 'loading' ); 842 }, 843 success: function (data) { 844 $( this ).closest( 'form' ).find( '.stm-ajax-loader' ).removeClass( 'loading' ); 845 $( this ).closest('form').find('.modal-body').addClass('sended'); 846 $( this ).closest( 'form' ).find( '.modal-body-message' ).append( '<div class="alert-modal alert alert-' + data.status + ' text-left">' + data.response + '</div>' ) 847 for (var key in data.errors) { 848 $( '#request-test-drive-form input[name="' + key + '"]' ).addClass( 'form-error' ); 849 } 850 if (data.status === 'success') { 851 $( this ).closest( 'form' ).find( '.modal-body-fields' ).addClass( 'hidden' ); 852 $( this ).closest( 'form' ).find( 'input' ).val( '' ); 853 } 854 } 855 } 856 ); 857 $( this ).closest( 'form' ).find( '.form-error' ).on( 858 'hover', 859 function () { 860 $( this ).removeClass( 'form-error' ); 861 } 862 ); 863 } 864 ); 865 } 866 867 function stm_ajax_add_trade_offer() { 868 $( '#trade-offer form' ).on( 869 "submit", 870 function (event) { 871 event.preventDefault(); 872 $.ajax( 873 { 874 url: ajaxurl, 875 type: "POST", 876 dataType: 'json', 877 context: this, 878 data: $( this ).serialize() + '&action=stm_ajax_add_trade_offer&security=' + stm_security_nonce, 879 beforeSend: function () { 880 $( '.alert-modal' ).remove(); 881 $( this ).closest( 'form' ).find( 'input' ).removeClass( 'form-error' ); 882 $( this ).closest( 'form' ).find( '.stm-ajax-loader' ).addClass( 'loading' ); 883 }, 884 success: function (data) { 885 $( this ).closest( 'form' ).find( '.stm-ajax-loader' ).removeClass( 'loading' ); 886 $( this ).closest( 'form' ).find( '.modal-body' ).append( '<div class="alert-modal alert alert-' + data.status + ' text-left">' + data.response + '</div>' ) 887 for (var key in data.errors) { 888 $( '#request-trade-offer-form input[name="' + key + '"]' ).addClass( 'form-error' ); 889 } 890 } 891 } 892 ); 893 $( this ).closest( 'form' ).find( '.form-error' ).on( 894 'hover', 895 function () { 896 $( this ).removeClass( 'form-error' ); 897 } 898 ); 899 } 900 ); 901 } 902 903 function clearFilter() { 904 $( '.reset-all' ).on( 905 'click', 906 function (e) { 907 e.preventDefault(); 908 909 $( this ).closest( '.filter' ).find( 'select' ).trigger( 'reset' ); 910 911 $( this ).closest( '.filter' ).find( 'select' ).find( 'option' ).each( 912 function () { 913 if ($( this ).attr( 'data-disabled' ) == 'disabled') { 914 $( this ).attr( 'disabled', 'disabled' ) 915 } 916 } 917 ) 918 919 if ($( '.filter-price' ).length > 0) { 920 $( '.stm-price-range' ).slider( 'values', [stmOptions.min, stmOptions.max] ); 921 $( "#stm_filter_min_price" ).val( stmOptions.min ); 922 $( "#stm_filter_max_price" ).val( stmOptions.max ); 923 } 924 } 925 ); 926 } 927 928 function clearMagazineFilter() { 929 $( '.c-r-remove-filter' ).on( 930 'click', 931 function(e){ 932 e.preventDefault(); 933 934 $( '.selected-filter' ).text( '' ); 935 $( this ).removeClass( 'active' ); 936 937 $( '#listing-with-review' ).find( 'select' ).trigger( 'reset' ); 938 939 $( '#listing-with-review' ).find( 'select' ).find( 'option' ).each( 940 function(){ 941 if ( $( this ).attr( 'data-disabled' ) == 'disabled') { 942 $( this ).attr( 'disabled','disabled' ) 943 } 944 } 945 ) 946 947 stm_load_cars_with_review( true ); 948 } 949 ); 950 } 951 952 function stm_sort_listing_cars() { 953 // init Isotope 954 if ($( '#modern-filter-listing .stm-isotope-sorting' ).length) { 955 if (typeof imagesLoaded == 'function') { 956 $( '.stm-isotope-sorting' ).imagesLoaded( 957 function () { 958 stmIsotope = $container.isotope( 959 { 960 itemSelector: '.stm-isotope-listing-item', 961 layoutMode: 'fitRows', 962 hiddenStyle: { 963 opacity: 0 964 }, 965 visibleStyle: { 966 opacity: 1 967 }, 968 transitionDuration: '0.5s', 969 getSortData: { 970 price: function (itemElem) { 971 var price = $( itemElem ).data( 'price' ); 972 return parseFloat( price ); 973 }, 974 date: function (itemElem) { 975 var date = $( itemElem ).data( 'date' ); 976 return parseFloat( date ); 977 }, 978 mileage: function (itemElem) { 979 var mileage = $( itemElem ).data( 'mileage' ); 980 return parseFloat( mileage ); 981 } 982 } 983 } 984 ); 985 } 986 ); 987 } 988 $( '#modern-filter-listing .stm-select-sorting select' ).select2().on( 989 'change', 990 function () { 991 stm_isotope_sort_function( $( this ).select2( 'val' ) ); 992 } 993 ) 994 } 995 } 996 997 function generateNumberFilter() { 998 /*Generate number field*/ 999 var dataset = []; 1000 1001 $( '.stm-isotope-listing-item' ).each( 1002 function () { 1003 var $this = $( this ); 1004 1005 var attributes = $this[0].attributes; 1006 1007 for (var prop in attributes) { 1008 if (typeof attributes[prop].nodeName === 'undefined' || attributes[prop].nodeName == 'data-numeric-price') { 1009 continue; 1010 } 1011 1012 var attribute = attributes[prop].nodeName; 1013 1014 if ( ! attribute.includes( '-numeric-' )) { 1015 continue; 1016 } 1017 1018 if ( ! dataset.includes( attribute )) { 1019 dataset.push( attribute ); 1020 } 1021 1022 } 1023 1024 } 1025 ); 1026 1027 dataset.forEach( 1028 function (attribute) { 1029 var attribute_name = attribute.replace( 'data-numeric-', '' ); 1030 var $filter = $( '.stm-accordion-single-unit.' + attribute_name ); 1031 1032 if ( ! $filter.length) { 1033 return true; 1034 } 1035 1036 var $filter_wrapper = $filter.find( '.stm-accordion-content-wrapper' ); 1037 1038 var filter_values = []; 1039 1040 $( '[' + attribute + ']' ).each( 1041 function () { 1042 var $this = $( this ); 1043 1044 var value = $this.attr( attribute ); 1045 1046 if ( ! filter_values.includes( value )) { 1047 filter_values.push( value ); 1048 } 1049 } 1050 ); 1051
1052 filter_values.sort().forEach( 1053 function(value){ 1054 $filter_wrapper.append( 1055 '<div class="stm-single-unit">' + 1056 '<label><input class="numeric-checkbox-js" type="checkbox" name="' + attribute + value + '" data-name="' + value + '">' + value + '</label>' + 1057 '</div>' 1058 ); 1059 } 1060 ); 1061 1062 $( '.numeric-checkbox-js' ).uniform( {} ); 1063 1064 $.uniform.update(); 1065 1066 } 1067 ); 1068 } 1069 1070 function stm_modern_filter_isotope() { 1071 1072 if ($( '#modern-filter-listing' ).length > 0) { 1073 1074 generateNumberFilter(); 1075 1076 $( 'body' ).on( 1077 'click', 1078 '.modern-filter-badges ul li i', 1079 function () { 1080 var tab_reset = $( this ).data( 'select' ); 1081 1082 if (tab_reset == 'price') { 1083 $( '.stm-price-range' ).slider( 'values', [stmOptions.min, stmOptions.max] ); 1084 1085 $( "#stm_filter_min_price" ).val( stmOptions.min ); 1086 $( "#stm_filter_max_price" ).val( stmOptions.max ); 1087 1088 stmIso.isotope( 1089 { 1090 filter: function () { 1091 var itemPrice = $( this ).data( 'price' ); 1092 1093 return parseInt( itemPrice, 10 ) >= stmOptions.min && parseInt( itemPrice, 10 ) <= stmOptions.max; 1094 } 1095 } 1096 ); 1097 1098 /*price_string = '<li><span>Price:</span> ' + stmOptions.min + ' - ' + stmOptions.max; 1099 price_string += '<i class="fas fa-times stm-clear-listing-one-unit" data-select="price"></i></li>';*/ 1100 1101 price_string = ''; 1102 $( this ).closest( 'li' ).remove(); 1103 var badges_length = $( ".stm-filter-chosen-units-list li" ).length; 1104 if (badges_length < 1) { 1105 $( '.stm-filter-chosen-units-list' ).css( {height: 0} ); 1106 } 1107 } else if (typeof stmOptionsObj[tab_reset] !== 'undefined') { 1108 $( '.stm-' + tab_reset + '-range' ).slider( 'values', [stmOptionsObj[tab_reset].min, stmOptionsObj[tab_reset].max] ); 1109 1110 $( "#stm_filter_min_" + tab_reset ).val( stmOptionsObj[tab_reset].min ); 1111 $( "#stm_filter_max_" + tab_reset ).val( stmOptionsObj[tab_reset].max ); 1112 1113 stmIso.isotope( 1114 { 1115 filter: function () { 1116 var itemPrice = $( this ).data( tab_reset ); 1117 return parseInt( itemPrice, 10 ) >= stmOptionsObj[tab_reset].min && parseInt( itemPrice, 10 ) <= stmOptionsObj[tab_reset].max; 1118 } 1119 } 1120 ); 1121 1122 dynamic_string[tab_reset] = ''; 1123 $( this ).closest( 'li' ).remove(); 1124 var badges_length = $( ".stm-filter-chosen-units-list li" ).length; 1125 if (badges_length < 1) { 1126 $( '.stm-filter-chosen-units-list' ).css( {height: 0} ); 1127 } 1128 } else { 1129 $( '#' + tab_reset + ' input[type=checkbox]' ).each( 1130 function () { 1131 if ($( this ).prop( 'checked' )) { 1132 $( this ).trigger( 'click' ); 1133 } 1134 } 1135 ) 1136 } 1137 1138 /*Number of filtered*/ 1139 if (typeof stmIsotope != 'undefined') { 1140 var stmIsoData = stmIsotope.data( 'isotope' ); 1141 if (typeof stmIsoData != 'undefined') { 1142 if (typeof stmIsoData.filteredItems != 'undefined') { 1143 $( '.stm-modern-filter-found-cars span' ).text( stmIsoData.filteredItems.length ); 1144 } 1145 } 1146 } 1147 } 1148 ); 1149 1150 var stmSortClasses = ''; 1151 var main_string = ''; 1152 var price_string = ''; 1153 var dynamic_string = new Object(); 1154 var dynamic_string_html = ''; 1155 var string = ''; 1156 var stmIso = $( '.stm-isotope-sorting' ); 1157 var stmFilterGroups = {}; 1158 var stmPriceMaxSelected, stmPriceMinSelected = ''; 1159 var stmMilMaxSelected, stmMilMinSelected = ''; 1160 1161 /*Checkbox clicked, filter*/ 1162 $( '#modern-filter-listing input[type=checkbox]' ).on( 1163 'click', 1164 function () { 1165 var badges = {}; 1166 var badges_reset = {}; 1167 stmFilterGroups = {}; 1168 $( window ).trigger( 'scroll' ); 1169 var stmFirst = 0; 1170 stmSortClasses = ''; 1171 var numberOfCats = 0; 1172 1173 $( '#modern-filter-listing input[type=checkbox]' ).each( 1174 function () { 1175 var stmChecked = $( this ).prop( 'checked' ); 1176 var stmCurrentClass = $( this ).attr( 'name' ); 1177 var stmBadgeValue = $( this ).data( 'name' ); 1178 var stmBadgeId = $( this ).closest( '.content' ).attr( 'id' ); 1179 1180 var stmFilterCurrentGroup = $( this ).closest( '.collapse' ).attr( 'id' ); 1181 1182 if (stmChecked) { 1183 var tab = $( this ).closest( '.stm-accordion-single-unit' ).find( '.title h5' ).text(); 1184 if (typeof badges[tab] == 'undefined') { 1185 badges[tab] = []; 1186 } 1187 if (typeof badges_reset[tab] == 'undefined') { 1188 badges_reset[tab] = ''; 1189 } 1190 badges[tab].push( stmBadgeValue ); 1191 badges_reset[tab] = stmBadgeId; 1192 1193 if (stmFirst == 0) { 1194 stmSortClasses += '.' + stmCurrentClass; 1195 } else { 1196 stmSortClasses += '.' + stmCurrentClass; 1197 } 1198 stmFirst++; 1199 1200 if (typeof (stmFilterGroups[stmFilterCurrentGroup]) == 'undefined') { 1201 stmFilterGroups[stmFilterCurrentGroup] = []; 1202 } 1203 stmFilterGroups[stmFilterCurrentGroup].push( stmCurrentClass ); 1204 1205 } 1206 if (stmSortClasses == '') { 1207 stmSortClasses = '.all'; 1208 } 1209 1210 } 1211 ); 1212 1213 if ($( '.stm-isotope-sorting' ).length > 0 && stmSortClasses != '') { 1214 var matches = []; 1215 1216 stmIso.isotope( 1217 { 1218 filter: function () { 1219 matches = []; 1220 var itemPrice = $( this ).data( 'price' ); 1221 var minPrice = $( '#stm_filter_min_price' ).val(); 1222 var maxPrice = $( '#stm_filter_max_price' ).val(); 1223 1224 if (Object.keys( stmFilterGroups ).length > 0) { 1225 for (var key in stmFilterGroups) { 1226 if (stmFilterGroups.hasOwnProperty( key )) { 1227 for (var k = 0; k < stmFilterGroups[key].length; k++) { 1228 var match = false;
1229 if ($( this ).hasClass( stmFilterGroups[key][k] )) { 1230 matches[key] = true; 1231 } 1232 } 1233 } 1234 } 1235 1236 var final_match = false; 1237 1238 if (Object.keys( matches ).length == Object.keys( stmFilterGroups ).length) { 1239 if (Object.keys( matches ).length > 0) { 1240 for (var m_key in matches) { 1241 if (matches.hasOwnProperty( m_key )) { 1242 if (matches[m_key]) { 1243 final_match = true; 1244 } else { 1245 final_match = false; 1246 } 1247 } 1248 } 1249 } else { 1250 final_match = false; 1251 } 1252 } 1253 1254 if (final_match) { 1255 if (typeof minPrice != 'undefined' && typeof maxPrice != 'undefined' && typeof itemPrice != 'undefined') { 1256 return parseInt( itemPrice, 10 ) >= minPrice && parseInt( itemPrice, 10 ) <= maxPrice; 1257 } else { 1258 return ($( this )); 1259 } 1260 } 1261 } else { 1262 return ($( this )); 1263 } 1264 1265 } 1266 } 1267 ) 1268 } 1269 1270 /*create badge*/ 1271 string = ''; 1272 1273 for (var key in badges) { 1274 if (badges.hasOwnProperty( key )) { 1275 if (badges.hasOwnProperty( key )) { 1276 string += '<li><span>' + key + ':</span> ' + badges[key].join( ', ' ); 1277 if (badges_reset.hasOwnProperty( key )) { 1278 string += '<i class="fas fa-times stm-clear-listing-one-unit" data-select="' + badges_reset[key] + '"></i>'; 1279 } 1280 string += '</li>'; 1281 1282 main_string = get_dynamic_badge_html( dynamic_string ) + price_string + string; 1283 $( '.modern-filter-badges ul.stm-filter-chosen-units-list' ).html( main_string ); 1284 } 1285 } 1286 } 1287 1288 if ($.isEmptyObject( badges )) { 1289 main_string = get_dynamic_badge_html( dynamic_string ) + price_string + string; 1290 $( '.modern-filter-badges ul.stm-filter-chosen-units-list' ).html( main_string ); 1291 } 1292 1293 //var badges_length = Object.keys(badges).length; 1294 var badges_length = $( ".stm-filter-chosen-units-list li" ).length; 1295 if (badges_length > 0) { 1296 1297 var badgesWidth = 0; 1298 var badgesMargin = 15; 1299 var badgesRowWidth = $( '.stm-filter-chosen-units-list' ).outerWidth(); 1300 1301 $( '.stm-filter-chosen-units-list li' ).each( 1302 function () { 1303 badgesWidth += $( this ).outerWidth(); 1304 } 1305 ); 1306 1307 // Add margins 1308 badgesWidth += badgesMargin * (badges_length - 1); 1309 1310 var row_number = (badgesWidth / badgesRowWidth) + 1; 1311 1312 $( '.stm-filter-chosen-units-list' ).css( 1313 { 1314 height: (parseInt( row_number ) * 47) + 'px' 1315 } 1316 ); 1317 } else { 1318 $( '.stm-filter-chosen-units-list' ).css( 1319 { 1320 height: 0 1321 } 1322 ); 1323 } 1324 1325 /*Number of filtered*/ 1326 if (typeof stmIsotope != 'undefined') { 1327 var stmIsoData = stmIsotope.data( 'isotope' ); 1328 if (typeof stmIsoData != 'undefined') { 1329 if (typeof stmIsoData.filteredItems != 'undefined') { 1330 $( '.stm-modern-filter-found-cars span' ).text( stmIsoData.filteredItems.length ); 1331 } 1332 } 1333 } 1334 1335 stm_set_query_transients( stmPriceMinSelected, stmPriceMaxSelected ); 1336 } 1337 ); 1338 1339 $( ".stm-price-range" ).on( 1340 'slide', 1341 function (event, ui) { 1342 1343 var minPrice = ui.values[0]; 1344 var maxPrice = ui.values[1]; 1345 stmIso.isotope( 1346 { 1347 filter: function () { 1348 var matches = []; 1349 var itemPrice = $( this ).data( 'price' ); 1350 var itemMil = (typeof ($( this ).data( 'mileage' )) != 'undefined') ? $( this ).data( 'mileage' ) : 0; 1351 1352 if (Object.keys( stmFilterGroups ).length > 0) { 1353 for (var key in stmFilterGroups) { 1354 if (stmFilterGroups.hasOwnProperty( key )) { 1355 for (var k = 0; k < stmFilterGroups[key].length; k++) { 1356 var match = false; 1357 if ($( this ).hasClass( stmFilterGroups[key][k] )) { 1358 matches[key] = true; 1359 } 1360 } 1361 } 1362 } 1363 1364 var final_match = false; 1365 1366 if (Object.keys( matches ).length == Object.keys( stmFilterGroups ).length) { 1367 if (Object.keys( matches ).length > 0) { 1368 for (var m_key in matches) { 1369 if (matches.hasOwnProperty( m_key )) { 1370 if (matches[m_key]) { 1371 final_match = true; 1372 } else { 1373 final_match = false;
1374 } 1375 } 1376 } 1377 } else { 1378 final_match = false; 1379 } 1380 } 1381 1382 if (final_match) { 1383 stmPriceMaxSelected = (typeof (maxPrice) == 'undefined') ? 0 : maxPrice; 1384 stmPriceMinSelected = (typeof (minPrice) == 'undefined') ? 0 : minPrice; 1385 1386 if (stmMilMaxSelected !== '' && stmMilMinSelected !== '') { 1387 return parseInt( itemPrice, 10 ) >= minPrice && parseInt( itemPrice, 10 ) <= maxPrice && parseInt( itemMil, 10 ) >= stmMilMinSelected && parseInt( itemMil, 10 ) <= stmMilMaxSelected; 1388 } else { 1389 return parseInt( itemPrice, 10 ) >= minPrice && parseInt( itemPrice, 10 ) <= maxPrice; 1390 } 1391 } 1392 } else { 1393 stmPriceMaxSelected = (typeof (maxPrice) == 'undefined') ? 0 : maxPrice; 1394 stmPriceMinSelected = (typeof (minPrice) == 'undefined') ? 0 : minPrice; 1395 1396 if (stmMilMaxSelected !== '' && stmMilMinSelected !== '') { 1397 return parseInt( itemPrice, 10 ) >= minPrice && parseInt( itemPrice, 10 ) <= maxPrice && parseInt( itemMil, 10 ) >= stmMilMinSelected && parseInt( itemMil, 10 ) <= stmMilMaxSelected; 1398 } else { 1399 return parseInt( itemPrice, 10 ) >= minPrice && parseInt( itemPrice, 10 ) <= maxPrice; 1400 } 1401 } 1402 } 1403 } 1404 ); 1405 1406 stm_set_query_transients( stmPriceMinSelected, stmPriceMaxSelected ); 1407 1408 /*Number of filtered*/ 1409 if (typeof stmIsotope != 'undefined') { 1410 var stmIsoData = stmIsotope.data( 'isotope' ); 1411 if (typeof stmIsoData != 'undefined') { 1412 if (typeof stmIsoData.filteredItems != 'undefined') { 1413 $( '.stm-modern-filter-found-cars span' ).text( stmIsoData.filteredItems.length ); 1414 } 1415 } 1416 } 1417 1418 price_string = '<li><span>Price:</span> ' + minPrice + ' - ' + maxPrice; 1419 price_string += '<i class="fas fa-times stm-clear-listing-one-unit" data-select="price"></i></li>'; 1420 main_string = get_dynamic_badge_html( dynamic_string ) + price_string + string; 1421 $( '.modern-filter-badges ul.stm-filter-chosen-units-list' ).html( main_string ); 1422 $( '.stm-filter-chosen-units-list' ).height( '47' ); 1423 1424 } 1425 ); 1426 1427 $( ".stm-modern-dynamic-slider" ).each( 1428 function () { 1429 var sliderIdent = $( this ).data( "slider-name" ); 1430 1431 $( ".stm-" + sliderIdent + "-range" ).on( 1432 'slide', 1433 function (event, ui) { 1434 var minMileage = ui.values[0]; 1435 var maxMileage = ui.values[1]; 1436 stmIso.isotope( 1437 { 1438 filter: function () { 1439 var matches = []; 1440 var itemPrice = (typeof ($( this ).data( 'price' )) != 'undefined') ? $( this ).data( 'price' ) : 0; 1441 var itemMileage = $( this ).data( sliderIdent ); 1442 1443 if (Object.keys( stmFilterGroups ).length > 0) { 1444 for (var key in stmFilterGroups) { 1445 if (stmFilterGroups.hasOwnProperty( key )) { 1446 for (var k = 0; k < stmFilterGroups[key].length; k++) { 1447 var match = false; 1448 if ($( this ).hasClass( stmFilterGroups[key][k] )) { 1449 matches[key] = true; 1450 } 1451 } 1452 } 1453 } 1454 1455 var final_match = false; 1456 1457 if (Object.keys( matches ).length == Object.keys( stmFilterGroups ).length) { 1458 if (Object.keys( matches ).length > 0) { 1459 for (var m_key in matches) { 1460 if (matches.hasOwnProperty( m_key )) { 1461 if (matches[m_key]) { 1462 final_match = true; 1463 } else { 1464 final_match = false; 1465 } 1466 } 1467 } 1468 } else { 1469 final_match = false; 1470 } 1471 } 1472 1473 if (final_match) { 1474 stmMilMaxSelected = maxMileage; 1475 stmMilMinSelected = minMileage; 1476 1477 if (stmPriceMaxSelected !== '' && stmPriceMinSelected !== '') { 1478 return parseInt( itemMileage, 10 ) >= minMileage && parseInt( itemMileage, 10 ) <= maxMileage && parseInt( itemPrice, 10 ) >= stmPriceMinSelected && parseInt( itemPrice, 10 ) <= stmPriceMaxSelected; 1479 } else { 1480 return parseInt( itemMileage, 10 ) >= minMileage && parseInt( itemMileage, 10 ) <= maxMileage; 1481 } 1482 } 1483 } else { 1484 stmMilMaxSelected = maxMileage; 1485 stmMilMinSelected = minMileage; 1486
1487 if (stmPriceMaxSelected !== '' && stmPriceMinSelected !== '') { 1488 return parseInt( itemMileage, 10 ) >= minMileage && parseInt( itemMileage, 10 ) <= maxMileage && parseInt( itemPrice, 10 ) >= stmPriceMinSelected && parseInt( itemPrice, 10 ) <= stmPriceMaxSelected; 1489 } else { 1490 return parseInt( itemMileage, 10 ) >= minMileage && parseInt( itemMileage, 10 ) <= maxMileage; 1491 } 1492 } 1493 } 1494 } 1495 ); 1496 1497 /*Number of filtered*/ 1498 if (typeof stmIsotope != 'undefined') { 1499 var stmIsoData = stmIsotope.data( 'isotope' ); 1500 if (typeof stmIsoData != 'undefined') { 1501 if (typeof stmIsoData.filteredItems != 'undefined') { 1502 $( '.stm-modern-filter-found-cars span' ).text( stmIsoData.filteredItems.length ); 1503 } 1504 } 1505 } 1506 1507 dynamic_string_html = '<li><span>' + sliderIdent + ':</span> ' + minMileage + ' - ' + maxMileage; 1508 dynamic_string_html += '<i class="fas fa-times stm-clear-listing-one-unit" data-select="' + sliderIdent + '"></i></li>'; 1509 1510 dynamic_string[sliderIdent] = dynamic_string_html; 1511 1512 main_string = get_dynamic_badge_html( dynamic_string ) + price_string + string; 1513 $( '.modern-filter-badges ul.stm-filter-chosen-units-list' ).html( main_string ); 1514 $( '.stm-filter-chosen-units-list' ).height( '47' ); 1515 } 1516 ); 1517 1518 } 1519 ); 1520 1521 // stm_remove_query_cookies(); 1522 1523 } 1524 // else if($('body.single').length == 0) { 1525 // stm_remove_query_cookies(); 1526 // } 1527 1528 // set query cookie 1529 function stm_set_query_transients(min, max) { 1530 1531 var cookieQueryObj = Object.assign( {}, stmFilterGroups ); 1532 1533 if (typeof min !== 'undefined' && typeof max !== 'undefined') { 1534 cookieQueryObj['min_price'] = [min]; 1535 cookieQueryObj['max_price'] = [max]; 1536 } 1537 1538 // delete query cookie 1539 // $.cookie('stm_search_results_query_' + stm_site_blog_id, null, {expires: -1, path: '/'}); 1540 1541 // set new query cookie 1542 // $.cookie('stm_search_results_query_' + stm_site_blog_id, JSON.stringify(cookieQueryObj), {expires: 7, path: '/'}); 1543 1544 // set cookie to come back to modern inventory page 1545 // $.cookie('stm_modern_inventory_link_' + stm_site_blog_id, window.location.href, {expires: 7, path: '/'}); 1546 1547 $.ajax( 1548 { 1549 type: 'post', 1550 url: ajax_url, 1551 data: { 1552 action: 'stm_set_query_transients', 1553 inventory_query: cookieQueryObj, 1554 inventory_link: window.location.href, 1555 } 1556 } 1557 ); 1558 } 1559 1560 // delete query and related cookies 1561 // function stm_remove_query_cookies() { 1562 // // also delete everywhere except on single listing page 1563 // $.cookie('stm_search_results_query_' + stm_site_blog_id, null, {expires: -1, path: '/'}); 1564 // $.cookie('stm_modern_inventory_link_' + stm_site_blog_id, null, {expires: -1, path: '/'}); 1565 // } 1566 } 1567 1568 function get_dynamic_badge_html(dynamic_string) { 1569 var dynamic_string_html = ''; 1570 $.each( 1571 dynamic_string, 1572 function (key, event) { 1573 dynamic_string_html += event; 1574 } 1575 ); 1576 1577 return dynamic_string_html; 1578 } 1579 1580 function stm_filter_links() { 1581 $( 'body' ).on( 1582 'click', 1583 '.stm-single-filter-link', 1584 function () { 1585 stm_single_filter_link = true; 1586 var stm_name = $( this ).data( 'slug' ); 1587 var stm_value = $( this ).data( 'value' ); 1588 if (typeof stm_name !== 'undefined' && typeof stm_value !== 'undefined') { 1589 $( '.reset-all' ).trigger( 'click' ); 1590 $( '#stm-filter-links-input' ).attr( 'name', stm_name ); 1591 $( '#stm-filter-links-input' ).val( stm_value ); 1592 } 1593 } 1594 ) 1595 } 1596 1597 STMListings.save_user_settings = function () { 1598 $( '#stm_user_settings_edit.stm_save_user_settings_ajax' ).on( 1599 'submit', 1600 function (e) { 1601 1602 var formData = new FormData(); 1603 1604 /*Add image*/ 1605 formData.append( 'stm-avatar', $( 'input[name="stm-avatar"]' )[0].files[0] ); 1606 1607 /*Add text fields*/ 1608 var formInputs = $( this ).serializeArray(); 1609 1610 for (var key in formInputs) { 1611 if (formInputs.hasOwnProperty( key )) { 1612 formData.append( formInputs[key]['name'], formInputs[key]['value'] ); 1613 } 1614 } 1615 1616 formData.append( 'action', 'stm_listings_ajax_save_user_data' ); 1617 formData.append( 'security', stm_listings_user_data_nonce ); 1618 1619 e.preventDefault(); 1620 1621 $.ajax( 1622 { 1623 type: "POST", 1624 url: ajaxurl, 1625 dataType: 'json', 1626 context: this, 1627 data: formData, 1628 contentType: false, 1629 processData: false, 1630 beforeSend: function () { 1631 $( '.stm-user-message' ).empty(); 1632 $( this ).find( '.stm-listing-loader' ).addClass( 'visible' ); 1633 }, 1634 success: STMListings.save_user_settings_success 1635 } 1636 ); 1637 } 1638 ) 1639 }; 1640 1641 STMListings.save_user_settings_success = function (data) { 1642 $( this ).find( '.stm-listing-loader' ).removeClass( 'visible' ); 1643 $( '.stm-user-message' ).text( data.error_msg ); 1644 1645 $( '.stm-image-avatar img, .stm-dropdown-user-small-avatar img' ).attr( 'src', data.new_avatar ); 1646 1647 if (typeof data.new_avatar === 'undefined' || data.new_avatar === '') { 1648 $( '.stm-image-avatar' ).removeClass( 'hide-empty' ).addClass( 'hide-photo' ); 1649 } else { 1650 $( '.stm-image-avatar' ).addClass( 'hide-empty' ).removeClass( 'hide-photo' ); 1651 } 1652 1653 }; 1654 1655 STMListings.stm_logout = function () { 1656 $( 'body' ).on( 1657 'click', 1658 '.stm_logout a', 1659 function (e) { 1660 e.preventDefault(); 1661 $.ajax( 1662 { 1663 url: ajaxurl, 1664 type: "POST", 1665 dataType: 'json', 1666 context: this, 1667 data: { 1668 'action': 'stm_logout_user' 1669 }, 1670 beforeSend: function () { 1671 $( '.stm_add_car_form .stm-form-checking-user .stm-form-inner' ).addClass( 'activated' ); 1672 }, 1673 success: function (data) { 1674 if (data.exit) { 1675 $( '.stm-form-checking-user button[type="submit"]' ).removeClass( 'enabled' ).addClass( 'disabled' ); 1676 window.location.reload(); 1677 } 1678 } 1679 } 1680 ); 1681 } 1682 ) 1683 }; 1684 1685 STMListings.stm_ajax_login = function () { 1686 $( '.lOffer-account-unit' ).on( 1687 'mouseout', 1688 function () { 1689 $( '.stm-login-form-unregistered' ).removeClass( 'working' ); 1690 } 1691 ); 1692 }; 1693 1694 function loadMoreDealerReviews() { 1695 $( 'body' ).on( 1696 'click', 1697 '.stm-load-more-dealer-reviews a', 1698 function (e) { 1699 e.preventDefault(); 1700 1701 if ($( this ).closest( '.stm-load-more-dealer-reviews' ).hasClass( 'not-clickable' )) { 1702 return false;
1703 } 1704 1705 var offset = $( this ).attr( 'data-offset' ); 1706 var user_id = $( this ).data( 'user' ); 1707 1708 $.ajax( 1709 { 1710 url: ajaxurl, 1711 data: { 1712 action: 'stm_ajax_dealer_load_reviews', 1713 offset: offset, 1714 user_id: user_id, 1715 security: stm_security_nonce 1716 }, 1717 method: 'POST', 1718 dataType: 'json', 1719 context: this, 1720 beforeSend: function () { 1721 $( this ).closest( '.stm-load-more-dealer-reviews' ).addClass( 'not-clickable' ); 1722 }, 1723 success: function (data) { 1724 $( this ).closest( '.stm-load-more-dealer-reviews' ).removeClass( 'not-clickable' ); 1725 if (data.html) { 1726 $( this ).closest( '.tab-pane' ).find( '#stm-dealer-reviews-units' ).append( data.html ); 1727 } 1728 if (data.new_offset) { 1729 $( this ).attr( 'data-offset', data.new_offset ); 1730 } 1731 if (data.button == 'hide') { 1732 $( this ).closest( '.stm-load-more-dealer-reviews' ).slideUp(); 1733 } 1734 } 1735 } 1736 ); 1737 } 1738 ) 1739 } 1740 1741 $( '#stm_submit_review .button' ).on( 1742 'click', 1743 function (e) { 1744 e.preventDefault(); 1745 1746 if ( ! $( this ).hasClass( 'disabled' )) { 1747 1748 $.ajax( 1749 { 1750 url: ajaxurl, 1751 dataType: 'json', 1752 context: this, 1753 data: $( this ).closest( 'form' ).serialize() + '&action=stm_submit_review&security=' + stm_security_nonce, 1754 beforeSend: function () { 1755 $( this ).closest( 'form' ).find( '.stm-icon-load1' ).addClass( 'activated' ); 1756 $( '#write-review-message ' ).slideUp(); 1757 }, 1758 success: function (data) { 1759 $( this ).closest( 'form' ).find( '.stm-icon-load1' ).removeClass( 'activated' ); 1760 1761 if (data.message) { 1762 $( '#write-review-message ' ).text( data.message ).slideDown(); 1763 } 1764 1765 if (data.updated) { 1766 if (data.message) { 1767 setTimeout(function () { 1768 window.location.href = data.updated; 1769 location.reload(); 1770 }, 1500); 1771 } else { 1772 window.location.href = data.updated; 1773 location.reload(); 1774 } 1775 } 1776 } 1777 } 1778 ); 1779 } 1780 } 1781 ) 1782 1783 $( '.stm-comment-dealer-wrapper .stm-bottom .stm-report-review a' ).on( 1784 'click', 1785 function (e) { 1786 e.preventDefault(); 1787 1788 if ( ! $( this ).hasClass( 'reported' )) { 1789 var stmID = $( this ).data( 'id' ); 1790 $.ajax( 1791 { 1792 type: "POST", 1793 url: ajaxurl, 1794 dataType: 'json', 1795 context: this, 1796 data: { 1797 'id': stmID, 1798 'action': 'stm_report_review', 1799 'security': stm_security_nonce 1800 }, 1801 beforeSend: function () { 1802 $( this ).addClass( 'reported' ); 1803 }, 1804 success: function (data) { 1805 if (data.message) { 1806 $( this ).text( data.message ); 1807 } 1808 } 1809 } 1810 ); 1811 } 1812 } 1813 ); 1814 1815 $( '.dealer-search-title select' ).on( 1816 'change', 1817 function () { 1818 $( 'input[name="stm_sort_by"]' ).val( $( this ).val() ); 1819 $( "#stm_all_listing_tab" ).find( "form" ).trigger( 'submit' ); 1820 } 1821 ); 1822 1823 $( '#stm_all_listing_tab_without_tabs .reset-filter' ).on( 1824 'click', 1825 function (e) { 1826 e.preventDefault(); 1827 $( this ) 1828 .closest( 'form' ) 1829 .find( 'select' ) 1830 .val( null ) 1831 .trigger( 'change' ); 1832 1833 $( this ) 1834 .closest( 'form' )
1835 .find( 'input' ) 1836 .val( '' ); 1837 1838 return false; 1839 } 1840 ); 1841 1842 $( '.stm-load-more-dealers' ).on( 1843 'click', 1844 function (e) { 1845 e.preventDefault(); 1846 1847 if ($( this ).hasClass( 'not-clickable' )) { 1848 return false; 1849 } 1850 1851 var offset = $( this ).attr( 'data-offset' ); 1852 1853 $.ajax( 1854 { 1855 //url: ajaxurl, 1856 url: stm_motors_current_ajax_url, 1857 dataType: 'json', 1858 context: this, 1859 data: $( '.stm_dynamic_listing_dealer_filter form' ).serialize() + '&offset=' + offset + '&ajax_action=stm_load_dealers_list&security=' + stm_security_nonce, 1860 beforeSend: function () { 1861 $( this ).addClass( 'not-clickable' ); 1862 }, 1863 success: function (data) { 1864 $( this ).removeClass( 'not-clickable' ); 1865 if (data.user_html) { 1866 $( '.dealer-search-results table tbody' ).append( data.user_html ); 1867 } 1868 if (data.new_offset) { 1869 $( '.stm-load-more-dealers' ).attr( 'data-offset', data.new_offset ); 1870 } 1871 if (data.remove && data.remove === 'hide') { 1872 $( this ).remove(); 1873 } 1874 } 1875 } 1876 ); 1877 } 1878 ); 1879 1880 $( '.stm-btn-plan-trial, .stm-btn-plan-pause, .stm-btn-plan-cancel' ).on( 1881 'click', 1882 function() { 1883 var subsId = $( this ).data( 'subsid' ); 1884 var userId = $( this ).data( 'userid' ); 1885 var status = $( this ).data( 'status' ); 1886 var msgblock = $( this ).data( 'msgblock' ); 1887 1888 var btn = $( this ); 1889 1890 btn.addClass( 'btn-load' ); 1891 1892 $.ajax( 1893 { 1894 url: ajaxurl, 1895 type: "POST", 1896 dataType: 'json', 1897 context: this, 1898 data: 'subs_id=' + subsId + '&user_id=' + userId + '&subs_status=' + status + '&action=stm_ajax_subscriptio_change_status&security=' + stm_security_nonce, 1899 success: function (data) { 1900 1901 btn.removeClass( 'btn-load' ); 1902 1903 if (data.status == 'success') { 1904 location.reload(); 1905 } else { 1906 $( '.' + msgblock ).text( data.status ); 1907 } 1908 } 1909 } 1910 ); 1911 } 1912 ); 1913})( jQuery ); 1914 1915function stm_loadMoreCars(that, category, taxonomy, offset, per_page, random_int = null ) { 1916 var $ = jQuery; 1917 $.ajax( 1918 { 1919 url: ajaxurl, 1920 data: { 1921 action: 'stm_ajax_load_more_cars', 1922 category: category, 1923 taxonomy: taxonomy, 1924 offset: offset, 1925 per_page: per_page, 1926 security: stm_security_nonce, 1927 random_int: random_int, 1928 }, 1929 method: 'POST', 1930 dataType: 'json', 1931 beforeSend: function () { 1932 $( that ).addClass( 'not-visible' ); 1933 $( that ).closest( '.dp-in' ).find( '.preloader' ).fadeIn( 600 ); 1934 }, 1935 success: function (data) { 1936 $( that ).closest( '.dp-in' ).find( '.preloader' ).hide(); 1937 if (random_int != null) { 1938 const appendTo = data['appendTo'] + '-' + random_int; 1939 if (data['content'] && data['appendTo']) { 1940 $( appendTo + ' .car-listing-row' ).append( data['content'] ); 1941 } 1942 } 1943 if (data['content'] && data['appendTo']) { 1944 $( data['appendTo'] + ' .car-listing-row' ).append( data['content'] ); 1945 } 1946 if (data['button']) { 1947 $( that ).attr( 'onclick', data['button'] ).removeClass( 'not-visible' ); 1948 } else { 1949 $( data['appendTo'] ).find( '.car-listing-actions' ).addClass( 'all-done' ); 1950 that.parent().text( '' ); 1951 } 1952 } 1953 } 1954 ); 1955} 1956 1957function stm_load_cars_with_review(upd) { 1958 var update = (upd) ? upd : false; 1959 var $ = jQuery; 1960 var $_form = $( '#listing-with-review' ).closest( 'form' ); 1961 var stmUrl = $_form.attr( 'action' ); 1962 1963 $.ajax( 1964 { 1965 url: stmUrl, 1966 dataType: 'json', 1967 context: this, 1968 data: $_form.serialize() + '&ajax_action=listings-binding', 1969 beforeSend: function () { 1970 if (typeof filterApp != 'undefined') { 1971 filterApp.loadListings = true; 1972 } 1973 }, 1974 success: function (data) { 1975 if (typeof data.offset != 'undefined') { 1976 $( 'input[name="offset"]' ).val( data.offset ); 1977 $( '.load-more-btn-wrap' ).show(); 1978 } else { 1979 $( 'input[name="offset"]' ).val( 0 ); 1980 $( '.load-more-btn-wrap' ).hide(); 1981 } 1982 1983 if (typeof data.posts != 'undefined') { 1984 if ( ! update) { 1985 for (var q = 0; q < data.posts.length; q++) { 1986 filterApp.pushNewData( data.posts[q] ); 1987 } 1988 } else { 1989 filterApp.posts = data.posts; 1990 setTimeout( 1991 function () { 1992 filterApp.loadListings = false;
1993 }, 1994 300 1995 ); 1996 } 1997 } 1998 } 1999 } 2000 ); 2001 return false; 2002}
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.