PageSourceSearch

https://www.dilworthlaw.com/wp-content/themes/paperstreet/js/lazySearch.js?ver=3.537

js dilworthlaw.com collected 2026-09-24 22:50:48 UTC 4,244 bytes, 130 lines download raw bytes

1/** @format */
2
3//Wrap all custom JS in an anonymous function that passes the alias "$" to everything so that "jQuery" doesn't have to be used
4(function ($) {
5	//Global variables
6	var firstPopOpened = false;
7	var searchCanStart = true;
8	var timeBetweenSearchTriggerMs = 100;
9	var searchCanTrigger = true;
10
11	//Document Ready = DOM is ready but content is not necessarily loaded
12	$(document).ready(function () {
13		console.log('Lazy search functionality ready7.');
14
15		//Prevent form "Enter" keypresses from opening additional filters
16		$('#attorney-search-input-name').on('keypress', function (e) {
17			if (e.keyCode == 13) {
18				e.preventDefault();
19				triggerAttorneyFormSearch();
20			}
21		});
22
23		//Open additional search filters box
24		$('#attorney-search-form-expand-button').on('click', function (e) {
25			e.preventDefault();
26			$('#attorney-search-form-expanded').toggleActive();
27			$(this).toggleActive();
28		});
29
30		//Corner close button to hide search filters box
31		$('#attorney-search-form-expanded-close').on('click', function (e) {
32			e.preventDefault();
33			$('#attorney-search-form-expanded').removeActive();
34		});
35
36		//Dynamic sort functionality with JS
37		$('.main-attorney-search').on('change', '#attorney-sort-selector', function () {
38			var attorneySortType = $('#attorney-sort-selector').val();
39
40			console.log('sort type is ' + attorneySortType);
41
42			if (attorneySortType == 'alpha-asc') {
43				$('#attorney-results').sortItems('a', 'last-name', false);
44			} else if (attorneySortType == 'alpha-desc') {
45				$('#attorney-results').sortItems('a', 'last-name', true);
46			}
47		});
48
49		//Letter buttons - desktop
50		$('button.attorney-search-letters-single').on('click', function () {
51			$('#attorney-hidden-letter').val($(this).data('letter'));
52			triggerAttorneyFormSearch();
53		});
54
55		$('#attorney-letter-selector').on('change', function () {
56			var letterSelection = $('#attorney-letter-selector option:selected').attr('data-letter');
57			$('#attorney-hidden-letter').val(letterSelection);
58		});
59
60		//Extra buttons in select pops - close and reset
61		$('.main-attorney-search').on('click', '#attorney-search-clear', function () {
62			document.getElementById('attorney-search-form-ajax').reset();
63			$('#attorney-search-form-ajax input, #attorney-search-form-ajax select').removeActive();
64			triggerAttorneyFormSearch();
65		});
66
67		//Trigger attorney search on any select dropdown changes
68		$('#attorney-search-form-ajax select').on('change', function () {
69			triggerAttorneyFormSearch();
70		});
71	});
72
73	//Initiates a attorney search, possibly with gates/conditions
74	function triggerAttorneyFormSearch() {
75		$('#attorney-search-form-ajax').trigger('submit');
76	}
77
78	//Temporarily prevents attorney search trigger
79	function disableAttorneySearch() {
80		searchCanStart = false;
81		setTimeout(enableAttorneySearch, timeBetweenSearchTriggerMs);
82	}
83
84	//Re-flags search as triggerable
85	function enableAttorneySearch() {
86		searchCanStart = true;
87		console.log('Lazy search can trigger again');
88	}
89
90	$('#attorney-search-form-ajax').on('submit', function (e) {
91		e.preventDefault();
92
93		if (searchCanStart == false) {
94			return;
95		} else {
96			console.log('AJAX search form submit...');
97
98			$('#attorney-search-inner').addClass('search-running');
99			disableAttorneySearch();
100		}
101
102		var formSubmitActionURL = $(this).attr('data-ajax-action'); //Points to file handling AJAX request
103		var submittedFormData = $(this).serializeArray();
104		var submittedFormDataProcessed = Array();
105
106		//Prep the data for the web server
107		submittedFormData.forEach(function (row) {
108			submittedFormDataProcessed[row.name] = row.value;
109		});
110
111		submittedFormDataProcessed = Object.assign({}, submittedFormDataProcessed);
112
113		jQuery.ajax({
114			url: formSubmitActionURL,
115			type: 'POST',
116			data: {
117				action: 'attorneys_search_change', //PHP hears this action and responds
118				attorneysSearchData: submittedFormDataProcessed
119			},
120			success: function (response) {
121				console.log('teest');
122				$('#attorney-search-inner').replaceWith(response).removeClass('search-running');
123				$('body').addClass('search-results-displayed');
124				$('#main').attr('tabindex', '-1').focus().removeAttr('tabindex');
125			}
126		});
127
128		$('#attorney-results').sortItems('a', 'last-name', false);
129	});
130})(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.