PageSourceSearch

https://www.gregorypoole.com/wp-content/cache/min/1/wp-content/the…/homepage-search-tabs.js?ver=1789991385

js gregorypoole.com collected 2026-09-25 18:46:44 UTC 7,419 bytes, 17 lines download raw bytes

1var FX=(function(FX,$){FX.HomepageSearchTabs={init:function(){var $tabs=$('.search-mode-tabs');if(!$tabs.length){return}
2this.$root=$tabs.closest('.services-filter-container--search-tabs');this.preventChoicesOnFields();this.bindTabs();this.bindFieldStates();this.bindRentalChoicesOpen();this.bindRentalSubmit();this.bindPartsSubmit();this.bindLocationsSubmit()},preventChoicesOnFields:function(){this.$root.find('.facetwp-facet select').each(function(){var el=this;el.classList.add('no-choice');el.classList.add('js-ignore-choices-auto');if(el.choices&&typeof el.choices.destroy==='function'){el.choices.destroy()}
3if(window.Choices&&el.fxChoicesIsInitialized){var parent=el.closest('.choices');if(parent&&parent.parentNode){parent.parentNode.insertBefore(el,parent);parent.parentNode.removeChild(parent)}
4el.fxChoicesIsInitialized=!1;el.style.display='';el.removeAttribute('hidden');el.removeAttribute('data-choice')}})},bindTabs:function(){var self=this;this.$root.on('click','.search-mode-tab',function(){var $tab=$(this);var sectionId=$tab.attr('aria-controls');self.$root.find('.search-mode-tab').removeClass('active').attr('aria-selected','false');$tab.addClass('active').attr('aria-selected','true');self.$root.find('.search-section').removeClass('active').attr('hidden',!0);self.$root.find('#'+sectionId).addClass('active').removeAttr('hidden');if('search-section-rental'===sectionId){self.initRentalCategoryChoices()}})},bindFieldStates:function(){var self=this;var syncFilter=function($filter){var filled=!1;var $facet=$filter.find('.facetwp-type-fselect');var $select=$filter.find('select.search-field');var $input=$filter.find('input.search-field');if($facet.length&&typeof FWP!=='undefined'&&FWP.facets){var name=$facet.data('name');var values=name&&FWP.facets[name]?FWP.facets[name]:[];filled=Array.isArray(values)&&values.length>0}else if($select.length){filled=!!($select.val()||'').toString().trim()}else if($input.length){filled=!!($input.val()||'').toString().trim()}
5$filter.toggleClass('is-filled',filled);if(filled){$filter.addClass('has-value-label')}};var syncAll=function(){self.preventChoicesOnFields();self.initRentalCategoryChoices();self.$root.find('.services-filter').each(function(){syncFilter($(this))})};this.$root.on('click','.facetwp-type-fselect',function(){$(this).closest('.services-filter').addClass('is-open')});this.$root.on('click','.fs-option',function(){$(this).closest('.services-filter').addClass('has-value-label')});$(document).on('click.homepageSearchTabs',function(e){if(!$(e.target).closest('.services-filter-container--search-tabs .facetwp-type-fselect').length){self.$root.find('.services-filter.is-open').removeClass('is-open')}});this.$root.on('change input','select.search-field, input.search-field',function(){var $filter=$(this).closest('.services-filter');$filter.addClass('has-value-label');syncFilter($filter)});$(document).on('facetwp-loaded.homepageSearchTabs facetwp-refresh.homepageSearchTabs',syncAll);syncAll()},initRentalCategoryChoices:function(){var el=this.$root.find('#rental-category')[0];if(!el||typeof FxChoice==='undefined'){return}
6if(el.fxChoicesIsInitialized){return}
7new FxChoice(el,{shouldSort:!1,searchEnabled:!1,itemSelectText:'',placeholder:!0,placeholderValue:''});this.bindRentalCategoryChoiceEvents(el)},bindRentalCategoryChoiceEvents:function(el){var $filter=$(el).closest('.services-filter');el.addEventListener('showDropdown',function(){$filter.addClass('is-open')});el.addEventListener('hideDropdown',function(){$filter.removeClass('is-open')})},bindRentalChoicesOpen:function(){var self=this;$(document).on('click.homepageSearchTabsRentalChoices',function(e){if(!$(e.target).closest('.search-section--rental .choices').length){self.$root.find('.search-section--rental .
7services-filter--has-select.is-open').removeClass('is-open')}})},slugifyRentalModel:function(text){return(text||'').toLowerCase().replace(/[^a-z0-9\s-]/g,'').trim().replace(/\s+/g,'-').replace(/-+/g,'-')},isRentCatUrl:function(url){return/^https?:\/\/rent\.cat\.com\//i.test(url)},isRentCatEquipmentCategory:function(url){var path=url.split('?')[0].replace(/\/$/,'');return/rent\.cat\.com\/[^/]+\/equipment\/[^/]+$/i.test(path)},appendUrlParams:function(baseUrl,params){var absolute=baseUrl;try{absolute=new URL(baseUrl,window.location.origin).toString()}catch(e){return baseUrl}
8var url=new URL(absolute);Object.keys(params).forEach(function(key){if(params[key]){url.searchParams.set(key,params[key])}});return url.toString()},appendRentCatUtm:function(url){return this.appendUrlParams(url,{utm_source:'gregorypoole.com',utm_medium:'referral',utm_campaign:'dealer_referral'})},buildRentalRequestUrl:function($section,model,location){var baseUrl=$section.data('rental-request-url')||'/rental/rental-request/';return this.appendUrlParams(baseUrl,{machine:model,location:location})},buildRentalTargetUrl:function($section,categoryUrl,model,location){if(!categoryUrl){if(model){return this.buildRentalRequestUrl($section,model,location)}
9return this.appendUrlParams('/rental/',{location:location})}
10if(model){if(this.isRentCatEquipmentCategory(categoryUrl)){var categoryPath=categoryUrl.split('?')[0].replace(/\/$/,'');return this.appendRentCatUtm(categoryPath+'/'+this.slugifyRentalModel(model))}
11return this.buildRentalRequestUrl($section,model,location)}
12if(this.isRentCatUrl(categoryUrl)){return this.appendRentCatUtm(categoryUrl)}
13return this.appendUrlParams(categoryUrl,{location:location})},bindRentalSubmit:function(){var self=this;this.$root.on('click','.js-rental-submit',function(){var $section=$(this).closest('.search-section');var categoryUrl=($section.find('#rental-category').val()||'').trim();var model=($section.find('#rental-model').val()||'').trim();var location=($section.find('#rental-location').val()||'').trim();window.location.href=self.buildRentalTargetUrl($section,categoryUrl,model,location)})},bindPartsSubmit:function(){this.$root.on('click','.js-parts-submit',function(){var keyword=($(this).closest('.search-section').find('#parts-keyword').val()||'').trim();if(!keyword){window.location.href='/parts/';return}
14var baseUrl='https://parts.cat.com/en/gregorypoole/search';var params=new URLSearchParams({q:keyword,page:'1',utm_source:'www.gregorypoole.com',utm_medium:'referral',utm_campaign:'dealer_referral'});window.open(baseUrl+'?'+params.toString(),'_blank')})},bindLocationsSubmit:function(){var generalLocationsUrl='/sales-reps-locations/locations/';this.$root.on('click','.js-locations-submit',function(){var $btn=$(this);var zipcode=($btn.closest('.search-section').find('#hp-locations-zip').val()||'').trim();if(!zipcode){window.location.href=generalLocationsUrl;return}
15if($btn.prop('disabled')){return}
16$btn.prop('disabled',!0);$.getJSON('/wp-json/wpcm-locations/v1/view',{zipcode:zipcode,distance:50,imahuman:'16749697'}).done(function(results){var list=Array.isArray(results)?results.slice():[];if(!list.length){window.location.href=generalLocationsUrl;return}
17list.sort(function(a,b){var da=typeof a.distance==='number'?a.distance:parseFloat(a.distance)||Infinity;var db=typeof b.distance==='number'?b.distance:parseFloat(b.distance)||Infinity;return da-db});var nearest=list[0];var url=nearest&&nearest.url?nearest.url:generalLocationsUrl;window.location.href=url}).fail(function(){window.location.href=generalLocationsUrl})})}};$(document).ready(function(){FX.HomepageSearchTabs.init()});return FX}(FX||{},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.