1( function( $ ) { 2 'use strict'; 3 4 function replaceBuildAndPriceLabel() { 5 $( '.motocommerce-build-and-price button' ).each( function() { 6 var $button = $( this ); 7 var label = $button.text(); 8 var updatedLabel = label.replace( 'Build and Price', 'Build & Price' ); 9 10 if ( label !== updatedLabel ) { 11 $button.text( updatedLabel ); 12 } 13 }); 14 } 15 16 function showPricesForAllowedOem() { 17 var oem = ( window.globalVars && globalVars.generalOEM ? globalVars.generalOEM : '' ).toLowerCase(); 18 19 if ( oem.split( ',' ).some( function( make ) { 20 return [ 'toyota', 'honda' ].includes( make.trim() ); 21 }) ) { 22 $( 'body' ).addClass( 'show-oem-prices' ); 23 } 24 } 25 26 function setModelFormContext( $card, target ) { 27 var model = $card.find( '.model-card__title:visible' ).first().text().replace( /\s+/g, ' ' ).trim(); 28 var $modal = $( '#' + target ); 29 30 if ( ! model ) { 31 model = $card.find( '.model-card__title' ).first().text().replace( /\s+/g, ' ' ).trim(); 32 } 33 if ( model && $modal.length ) { 34 $modal.find( 'textarea[name="message"]' ).val( 'I am interested in a personalized offer and would like to confirm availability for this ' + model ).trigger( 'change' ).closest( '.form-label' ).find( '.label-text-textarea' ).addClass( 'floating' ); 35 } 36 } 37 38 function enhanceModelCards() { 39 $( '.model-card' ).each( function() { 40 var $card = $( this ); 41 var $ctas = $card.find( '.model-card__ctas, .model-card-custom__ctas' ).first(); 42 var $button = $card.find( '[convertus-data-id="models__model-card-button"]' ).first(); 43 $button.removeClass( 'button--alternate' ).addClass( 'button--centered' ); 44 45 $card.find( '.model-card__ctas--build-and-price:not(:has(.modal-trigger))' ).each( function() { 46 if ( 'none' !== $( this ).css( 'display' ) ) { 47 $( this ).hide(); 48 } 49 }); 50 if ( ! $ctas.length && $button.length ) { 51 $ctas = $( '<div class="model-card-custom__ctas"></div>' ).insertBefore( $button ).append( $button ); 52 } 53 54 }); 55 } 56 57 function enhanceModelInformation() { 58 $( '.model-information--finances' ).each( function() { 59 var $finances = $( this ); 60 var $modelInformation = $finances.closest( '.model-information' ); 61 62 var $buildAndPrice = $modelInformation.find( '.motocommerce-build-and-price' ).last(); 63 var $viewInventoryTarget = $buildAndPrice.length ? $buildAndPrice : $finances; 64 var $viewInventory = $modelInformation.find( '.model-information__view-inventory' ); 65 var modelPath = window.location.pathname.split( '/' ); 66 var modelIndex = modelPath.indexOf( 'models' ); 67 var yearMatch = window.location.search.match( /[?&]y=([^&]+)/ ); 68 69 if ( $buildAndPrice.length && $viewInventory.length && $buildAndPrice.next()[0] !== $viewInventory[0]) { 70 $viewInventory.insertAfter( $buildAndPrice ); 71 } 72 73 if ( $viewInventoryTarget.length && -1 < modelIndex && ! $viewInventory.length && yearMatch ) { 74 var make = decodeURIComponent( modelPath[ modelIndex + 1 ] || '' ); 75 var model = decodeURIComponent( modelPath[ modelIndex + 2 ] || '' ); 76 var year = decodeURIComponent( yearMatch[1]); 77 var inventoryUrl = '/vehicles/?sc=new&mk=' + encodeURIComponent( make ) + '&md=' + encodeURIComponent( model ) + '&yr=' + year + ',' + year + '&in_transit=true&in_stock=true&on_order=true'; 78 79 $( '<div class="model-information__view-inventory"></div>' ) 80 .append( $( '<a>', { 81 class: 'button button--centered', 82 href: inventoryUrl, 83 'convertus-data-id': 'models__view-inventory', 84 text: 'View Inventory' 85 }) ) 86 .insertAfter( $viewInventoryTarget ); 87 } 88 }); 89 } 90 91 function hideEmptyInventoryWidgets() { 92 $( '.inventory-carousel-widget, .model-inventory-carousel-widget' ).each( function() { 93 var $widget = $( this ); 94 95 if ( $widget.find( '.no-results' ).length ) { 96 $widget.hide(); 97 98 if ( $widget.hasClass( 'model-inventory-carousel-widget' ) ) { 99 $( '.on-page-widgets-navigation-tabs .widget-item' ).filter( function() { 100 return /^(inventory|l'inventaire)$/i.test( $.trim( $( this ).text() ) ); 101 }).each( function() { 102 $( this ).closest( '.tns-item' ).addBack().hide(); 103 }); 104 } 105 } 106 }); 107 } 108 109 $( function() { 110 showPricesForAllowedOem(); 111 $( document ).on( 'click', '.model-card .modal-trigger', function() { 112 var $card = $( this ).closest( '.model-card' ); 113 var target = $( this ).data( 'target' ); 114 setModelFormContext( $card, target ); 115 setTimeout( function() { 116 setModelFormContext( $card, target ); 117 }, 0 ); 118 }); 119 replaceBuildAndPriceLabel(); 120 enhanceModelCards(); 121 enhanceModelInformation(); 122 hideEmptyInventoryWidgets(); 123 124 if ( window.MutationObserver ) { 125 new MutationObserver( function() { 126 replaceBuildAndPriceLabel(); 127 enhanceModelCards(); 128 enhanceModelInformation(); 129 hideEmptyInventoryWidgets(); 130 }).observe( document.body, { childList: true, subtree: true }); 131 } 132 }); 133}( 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.