PageSourceSearch

https://www.akersellis.com/mlsEngine/javascripts/srp/z_srp.js?v=76

js akersellis.com collected 2026-10-09 23:41:26 UTC 20,399 bytes, 560 lines download raw bytes

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

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.