PageSourceSearch

https://gorollick.com/scripts/gorollick/top-menu.js?v=2.229.0

js gorollick.com collected 2026-09-29 06:05:11 UTC 12,999 bytes, 396 lines download raw bytes

1/** @format */
2
3const { defaultConditions } = gorollick;
4const topMenuStartPerfRemediationEnabled = !!(window.gorollick && window.gorollick.startPerfRemediation);
5$(document).ready(() => {
6	prepare_popovers();
7	customDropDown();
8	onWindowResize();
9	// loadNavigationGPT();
10	setDropDownMaxHeight();
11});
12
13function onWindowResize() {
14	const h = $('#rollick_header_container').outerHeight();
15	if (topMenuStartPerfRemediationEnabled) {
16		const minimumHeaderHeight = document.body.classList.contains('rollick-redesign') ? 76 : 60;
17		$('#content_container').css('padding-top', `${Math.max(h || 0, minimumHeaderHeight)}px`);
18		return;
19	}
20	$('#content_container').css('padding-top', `${h}px`);
21}
22
23function customDropDown() {
24	const $menu = $('ul.dropdown-menu');
25	$('.toggle')
26		.off('click.topMenu')
27		.on('click.topMenu', () => {
28			$menu.toggleClass('is-active');
29		});
30	$('.home')
31		.off('mouseenter.topMenu')
32		.on('mouseenter.topMenu', function (e) {
33			$('.dropdown-menu.motorcycles').css('display', 'none');
34			$('.dropdown-menu.rvs').css('display', 'none');
35			if (e.target && e.target.id != 'home') {
36				hide_all_popovers(e);
37			}
38			$(this).next('ul').toggle();
39			e.stopPropagation();
40			e.preventDefault();
41		});
42	$('ul.navbar-nav.mr-auto')
43		.off('mouseenter.topMenu')
44		.on('mouseenter.topMenu', (e) => {
45			$('ul.dropdown-menu').css('display', 'none');
46			e.stopPropagation();
47			e.preventDefault();
48		});
49
50	$('.dropdown-submenu a.options')
51		.off('mouseenter.topMenu')
52		.on('mouseenter.topMenu', function (e) {
53			if (this.innerText == 'RVs') {
54				$('.dropdown-menu.rvs').css('display', 'block');
55				$('.dropdown-menu.motorcycles').css('display', 'none');
56				$('.dropdown-menu.finance').css('display', 'none');
57				$('.dropdown-menu.sellYourVehicle').css('display', 'none');
58			} else if (this.innerText == 'Motorcycles') {
59				$('.dropdown-menu.motorcycles').css('display', 'block');
60				$('.dropdown-menu.rvs').css('display', 'none');
61				$('.dropdown-menu.finance').css('display', 'none');
62				$('.dropdown-menu.sellYourVehicle').css('display', 'none');
63			} else if (this.innerText == 'Financing') {
64				$('.dropdown-menu.finance').css('display', 'block');
65				$('.dropdown-menu.motorcycles').css('display', 'none');
66				$('.dropdown-menu.rvs').css('display', 'none');
67				$('.dropdown-menu.sellYourVehicle').css('display', 'none');
68			} else if (this.innerText == 'Sell Your Vehicle') {
69				$('.dropdown-menu.sellYourVehicle').css('display', 'block');
70				$('.dropdown-menu.motorcycles').css('display', 'none');
71				$('.dropdown-menu.rvs').css('display', 'none');
72				$('.dropdown-menu.finance').css('display', 'none');
73			}
74			e.stopPropagation();
75			e.preventDefault();
76		});
77	$('.other')
78		.off('mouseenter.topMenu')
79		.on('mouseenter.topMenu', (e) => {
80			$('.dropdown-menu.motorcycles').css('display', 'none');
81			$('.dropdown-menu.rvs').css('display', 'none');
82			$('.dropdown-menu.finance').css('display', 'none');
83			$('.dropdown-menu.sellYourVehicle').css('display', 'none');
84			e.stopPropagation();
85			e.preventDefault();
86		});
87}
88
89/**
90 * Reinitializes header navigation after AJAX body swap.
91 * Safe to call multiple times - uses namespaced events to prevent handler accumulation.
92 */
93function reinitHeaderNavigation() {
94	prepare_popovers();
95	customDropDown();
96	setDropDownMaxHeight();
97}
98function prepare_popovers() {
99	populate_popover_content();
100	const popoverTemplate =
101		'<div class="popover $CUSTOM_CSS_CLASS" role="tooltip">' +
102		'<div class="arrow"></div><h3 class="popover-header"></h3>' +
103		'<div class="popover-body"></div></div>';
104	$('.submenu_popover').each(function () {
105		const _this = this;
106		let custom_css_class = '';
107		const _custom_css_class = $(_this).attr('data-css-class');
108		custom_css_class = _custom_css_class || custom_css_class;
109		const _popoverTemplate = popoverTemplate.replace('$CUSTOM_CSS_CLASS', custom_css_class);
110		const $popover = $(_this);
111		$popover.popover('dispose');
112		$popover
113			.popover({
114				trigger: 'manual',
115				template: _popoverTemplate,
116				placement: 'bottom',
117				html: true,
118			})
119			.off('mouseenter.topMenu')
120			.on('mouseenter.topMenu', function () {
121				hide_all_popovers(this);
122				$popover.popover('show');
123				$('#content_container').add('.header_container').add('nav-item');
124				// .off("mousemove").on("mousemove", function () {
125				//     $popover.popover('hide');
126				// });
127			});
128	});
129	$('body').off('.topMenu').on('click.topMenu', hide_all_popovers);
130	$(window).off('.topMenu').on('scroll.topMenu', hide_all_popovers);
131}
132
133function populate_popover_content() {
134	$('[rel=popover]').each(function () {
135		const $el = $(this);
136		const storedTemplateId = $el.data('popoverTemplateId');
137		const templateId = storedTemplateId || $el.attr('data-content');
138
139		if (!templateId || !templateId.startsWith('#')) {
140			return;
141		}
142
143		$el.data('popoverTemplateId', templateId);
144		const templateData = $(templateId).html();
145		if (templateData != null) {
146			$el.attr('data-content', templateData);
147		}
148	});
149}
150
151function hide_all_popovers(e) {
152	$('[rel=popover]').each(function () {
153		// hide any open popovers when the anywhere else in the body is clicked
154		if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
155			$(this).popover('hide');
156		}
157	});
158	if (e && e.target && e.target.id == 'search_new_rv') {
159		navigateToCategory('rvs', 'n');
160	}
161	if (e && e.target && e.target.id == 'search_rv') {
162		navigateToCategory('rvs', defaultConditions.navbar.rvs);
163	}
164	if (e && e.target && e.target.id == 'search_used_rv') {
165		navigateToCategory('rvs', 'u');
166	}
167	if (e && e.target && e.target.id == 'search_showroom_motorcycle') {
168		navigateToCategory('motorcycles', 's');
169	}
170	if (e && e.target && e.target.id == 'search_new_motorcycle') {
171		navigateToCategory('motorcycles', 'n');
172	}
173	if (e && e.target && e.target.id == 'search_used_motorcycle') {
174		navigateToCategory('motorcycles', 'u');
175	}
176	if (e && e.target && e.target.id == 'search_motorcycle') {
177		navigateToCategory('motorcycles', defaultConditions.navbar.motorcycles);
178	}
179	if (e && e.target && e.target.id == 'menu_item_watercrafts') {
180		navigateToCategory('watercrafts', defaultConditions.navbar.watercrafts
180);
181	}
182	if (e && e.target && e.target.id == 'menu_item_scooters') {
183		navigateToCategory('scooters', defaultConditions.navbar.scooters);
184	}
185	if (e && e.target && e.target.id == 'menu_item_snowmobiles') {
186		navigateToCategory('snowmobiles', defaultConditions.navbar.snowmobiles);
187	}
188	if (e && e.target && e.target.id == 'rv_rental') {
189		navigateToStaticPages('rv_rental');
190	}
191	if (e && e.target && e.target.id == 'motorcycle_rental') {
192		navigateToStaticPages('motorcycle_rental');
193	}
194	if (e && e.target && e.target.id == 'rv_accessories') {
195		navigateToRvAccessoriesPage();
196	}
197	if (e && e.target && e.target.id == 'home') {
198		window.location.href = `/${gorollick.affinity}/start`;
199	}
200}
201
202function openNavSamsClub() {
203	document.getElementById('samclubMainNav').style.width = '280px';
204}
205function closeSamsClubNav() {
206	document.getElementById('samclubMainNav').style.width = '0';
207	document.getElementById('RVSSubNav').style.width = '0';
208	document.getElementById('MOTORCYCLESSubNav').style.width = '0';
209}
210function openSamSideNav(category) {
211	document.getElementById('samclubMainNav').style.width = '0';
212	document.getElementById(`${category.toUpperCase()}SubNav`).style.width = '280px';
213}
214function closeSamSideNav(category) {
215	document.getElementById('samclubMainNav').style.width = '280px';
216	document.getElementById(`${category.toUpperCase()}SubNav`).style.width = '0';
217}
218
219function navigateToStaticPages(category) {
220	const categoryMapping = {
221		rv_rental: 'rvrentals',
222		motorcycle_rental: 'motorcyclerentals',
223	};
224
225	const urlParams = new URLSearchParams(location.search.substr(1));
226	const mount_path = gorollick.mountpath;
227	const { affinity } = gorollick;
228	const retainableQueryParams = ['zip', 'partner', 'highlighted'];
229	const queryParamObject = getAllQueryParams(urlParams);
230	for (const key in queryParamObject) {
231		if (Object.hasOwn(queryParamObject, key)) {
232			if (
233				retainableQueryParams.findIndex((ele) => {
234					if (ele.includes('*') && key.includes(ele.replace('*', ''))) {
235						return true;
236					}
237					if (key.toLowerCase() == ele.toLowerCase()) {
238						return true;
239					}
240					return false;
241				}) < 0
242			) {
243				delete queryParamObject[key];
244			}
245		}
246	}
247	window.location.href = `${window.location.origin + mount_path}/${affinity}/${categoryMapping[category]}${
248		Object.keys(queryParamObject).length ? `?${new URLSearchParams(queryParamObject).toString()}` : ''
249	}`;
250}
251
252function navigateToCategory(category, condition, brand = '') {
253	const urlParams = new URLSearchParams(location.search.substr(1));
254	/* Params to keep between navigation:
255        zip, condition, distance, partner, utm_, pk_
256    */
257	const skipParam = gorollick.skipParam || '';
258	const retainableQueryParams = ['zip', 'condition', 'distance', 'partner', 'highlighted'];
259	const queryParamObject = getAllQueryParams(urlParams);
260	for (const key in queryParamObject) {
261		if (Object.hasOwn(queryParamObject, key)) {
262			if (
263				retainableQueryParams.findIndex((ele) => {
264					if (ele == skipParam) {
265						return false;
266					}
267					if (ele.includes('*') && key.includes(ele.replace('*', ''))) {
268						return true;
269					}
270					if (key.toLowerCase() == ele.toLowerCase()) {
271						return true;
272					}
273					return false;
274				}) < 0
275			) {
276				delete queryParamObject[key];
277			}
278		}
279	}
280	queryParamObject.categories = category;
281	condition = (condition || queryParamObject.condition || '').toLowerCase();
282	if (condition) {
283		queryParamObject.condition = condition;
284	}
285	if ((category == 'rvs' || category == 'boats') && condition == 's') {
286		condition = 'n';
287		queryParamObject.condition = condition;
288	}
289	if (category == 'golf-carts' && ['n', 'new', ''].includes(condition)) {
290		brand = brand || 'E-Z-GO';
291	}
292	const conditionWord =
293		condition.toLowerCase() == 'n' || !condition.length
294			? 'NEW'
295			: condition.toLowerCase() == 'u'
296			? 'USED'
297			: 'SHOWROOM';
298	if (
299		DISTANCES_BY_VEHICLE_CATEGORY[category] &&
300		DISTANCES_BY_VEHICLE_CATEGORY[category][conditionWord] &&
301		DISTANCES_BY_VEHICLE_CATEGORY[category][conditionWord].includes(parseInt(getCookie('radius'), 10))
302	) {
303		queryParamObject.distance = getCookie('radius');
304	} else {
305		queryParamObject.distance = DISTANCES_BY_VEHICLE_CATEGORY[category].DEFAULT;
306	}
307	if (brand) {
308		queryParamObject.manufacturers = brand;
309	}
310	const simplified_slug_categories = [
311		'utvs',
312		'rvs',
313		'boats',
314		'motorcycles',
315		'atvs',
316		'golf-carts',
317		'watercrafts',
318		'scooters',
319		'snowmobiles',
320	];
321	let slug = '';
322	if (/^n$/i.test(condition) && !simplified_slug_categories.includes(category.toLowerCase())) {
323		slug = 'new';
324	}
325	if (/^u$/i.test(condition) && !simplified_slug_categories.includes(category.toLowerCase())) {
326		slug = 'used';
327	}
328	const { distance } = queryParamObject;
329	if (category == 'rvs') {
330		if (!distance) {
331			queryParamObject.distance = '4096';
332		}
333	} else if (distance == '4096') {
334		queryParamObject.distance = '100';
335	}
336	slug = slug ? `${slug}-${category}-for-sale` : `${category}-for-sale`;
337	const mount_path = gorollick.mountpath;
338	let { affinity } = gorollick;
339	if (affinity == 'r') {
340		affinity = getAffinity() || 'r';
341		if (affinity !== 'r') {
342			gorollick.affinity = affinity;
343		}
344	}
345	if (gorollick.state?.searchPayload?.highlighted && !queryParamObject.highlighted) {
346		queryParamObject.highlighted = true;
347	}
348	// console.log(affinity)
349	// let queryParamObject = getAllQueryParams(urlParams);
350	// delete queryParamObject.distance;
351	window.location.href = `${window.location.origin + mount_path}/${affinity}/inventory/${slug}${
352		Object.keys(queryParamObject).length ? `?${new URLSearchParams(queryParamObject).toString()}` : ''
353	}`;
354}
355
356function navigateToRvAccessoriesPage() {
357	const url = 'https://www.partsvia.com/gorollick';
358	const trackingObj = { action: 'Navigation Click' };
359	trackingObj.category = 'PartsVia';
360	trackGA(trackingObj);
361	window.open(url, '_blank');
362}
363
364function loadNavigationGPT() {
365	if (window.adsBlocked) {
366		$('.adm-cards').hide();
367		return;
368	}
369	// console.log($('.adm-cards').length);
370	if (!$('.adm-cards').length) {
371		return;
372	}
373	const admIds = [];
374	let targets;
375	window.googletag = window.googletag || { cmd: [] };
376	googletag.cmd.push(() => {
377		googletag.pubads().collapseEmptyDivs();
378		$('.adm-nav-cards').each((index, item) => {
379			const itemId = $(item).attr('id');
380			targets = $(item).data();
381			admIds.push(itemId);
382			const adSlot = googletag.defineSlot(targets.adunit, targets.dimensions, itemId);
383			const sizeMap = [{ screenSize: [969, 624], adSize: [320, 50] }];
384			setUpAdResponsive(targets, adSlot, sizeMap);
385			setAdTarget(targets, adSlot);
386			adSlot.addService(googletag.pubads());
387		});
388		googletag.enableServices();
389		displayGTM(admIds);
390	});
391}
392
393function setDropDownMaxHeight() {
394	const headerHeight = $('.rollick_header_container').height();
395	$('.dropdown-menu').css('max-height', `calc(100vh - ${headerHeight + 3}px)`);
396}

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.