' + '' + '' ); } let resultPosition = 0; let impressions = []; let template = $('#tmpl-listing').html(); Mustache.parse(template); $.each(response.records, function(row, itemDetails) { var itemOutput = Mustache.render(template, { advertId: itemDetails.advertId, inventoryUUID: itemDetails.inventoryUUID, listingURL: window.location.protocol+"//"+window.location.host+"/"+itemDetails.canonicalURL, listingName: itemDetails.manufacturerName+' '+itemDetails.partSuitsShort+' '+itemDetails.partName, listingManufacturer: itemDetails.manufacturerName, listingPartName: itemDetails.partName, listingPartNumber: itemDetails.partNumber, listingPartSuits: itemDetails.partSuits, listingCondition: itemDetails.inventoryCondition, listingTerm: itemDetails.inventoryTerm, listingCategory: (itemDetails.inventoryCategory !== undefined ? itemDetails.inventoryCategory.toUpperCase() : ''), listingSubcategory: (itemDetails.inventorySubcategory !== undefined ? itemDetails.inventorySubcategory.toUpperCase() : ''), listingPhotoURL: $('#assetPath').val() + itemDetails.photoURL, listingPhotoCount: itemDetails.photoCount }); $('#search-results').append(itemOutput); $('#l-' + itemDetails.inventoryUUID + '-container').on('click', function(){ window.location = window.location.protocol + '//' + window.location.host + '/' + itemDetails.canonicalURL; }); resultPosition++; let impression = { id: itemDetails.partNumber, name: (itemDetails.partName !== undefined ? itemDetails.partName : ''), category: (itemDetails.inventoryCategory!== undefined ? itemDetails.inventoryCategory.toUpperCase() : '') + (itemDetails.inventorySubcategory !== undefined ? ' / ' + itemDetails.inventorySubcategory.toUpperCase() : ''), variant: itemDetails.inventoryTerm + ' - ' + itemDetails.inventoryCondition, brand: itemDetails.manufacturerName, coupon: itemDetails.inventoryCountry, quantity: 1, dimension7: (itemDetails.advertId !== undefined ? itemDetails.advertId : ''), dimension14: itemDetails.photoCount, position: resultPosition, list: 'Search Listings' }; impressions.push(impression); }); $.each(response.records, function(row, itemDetails) { if(localStorage.getItem('b-'+itemDetails.inventoryUUID+'-line') !== null){ $('#l-'+itemDetails.inventoryUUID+'-star') .removeClass('far') .addClass('fas star-selected'); $('#l-'+itemDetails.inventoryUUID+'-action').on('click',function() { removeFromBasket('inventory', itemDetails.inventoryUUID); }); }else{ $('#l-'+itemDetails.inventoryUUID+'-action').on('click',function() { addToBasket('listing', itemDetails.inventoryUUID); }); } if(itemDetails.photoURL !== '') { $('#l-'+itemDetails.inventoryUUID+'-photo').removeClass('d-none'); $('#l-'+itemDetails.inventoryUUID+'-specs').addClass('d-none'); $(document) .on('mouseenter', '#l-'+itemDetails.inventoryUUID+'-photo', function () { $('#l-'+itemDetails.inventoryUUID+'-photo').fadeOut( 'fast', function() { $('#l-' + itemDetails.inventoryUUID + '-specs') .hide() .removeClass('d-none') .fadeIn('fast') } ); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'pageOverlay', virtualPageURL: window.location.protocol + '//' + window.location.host + '/' + itemDetails.canonicalURL, virtualPageTitle: itemDetails.partNumber + ' ' + (itemDetails.partName !== undefined ? itemDetails.partName : '' ), }); }) .on('mouseleave', '#l-'+itemDetails.inventoryUUID+'-specs', function () { $('#l-'+itemDetails.inventoryUUID+'-specs') .fadeOut('fast') .addClass('d-none') .show(); $('#l-'+itemDetails.inventoryUUID+'-photo').fadeIn('fast'); }); } $('.l-'+itemDetails.inventoryUUID+'-link').on('click', function() { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'eec.impressionClick', ecommerce: { click: { actionField: { list: 'Search Listings' }, products: [{ id: itemDetails.partNumber, name: itemDetails.partName, category: (itemDetails.inventoryCategory!== undefined ? itemDetails.inventoryCategory.toUpperCase() : '') + (itemDetails.inventorySubcategory !== undefined ? ' / ' + itemDetails.inventorySubcategory.toUpperCase() : ''), variant: itemDetails.inventoryTerm + ' - ' + itemDetails.inventoryCondition, brand: itemDetails.manufacturerName, coupon: itemDetails.inventoryCountry, quantity: 1, dimension7: itemDetails.advertId, dimension14: itemDetails.photoCount, position: $('#l-'+itemDetails.inventoryUUID).index('.l-card')+1, }] } } }); }); if (itemDetails.inventoryPartName === '') { $('#l-'+itemDetails.inventoryUUID+'-partname-container').addClass('d-none'); } if (itemDetails.inventoryPartNumber === '') { $('#l-'+itemDetails.inventoryUUID+'-partnumber-container').addClass('d-none'); } if (itemDetails.inventoryManufacturer === '') { $('#l-'+itemDetails.inventoryUUID+'-manufacturer-container').addClass('d-none'); } if (itemDetails.inventoryCondition === '') { $('#l-'+itemDetails.inventoryUUID+'-condition-container').addClass('d-none'); } if (itemDetails.partSuits === '') { $('#l-'+itemDetails.inventoryUUID+'-suits-container').addClass('d-none'); } }); if (response.resultsTotal > (response.resultsStart + response.records.length) ) { $('#search-more-results') .off('click') .on('click', function(){ search(searchTerm, (response.resultsStart + response.records.length)); }); $('#search-results-paging').removeClass('d-none'); } else { $('#search-more-results').addClass('d-none'); $('#search-results-paging').addClass('d-none'); if (response.resultsStart > 0) { $('#search-results-completed').removeClass('d-none'); } } $('#search-results-loading').remove(); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'eec.impressionView', ecommerce: { impressions } }); } else { $('#search-results-loading').remove(); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { console.log('An communication error occurred. Please refresh the page and try again.'); } });}jQuery(function() { let basketCount=0; let lineDetails; let enquiryNoItems = $('#enquiryNoItems'); let template = $('#tmpl-enquiry-line').html(); for ( let i = 0, len = localStorage.length; i < len; ++i ) { if (localStorage.key( i ).indexOf('b-') !== -1) { lineDetails = JSON.parse( localStorage.getItem( localStorage.key( i ) ) ); if(!enquiryNoItems.hasClass('d-none')){ enquiryNoItems.addClass('d-none'); } Mustache.parse(template); if (lineDetails.type === 'listing') { let lineContent = Mustache.render(template, { uuid: lineDetails.uuid, url: lineDetails.url, name: lineDetails.name, subtitle: lineDetails.partnumber + ' | ' + lineDetails.term + ' | ' + lineDetails.condition, partsuits: ((lineDetails.partsuits !== '' && lineDetails.partsuits !== undefined) ? lineDetails.partsuits : ''), type: lineDetails.type }); $('#enquiryBasket').append(lineContent); } else { let lineContent = Mustache.render(template, { uuid: lineDetails.uuid, url: lineDetails.url, name: lineDetails.name, subtitle: lineDetails.partnumber + ' | Venta directa', partsuits: lineDetails.partsuits, type: '', }); $('#enquiryBasket').append(lineContent); } if (i > 1) { $('#b-' + lineDetails.uuid + '-line').addClass('d-none'); } $('#b-' + lineDetails.uuid + '-line').slideDown('slow'); if ($('#a-' + lineDetails.uuid + '-add').length) { $('#a-' + lineDetails.uuid + '-add') .removeClass('btn-outline-dark') .addClass('btn-dark') .html(' Agregado a la solicitud'); } basketCount++; } } $('.enquiryCartCount').html(basketCount); if(basketCount > 2) { setTimeout(function(){ $('#enquiryBasket').append( '
'); $('#b-viewmore-link').on('click', function(event) { event.preventDefault(); $('#b-viewmore').slideUp('slow', '', function(){ $('#b-viewmore').remove(); $('#enquiryBasket>div').removeClass('d-none'); }); }); }, 300); } $('#enquiryBasketCount').val(basketCount);});function addToBasket(itemType, itemUUID, redirect){ "use strict"; event.preventDefault(); let enquiryNoItems = $('#enquiryNoItems'); let count = $('#enquiryBasketCount'); if (!enquiryNoItems.hasClass('d-none')) { enquiryNoItems.addClass('d-none'); } let template = $('#tmpl-enquiry-line').html(); Mustache.parse(template); if (itemType == 'listing') { var localStorageDetails = { type: itemType, uuid: itemUUID, advertid: $('#l-' + itemUUID + '-advertid').text().trim(), url: $('#l-' + itemUUID + '-url').text().trim(), name: $('#l-' + itemUUID + '-manufacturer').text().trim() + ' ' + $('#l-'+itemUUID+'-partname').text().trim(), subtitle: $('#l-' + itemUUID + '-partnumber').text().trim() + ' | ' + $('#l-' + itemUUID + '-term').text().trim() + ' | ' + $('#l-' + itemUUID + '-condition').text().trim(), partnumber: $('#l-' + itemUUID + '-partnumber').text().trim(), partname: $('#l-' + itemUUID + '-partname').text().trim(), partsuits: $('#l-' + itemUUID + '-suits').text().trim(), category: $('#l-' + itemUUID + '-category').text().trim(), subcategory: $('#l-' + itemUUID + '-subcategory').text().trim(), condition: $('#l-' + itemUUID + '-condition').text().trim(), term: $('#l-' + itemUUID + '-term').text().trim(), location: $('#l-' + itemUUID + '-location').text().trim(), manufacturer: $('#l-' + itemUUID + '-manufacturer').text().trim(), photocount: $('#l-' + itemUUID + '-photos').text().trim() }; var products = [{ id: $('#l-'+itemUUID+'-partnumber').text().trim(), name: $('#l-'+itemUUID+'-partname').text().trim(), category: $('#l-'+itemUUID+'-category').text().trim()+($('#l-'+itemUUID+'-subcategory').text().trim() !== '' ? ' / '+$('#l-'+itemUUID+'-subcategory').text().trim():''), variant: $('#l-'+itemUUID+'-term').text().trim() + ' - ' + $('#l-'+itemUUID+'-condition').text().trim(), brand: $('#l-'+itemUUID+'-manufacturer').text().trim(), coupon: $('#l-'+itemUUID+'-location').text().trim(), quantity: 1, dimension7: $('#l-'+itemUUID+'-advertid').text().trim(), dimension14: $('#l-'+itemUUID+'-photos').text().trim(), }]; } else if (itemType == 'part') { var localStorageDetails = { type: itemType, uuid: itemUUID, advertid: false, url: $('#p-'+itemUUID+'-url').val(), name: $('#p-'+itemUUID+'-manufacturer').text().trim() + ' ' + $('#p-' + itemUUID + '-partname').text().trim(), subtitle: $('#p-'+itemUUID+'-partnumber').text().trim() + ' | ' + 'Venta directa', partnumber: $('#p-' + itemUUID + '-partnumber').text().trim(), partname: $('#p-' + itemUUID + '-partname').text().trim(), partsuits: $('#p-' + itemUUID + '-suits').text().trim(), category: $('#p-' + itemUUID + '-category').text().trim(), subcategory: $('#p-' + itemUUID + '-subcategory').text().trim(), condition: false, term: false, location: false, manufacturer: $('#p-' + itemUUID + '-manufacturer').text().trim(), photocount: 0 }; var products = [{ id: $('#p-'+itemUUID+'-partnumber').text().trim(), name: $('#p-'+itemUUID+'-partname').text().trim(), category: $('#p-'+itemUUID+'-category').text().trim()+($('#p-'+itemUUID+'-subcategory').text().trim() !== '' ? ' / '+$('#p-'+itemUUID+'-subcategory').text().trim():''), variant: 'Unspecified', brand: $('#p-'+itemUUID+'-manufacturer').text().trim(), coupon: '', quantity: 1, dimension7: $('#p-'+itemUUID+'-advertid').text().trim(), dimension14: 0 }]; } var lineDetails = Mustache.render(template, localStorageDetails); $('#enquiryBasket').append(lineDetails); $('#b-' + itemUUID + '-line').slideDown('slow'); try { localStorage.setItem('b-' + itemUUID + '-line', JSON.stringify(localStorageDetails) ); } catch(e) { console.log('Local storage not supported'); } if ($('#l-' + itemUUID + '-star').length) { $('#l-' + itemUUID + '-star').remove(); $('#l-' + itemUUID + '-action') .prepend(' ') .off('click') .on('click', function () { removeFromBasket(itemType, itemUUID); }); } else if ($('#a-' + itemUUID + '-add').length) { $('#a-' + itemUUID + '-add') .removeClass('btn-outline-dark') .addClass('btn-dark') .html(' Agregado a la solicitud'); } else if ($('#p-' + itemUUID + '-add').length) { $('#p-' + itemUUID + '-add') .removeClass('btn-outline-dark') .addClass('btn-dark') .html(''); } if(parseInt(count.val()) > 2){ $('#b-'+itemUUID+'-line').addClass('d-none'); } let totalItems = parseInt(count.val()) + 1; count.val(totalItems); $('.enquiryCartCount').html(totalItems); $('#enquiryItem'+itemUUID+'Add').addClass('d-none'); $('#enquiryItem'+itemUUID+'Added').removeClass('d-none'); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'eec.add', ecommerce: { add: { products } } }); if (redirect === 1) { window.location = window.location.protocol + "//" + window.location.host + "/checkout/quote/"; } else { notie.alert({ type: 'success', text: '' + ' ' + (itemType == 'listing' ? $('#l-'+itemUUID+'-manufacturer').text() + ' ' + $('#l-'+itemUUID+'-partname').text() : $('#p-'+itemUUID+'-manufacturer').text() + ' ' + $('#p-'+itemUUID+'-partname').text() ) +' ha sido agregado a su solicitud' + '
', stay: false, time: 3, position: 'top' }); }}function removeFromBasket(itemType, itemUUID){ "use strict"; event.preventDefault(); let action = $('#l-'+itemUUID+'-action'); let lineDetails = JSON.parse(localStorage.getItem( 'b-'+itemUUID+'-line' )); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'eec.remove', ecommerce: { remove: { products: [{ id: lineDetails.partnumber, name: lineDetails.partname, category: lineDetails.category.toUpperCase() + (lineDetails.subcategory !== '' ?' / ' + lineDetails.subcategory.toUpperCase() :''), variant: lineDetails.term + ' - ' + lineDetails.condition, brand: lineDetails.manufacturer, coupon: lineDetails.location, quantity: 1, dimension7: lineDetails.advertid, dimension14: lineDetails.photocount }] } } }); localStorage.removeItem('b-' + itemUUID + '-line'); $('#l-'+itemUUID+'-star').remove(); action.prepend(' '); action.off('click'); action.on('click', function() { addToBasket(itemType, itemUUID); }); notie.alert({ type: 'warning', text: ' ' + ($('#b-' + itemUUID + '-name').length ? $('#b-' + itemUUID + '-name').text() : ($('#l-' + itemUUID + '-link').length ? $('#l-' + itemUUID + '-link').text() : '' ) ) + ' ha sido eliminado de su cesta de consultas
', stay: false, time: 3, position: 'top' }); $('#b-'+itemUUID+'-line').slideUp('slow', '', function(){ $('#b-'+itemUUID+'-line').remove(); if($.trim($('#enquiryBasket').html()) === ''){ $('#enquiryNoItems').hide().removeClass('d-none').slideDown('slow'); } }); if ($('#a-' + itemUUID + '-add').length) { $('#a-' + itemUUID + '-add') .addClass('btn-outline-dark') .removeClass('btn-dark') .html(' Agregar a la solicitud'); } if ($('#p-' + itemUUID + '-add').length) { $('#p-' + itemUUID + '-add') .addClass('btn-outline-dark') .removeClass('btn-dark') .html(''); } let totalItems = parseInt($('#enquiryBasketCount').val()) - 1; $('#enquiryBasketCount').val(totalItems); $('.enquiryCartCount').html(totalItems); if($('#enquiryItem'+itemUUID+'Add') !== undefined){ $('#enquiryItem'+itemUUID+'Add').removeClass('d-none'); $('#enquiryItem'+itemUUID+'Added').addClass('d-none'); }}function searchsite() { "use strict"; let limit = 6; let sitesearch = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: window.location.protocol + '//' + window.location.host + '/dataindex/?' + 'type=search&' + 'filterType=1,2,3&' + 'searchSize=' + limit + '&' + 'searchStart=0&' + 'searchType=typeahead&' + 'searchTerm=%QUERY', wildcard: '%QUERY' } }); $('#search-keyword').typeahead( { hint: true, highlight: true, minLength: 3 }, { name: 'Components', display: 'value', source: sitesearch, limit: limit, templates: { footer: Handlebars.compile( '' ), empty: [ '', 'No se encontraron resultados de búsqueda', '
' ].join('\n'), suggestion: Handlebars.compile( '' + '{{#if partName}}' + '{{#if inventoryCondition}}{{inventoryCondition}} {{/if}}{{partNumber}} {{partName}}
' + '{{else if partNumber}}' + '{{#if inventoryCondition}}{{inventoryCondition}} {{/if}}{{partNumber}}
' + '{{/if}}' + '{{#if modelName}}' + '{{manufacturerName}} {{modelName}}
' + '{{/if}}' + '{{#if inventoryTerm}}' + '{{inventoryTerm}}' + '{{/if}}' + '{{#if partCategory}}' + '{{partCategory}}' + '{{/if}}' + '{{#if modelCategory}}' + '{{modelCategory}}' + '{{/if}}' + '
' ) } } ) .unbind("blur") .on("blur", function () { $('#search-keyword').typeahead("close"); }) .on('typeahead:selected typeahead:autocompleted', function (e, sitesearch) { window.location = window.location.protocol + "//" + window.location.host + "/" + sitesearch.canonicalURL; });}$(function(){ $('.lazy').lazy(); $('#f-submitBtn').on('click' , function(event){ event.preventDefault(); $('#footer-enquiry-form').submit(); }); positionFooter(); window.dataLayer = window.dataLayer || [];window.dataLayer.push([]);});function submitSubscription(token) { document.getElementById("newsletter-subscription").submit();}function submitEnquiry(token) { document.getElementById("footer-enquiry-form").submit();}function positionFooter(){ let footerHeight = $("#sourcing-services").height(); let footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px"; if(($(document.body).height()+footerHeight) > $(window).height()){ $("#sourcing-services").css({position: "absolute"}).stop().animate({top: footerTop},0); }else{ $("#sourcing-services").css({position: "static"}); }}$('.cta-event').on('click', function(){ window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'ctaType': $(this).data('ctatype'), 'ctaText': $(this).data('ctatext'), 'ctaDestinationURL': ($(this).data('ctalink') !== undefined ? $(this).data('ctalink') : $(this).attr('href')), 'event': 'ctaClick' });});function GTMpush(attrName, attrVal, eventVal){ window.dataLayer = window.dataLayer || []; dataLayer.push({ [attrName]: attrVal, 'event': eventVal });}