PageSourceSearch

https://www.onthesandvacations.com/bookingEngine/javascripts/srp/z_srp.js?v=159

js onthesandvacations.com collected 2026-10-09 22:34:39 UTC 20,196 bytes, 547 lines download raw bytes

1//////////////////////
2// Global Functions //
3//////////////////////
4
5// SRP - Submit Form Function
6function srpSubmitForm() {
7	$.ajax({
8		type: 'POST',
9		url: siteFolder + 'ajax/results' + siteURLEnding,
10		data: $('#srpSubmitForm').serialize(),
11		success: function (data) {
12
13      // SRP - Reset scroll form paging for infinite scroll after scroll animation is done
14			setTimeout(function () {
15        $('#scrollForm [name=page]').val(1);
16			}, 810);
17
18      // SRP - Populate the Results
19  		$('.srp-results-wrap').html(data);
20
21  		// SRP - Update Filter Count in header
22      filterCount();
23
24			// SRP - Initialize Property Widget Image Slider
25			bePropWidgetSlider();
26
27			// SRP - If Sort By Option is Open - Close it
28			$('.srp-header-sort-by-select-chosen, .srp-header-sort-by-toggle').removeClass('active');
29			$('.srp-header-sort-by-select-dropdown').removeClass('open');
30
31      if($('#srpMap').length){
32        // SRP - Update the Map
33        $.ajax({
34          type: 'POST',
35          url: siteFolder + 'ajax/map' + siteURLEnding,
36          data: $('#mapForm').serialize(),
37          dataType: 'json',
38          success: function(data) {
39            drawMapAllResults(map, markers, data);
40          },
41          error: function(xhr, textStatus, error){
42            //console.log(xhr.statusText);
43            //console.log(textStatus);
44            //console.log(error);
45          }
46        });
47      }
48
49      // SRP - Flex Tab Update
50      $.ajax({
51        type: 'POST',
52        url: siteFolder + 'ajax/flextabs' + siteURLEnding,
53    		data: $('#srpSubmitForm').serialize(),
54        success: function(data) {
55          $('#flexTabs').html(data);
56        },
57        error: function(xhr, textStatus, error){
58          //console.log(xhr.statusText);
59          //console.log(textStatus);
60          //console.log(error);
61        }
62      });
63
64      // SRP - Update Address Bar URL with New Params
65      var formString = $("#srpSubmitForm").serialize();
66      var formString = formString.replace('&srp_filters_modal_options_property_name=','');
67      var formString = formString.replace('&srp_filters_modal_options_property_number=','');
68      window.history.replaceState( {} , null, '?' + formString );
69
70      // SRP - Show Clear All Button
71      showClearAllButton();
72
73      // SRP - Update the Canonical URL Based on the new formString (for better Sharing on Mobile/Desktop)
74      var currentURL = window.location.href;
75      $('link[rel="canonical"]').attr('href',currentURL);
76
77      // SRP - Display the Popular Toast
78			displayPopular();
79
80			// SRP - Scroll to first result (includes flex tabs and filters if they are there)
81			$('html, body').animate({ scrollTop: $('#topOfResults').position().top - 20 }, 800);
82
83		}
84	}); // End Ajax Call
85};
86
87// SRP - Update Filter Count in header
88function filterCount() {
89	var filterCount = $('.srp-active-filters .srp-active-filters-badge:not([data-id=checkinDates])').length;
90  if (filterCount >= 1) {
91  	$('.srp-header-filters-count').text(filterCount);
92  }
93  if (filterCount == 0 ) {
94  	$('.srp-header-filters-count').text('');
95  }
96}
97filterCount();
98
99// SRP - Show Clear All Button
100function showClearAllButton() {
101  if ( $('.srp-active-filters').is(':empty') ) {
102    $('.srp-header-filters-clear').addClass('d-none');
103  } else {
104    $('.srp-header-filters-clear').removeClass('d-none');
105  }
106}
107showClearAllButton();
108
109// SRP - Update Property Price Function - used by /srp/resultsLoopProperty.cfm
110// - Dated Search Calculation via API Call ajax
111function updatePropertyPrice(propertyID, checkin, checkout){
112	$.ajax({
113		type: 'GET',
114		url: siteFolder + 'ajax/srp/quote' + siteURLEnding + '?propertyID=' + propertyID + '&checkin=' + checkin + '&checkout=' + checkout,
115		dataType: 'text',
116		success: function(data) {
117			$('#propertyPriceDiv'+propertyID).html(data);
118		},
119		error: function(xhr, textStatus, error){
120			//console.log(xhr.statusText);
121			//console.log(textStatus);
122			//console.log(error);
123		}
124	});
125}
126
127// SRP - Flex Day Tab Click - Used by /srp/flexTabs.cfm
128function clickFlexDayTab(tab, checkin, checkout){
129	$('#flexTab').val(tab);
130	$('#srpDatesArrivalDate').val(checkin);
131	$('#srpDatesDepartureDate').val(checkout);
132	$('.srp-dates-arrival-date').html(checkin);
133	$('.srp-dates-departure-date').html(checkout);
134  datepicker.dates[0] = $.datepicker.parseDate(datepicker.dateFormat, checkin).getTime();
135	datepicker.dates[1] = $.datepicker.parseDate(datepicker.dateFormat, checkout).getTime();
136	$('.be-datepicker-widget').datepicker('refresh');
137	srpSubmitForm();
138}
139
140// SRP - Display the Current Users Toast Function
141function displayCurrentUsersUrgency(){
142	var currentUsers = $('#currentUsersID').val();
143	var siteName = $('#urgencySiteName').val();
144	if(currentUsers >= 1){
145		$.fn.beToast({
146			icon: 'bolt-solid',
147			iconColor: 'site-color-2',
148			title: 'Hurry Now!',
149			body: `<strong>${currentUsers}</strong> people are planning their vacation with ${siteName} right now.`,
150			delay: 7000
151		});
152	}
153	if(currentUsers == 1){
154		$.fn.beToast({
155			icon: 'bolt-solid',
156			iconColor: 'site-color-2',
157			title: 'Hurry Now!',
158			body: `1 person is planning their vacation with ${siteName} right now.`,
159			delay: 7000
160		});
161	}
162}
163
164// SRP - Display the Popular Toast Function
165function displayPopular(){
166	var percentBooked = $('#percentBookedID').val();
167	if(percentBooked >= 0){
168		$.fn.beToast({
169			icon: 'bolt-solid',
170			iconColor: 'site-color-2',
171			title: 'Popular Search!',
172			body: `Your dates are popular! <strong>${percentBooked}%</strong> of our inventory is booked. Don't miss out!`,
173			delay: 7000
174		});
175	}
176}
177
178function loadCustomSRP(url) {
179	$('#srpSubmitForm').attr('action', url);
180	$('#srpSubmitForm').submit();
181}
182
183////////////////////
184// Document Ready //
185////////////////////
186$(document).ready(function () {
187
188  // SRP - Display the Popular Toast on Page Load
189	displayPopular();
190
191  // SRP - Display the Current Users Toast on Page Load
192	displayCurrentUsersUrgency();
193
194	// SRP - Sort By Button Choice
195	$('.srp-header-sort-by-select-dropdown-option-btn').on('click', function () {
196		// Desktop
197		var sortBy = $(this).data('sort-by');
198		var sortByText = $(this).closest('.srp-header-sort-by-select-dropdown-option').find('.srp-header-sort-by-select-dropdown-option-text').text();
199		var sortByIcon = $(this).find('use').attr('href');
200		$('.srp-header-sort-by-select-dropdown-option-btn').removeClass('active');
201		$(this).addClass('active');
202		$('.srp-header-sort-by-select-chosen-text').text(sortByText);
203		$('.srp-header-sort-by-select-chosen-icon').find('use').attr('href', sortByIcon);
204		$('input[name=sortBy]').val(sortBy);
205		// Mobile & Desktop
206		$('.srp-header-sort-by-toggle').find('use').attr('href', sortByIcon);
207		$('.srp-header-sort-by-select-dropdown').removeClass('open');
208		// Submit SRP Form
209		srpSubmitForm();
210	});
211
212	// SRP - Mobile - Move Date Labels to Filters Modal
213	$(window).on('resize',function(){
214		if ($(window).outerWidth() <= 1024) {
215  		// Mobile
216			$('.srp-dates-desktop-wrap').prependTo('.srp-filters-modal-datepicker');
217		} else {
218  		// Desktop
219			$('.srp-dates-desktop-wrap').prependTo('.srp-dates-desktop-toggle');
220		}
221	}).resize();
222
223	// SRP - Dates Modal - Flex Days
224	if ($('#flexDatesCheckbox').length) {
225  	// Move Flexdates checkbox for mobile / desktop
226  	$(window).on('resize',function(){
227  		if ($(window).outerWidth() <= 1024) {
228    		// Mobile
229  			$('.srp-dates-modal .i-modal-footer-bar .srp-dates-modal-options-item .be-checkbox').insertAfter('.srp-filters-modal-datepicker .srp-filters-modal-datepicker-body');
230  		} else {
231    		// Desktop
232  			$('.srp-filters-modal-datepicker .srp-dates-modal-options-item .be-checkbox').appendTo('.i-modal-footer-bar .srp-dates-modal-options-item');
233  		}
234  	}).resize();
235  	$('#flexDatesCheckbox').change(function() {
236  		if($('#flexDatesCheckbox').is(':checked') == true){
237  			$('#flexDates').val(1);
238  		} else {
239  			$('#flexDates').val(0);
240  		}
241  	});
242  }
243
244  // SRP - Toggle Exact On for Counters with Exact
245  if ( $('.be-counter-exact-toggle-checkbox').length ) {
246    $('.be-counter-exact-toggle-checkbox').on('change',function(){
247      $(this).closest('.be-counter-group').find('.be-counter-and-up').toggleClass('d-none');
248    });
249  }
250
251	// SRP - Filters - Remove Active Filters Badges
252	$(document).on('click', '.srp-active-filters-badge', function () {
253		var id = $(this).data('id');
254		if(id == 'checkinDates'){
255			clearDatepicker();
256		} else if (id == 'sleeps' || id == 'bedrooms' || id == 'bathrooms'){
257			var matchInput = $('input[type=hidden][name=' + id + ']');
258			matchInput.val('');
259			// Reset Counters in Filter Modal
260			matchInput.closest('.be-counter-group').find('.be-counter-count').addClass('d-none');
261			matchInput.closest('.be-counter-group').find('.be-counter-any').removeClass('d-none');
262			matchInput.closest('.be-counter-group').find('.be-counter-exact-toggle').addClass('disabled');
263			matchInput.closest('.be-counter-group').find('.be-counter-exact-toggle-checkbox').prop('checked', false).prop('disabled', true);
264			// Reset Sliders in Filter Modal
265			if ($('.srp-filters-modal-options-slider-wrap').length) {
266  			if ( id == 'sleeps' ) {
267    			srpFilterSlider('srpRefineGuestsSlider', 'reset');
268  			}
269  			if ( id == 'bedrooms' ) {
270    			srpFilterSlider('srpRefineBedroomsSlider', 'reset');
271  			}
272  			if ( id == 'bathrooms' ) {
273    			srpFilterSlider('srpRefineBathroomsSlider', 'reset');
274  			}
275			}
276		} else {
277			$('#' + id).trigger('click'); // Changed to trigger click so that the 'deselect all' is changed too
278		}
279		srpSubmitForm();
280	});
281
282	// SRP - Filters - Filters and Dates Modal Apply Buttons
283	$('.srp-dates-modal-footer-apply, .srp-filters-modal-footer-apply').on('click', function () {
284		if (!$('#srpDatesArrivalDate').val() == '' && $('#srpDatesDepartureDate').val() == '') {
285			// Don't submit the form if there are not BOTH dates added (just one date)
286			$('.i-modal-footer-bar').append(alertMessage('alert alert-danger i-modal-alert m-0', 'Please choose a Departure Date'));
287			setTimeout(function () {
288				$('.i-modal-alert').fadeOut(400, function () { $(this).remove(); });
289			}, 3000);
290		} else {
291			// Close Modal
292			$('html').removeClass('modal-open');
293			$(this).closest('.i-modal').removeClass('open');
294			// Submit SRP Form
295			srpSubmitForm();
296		}
297	});
298
299	// SRP - Filters - Counters
300	beCounter('.srp-filters-modal', 'Any');
301
302	// SRP - Filters - Slider Function
303	function srpFilterSlider(id, reset) {
304  	var srpFilterSliderID = $('#' + id);
305  	var srpFilterSliderMin = srpFilterSliderID.data('min');
306  	var srpFilterSliderMax = srpFilterSliderID.data('max');
307  	var srpFiltersSliderInput = $('#' + id + 'Input');
308		var srpFiltersSliderInputValue = srpFiltersSliderInput.val();
309  	if (srpFilterSliderID.length) {
310  		var srpFilterSlider = document.getElementById(id);
311  		if (reset == 'reset') {
312    		srpFilterSlider.noUiSlider.reset();
313        srpFiltersSliderInput.val('');
314  		} else {
315    		// Load Slider
316    		noUiSlider.create(srpFilterSlider,{
317    			start: [ srpFilterSliderMin, srpFilterSliderMax ],
318    			step: 1,
319    			tooltips: [ wNumb({ decimals: 0 }), wNumb({ decimals: 0 }) ],
320    			connect: [false, true, false],
321    			range: { 'min': [ srpFilterSliderMin ], 'max': [ srpFilterSliderMax ] },
322    			format: wNumb({ decimals: 0 })
323    		});
324    		// Populate slider values when input already has values on page load
325    		if (srpFiltersSliderInputValue.length) {
326      		var splitValue = srpFiltersSliderInputValue.split(',');
327      	  srpFilterSlider.noUiSlider.set([splitValue[0], splitValue[1]]);
328    		}
329    		// Populate hidden input with slider values when set
330    		srpFilterSlider.noUiSlider.on('set',function() {
331    			var srpFilterSliderValues = srpFilterSlider.noUiSlider.get();
332          srpFiltersSliderInput.val(srpFilterSliderValues);
333    		});
334      }
335  	}
336  }
337
338  // SRP - Filters - Guest Slider
339  srpFilterSlider('srpRefineGuestsSlider');
340
341  // SRP - Filters - Bedrooms Slider
342  srpFilterSlider('srpRefineBedroomsSlider');
343
344  // SRP - Filters - Bathrooms Slider
345  srpFilterSlider('srpRefineBathroomsSlider');
346
347	// SRP - Filters - Select All Checkboxes
348	$('.srp-filters-modal-options-select-all-checkbox').on('click', function () {
349		var itemCheckbox = $(this).closest('.srp-filters-modal-options-section').find('.srp-filters-modal-options-item-checkbox');
350		var checked = $(this).prop('checked');
351		itemCheckbox.prop('checked', checked);
352		$(this).next().text($(this).next().text() == 'Deselect All' ? 'Select All' : 'Deselect All');
353	});
354
355	// SRP - Filters - Deselect Select All Checkbox when a single or more checkbox is unchecked
356	$('.srp-filters-modal-options-item-checkbox').on('click', function () {
357		var itemCheckbox = $(this).closest('.srp-filters-modal-options-section').find('.srp-filters-modal-options-item-checkbox');
358		var selectAllCheckbox = $(this).closest('.srp-filters-modal-options-section').find('.srp-filters-modal-options-select-all-checkbox');
359		var selectAllLabel = $(this).closest('.srp-filters-modal-options-section').find('.srp-filters-modal-options-select-all label');
360		if (!$(itemCheckbox).filter(':checked').length > 0) {
361			$(selectAllCheckbox).prop('checked', false);
362			$(selectAllLabel).text('Select All');
363		}
364		if ($(itemCheckbox).filter(':checked').length == $(itemCheckbox).length) {
365			$(selectAllCheckbox).prop('checked', true);
366			$(selectAllLabel).text('Deselect All');
367		} else {
368			$(selectAllCheckbox).prop('checked', false);
369			$(selectAllLabel).text('Select All');
370		}
371	});
372
373	// SRP - Filters - Collapse Checkboxes for 'See all' button toggle on load
374	$('.srp-filters-modal-options-checkboxes').each(function () {
375  	var optionsMin = $(this).data('options-min');
376		var optionsItem = $(this).find('.srp-filters-modal-options-item');
377		var optionsItemHeight = optionsItem.outerHeight();
378		var seeAllDefaultHeight = document.documentElement.style.getPropertyValue('--seeAllDefaultHeight');
379		if ($(window).outerWidth() <= 768) {
380  		// Mobile
381  		var optionsMinCalc = optionsMin;
382		} else {
383  		// Desktop
384  		var optionsMinCalc = optionsMin / 2;
385		}
386		$(this).css({'--seeAllDefaultHeight': optionsItemHeight * optionsMinCalc + 'px'});
387		if (optionsMin < optionsItem.length) {
388  		$(this).addClass('collapsed');
389  		$(this).next('.srp-filters-modal-options-see-all').removeClass('d-none');
390		}
391	});
392
393	// SRP - Filters - See All Button Toggle
394	$('.srp-filters-modal-options-see-all-btn').on('click', function () {
395		var seeAllContainer = $(this).closest('.srp-filters-modal-options-section').find('.srp-filters-modal-options-checkboxes');
396		var seeAllDefaultHeight = document.documentElement.style.getPropertyValue('--seeAllDefaultHeight');
397		var seeAllBtnTextSpan = $(this).find('.srp-filters-modal-options-see-all-btn-text');
398		var seeAllBtnIcon = $(this).find('use').attr('href');
399		var seeAllScrollHeight = seeAllContainer[0].scrollHeight;
400		if (seeAllBtnIcon == '#plus-regular') {
401			seeAllContainer.addClass('collapsed');
402			seeAllBtnTextSpan.text('See less');
403			seeAllContainer.css({ 'max-height': seeAllScrollHeight + 'px' });
404			$(this).find('use').attr('href', '#minus-regular');
405		} else {
406			seeAllContainer.removeClass('collapsed');
407			seeAllBtnTextSpan.text('See all');
408			seeAllContainer.css({ 'max-height': seeAllDefaultHeight });
409			$(this).find('use').attr('href', '#plus-regular');
410		}
411	});
412
413	// SRP - Property Select - Jump to PDP
414	$('.srp-filters-modal-options-select').change(function () {
415    var tabName = $(this).find('option:selected').text();
416		var redirectWindow = window.open( this.options[ this.selectedIndex ].value, tabName);
417		redirectWindow.location;
418	});
419
420	// SRP - Filters - Clear All Filters Function
421	function clearAllFilters() {
422  	// Clear all checkboxes in the Filter Modal Form
423		$('.srp-filters-modal input[type=checkbox]').prop('checked', false);
424		$('.be-counter-and-up').addClass('d-none');
425		// Clear all selectpickers in the Filter Modal Form
426		$('.srp-filters-modal-options-select').selectpicker('val', '');
427		// Clear all hidden inputs in the Filter Modal Form
428		if ($('.srp-filters-modal input[name^=checkin], .srp-filters-modal input[name^=checkout]')) {
429			// Don't clear dates
430		} else {
431			$('.srp-filters-modal input[type=hidden]').val('');
432		}
433		// Clear all counter hidden inputs
434		$('.srp-filters-modal .be-counter').each(function () {
435			var min = $(this).find('.be-counter-count').data('min');
436			$(this).find('.be-counter-count').text(min).addClass('d-none');
437			$(this).find('.be-counter-any').removeClass('d-none');
438			$(this).find('input[type=hidden]').val('Any');
439			$(this).find('.be-counter-exact-toggle').addClass('disabled');
440			$(this).find('.be-counter-exact-toggle-checkbox').prop('checked', false).prop('disabled', true);
441		});
442		// Clear all Sliders in Filter Modal
443		if ($('.srp-filters-modal-options-slider-wrap').length) {
444			srpFilterSlider('srpRefineGuestsSlider', 'reset');
445			srpFilterSlider('srpRefineBedroomsSlider', 'reset');
446			srpFilterSlider('srpRefineBathroomsSlider', 'reset');
447		}
448	}
449
450	// SRP - Filters - Start Over Button in Filters Modal Footer
451	$('.srp-filters-modal-footer-clear').on('click', function () {
452		clearAllFilters();
453	});
454
455	// SRP - Filters - Header Sub Bar - Clear All X Button
456	$('.srp-header-filters-clear').on('click', function () {
457  	$(this).tooltip('hide');
458  	$(this).addClass('d-none');
459  	$('html').removeClass('modal-open');
460  	$('.srp-filters-modal').removeClass('open');
461  	clearDatepicker();
462  	clearAllFilters();
463  	srpSubmitForm();
464	});
465
466  if ($('#saveSearchForm').length) {
467		$('#saveSearchForm').validate({
468  		submitHandler: function(form){
469				var formString = $("#srpSubmitForm").serialize();
470				var formString = formString.replace('&srp_filters_modal_options_property_name=','');
471				var formString = formString.replace('&srp_filters_modal_options_property_number=','');
472				$('#searchURL').val(formString);
473  			$.ajax({
474  				type: "POST",
475  				url: siteFolder + 'ajax/saveSearch' + siteURLEnding,
476  				data: $('form#saveSearchForm').serialize(),
477  				dataType: "text",
478          beforeSend: function(){
479          },
480  				success: function (response) {
481  					response = $.trim(response);
482						$('#searchName').val('');
483						closeModal();
484						$.fn.beToast({
485							icon: 'exclamation-circle-solid',
486							iconColor: 'site-color-1',
487							title: 'Notifcation Set!',
488							body: 'Your search has been saved to your account.',
489							delay: 7000
490						});
491  				}
492  			});
493  			return false;
494  		}
495  	});
496  }
497
498  // SRP - No Results Inquiry Form
499	if ($('.results-inquiry-form-wrap').length ) {
500    $('.results-inquiry-form-wrap .selectpicker').selectpicker();
501    $('.results-inquiry-form-wrap .datepicker').datepicker();
502  }
503
504	// SRP - Infinite Scroll Ajax Results
505	var isLoading = false;
506	var scrollArea = $(window);
507	$(scrollArea).on('scroll', function (e) {
508		var form = $('#scrollForm');
509		var currentPage = parseInt(form.find('[name=page]').val());
510		var bottomResult = $('#bottomOfResults');
511		var position = bottomResult.position().top;
512		var scllwidth = $(scrollArea).scrollTop() + $(scrollArea).height();
513		if (scllwidth > position) {
514			var totalRecord = parseInt(bottomResult.attr('data-count'));
515			var totalPage = $('.srp-results-wrap [name^=page][name$=propertyIDs]').length;
516      if (currentPage < totalPage && !isLoading) {
517  			if (!$('.srp-results-wrap + .be-loading').length) {
518  				bottomResult.before(beLoading);
519  			}
520  			var newpage = currentPage + 1;
521        form.find('[name=page]').val(newpage);
522        form.find('[name=propertyIDs]').val($('#page' + newpage + 'propertyIDs').val());
523				if (!isLoading) {
524					isLoading = true;
525    			$.ajax({
526    				type: 'POST',
527    				url: siteFolder + 'ajax/results/scroll' + siteURLEnding,
528    				data: form.serialize(),
529    				success: function (data) {
530  						setTimeout(function () {
531  							isLoading = false;
532  							// Remove Loading Bar
533  							$('.srp-results-wrap + .be-loading').remove();
534  							// Append new results
535  							$('.srp-results-wrap .srp-results').append(data);
536  							// Reinitilize slider for newly appended results
537  							bePropWidgetSlider();
538  							//console.log('This is from the infinite scroll ajax');
539  						}, 400);
540    				}
541    			});
542    		}
543  		}
544		}
545	});
546
547});

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.