PageSourceSearch

https://www.cmhc.org/wp-content/plugins/cmh-organizations-plugin-m…/plugin-organizations-public.js?ver=1.0.0

js cmhc.org collected 2026-09-26 06:58:12 UTC 10,950 bytes, 361 lines download raw bytes

1(function ($) {
2	'use strict';
3
4	/**
5	 * All of the code for your public-facing JavaScript source
6	 * should reside in this file.
7	 *
8	 * Note: It has been assumed you will write jQuery code here, so the
9	 * $ function reference has been prepared for usage within the scope
10	 * of this function.
11	 *
12	 * This enables you to define handlers, for when the DOM is ready:
13	 *
14	 * $(function() {
15	 *
16	 * });
17	 *
18	 * When the window is loaded:
19	 *
20	 * $( window ).load(function() {
21	 *
22	 * });
23	 *
24	 * ...and/or other possibilities.
25	 *
26	 * Ideally, it is not considered best practise to attach more than a
27	 * single DOM-ready or window-load handler for a particular page.
28	 * Although scripts in the WordPress core, Plugins and Themes may be
29	 * practising this, we should strive to set a better example in our own work.
30	 */
31
32	var canLoadMore = false;
33	$(function () {
34
35		/**
36		 * Autocomplete Organization Name
37		 * */
38		$("#cmh_organization_name").autocomplete({
39			minLength: 3,
40			source: function (request, response) {
41				$.ajax({
42					type: "POST",
43					url: cmh_organizations_ajax.url,
44					dataType: 'json',
45					data: {
46						action: "ajaxSearchOrganizationsByName",
47						nonce: cmh_organizations_ajax.nonce,
48						name: request.term
49					},
50					success: function (data) {
51
52						if (data.success == true) {
53							let organizations = [];
54							$.each(data.data, function (key, value) {
55								organizations.push({
56									slug: value.slug,
57									label: value.name,
58									image: value.image,
59								});
60							});
61							response(organizations);
62						}
63					},
64					error: function (jqXHR, textStatus, errorThrown) {}
65				});
66			},
67			select: function (event, ui) {
68				location.href = "/location/" + ui.item.slug;
69				return false;
70			},
71		});
72
73
74
75
76		if (document.getElementById('load-more-orgs-button') != null) {
77
78
79			document.getElementById('load-more-orgs-button').style.display = 'none';
80
81			$('#organization-search-button').on('click', function () {
82
83				var orgName = $("input[name='org-name']").val();
84				var orgLocation = $("input[name='org-location']").val();
85				var orgMiles = $("select[name='org-miles'] option:selected").val();
86				var orgSpecial = $("select[name='org-speciality'] option:selected").val();
87				var miles = 0;
88
89				if($.inArray(orgMiles, ["5", "10", "15", "25", "50", "75", "100", "200"]) !== -1) {
90					miles = orgMiles;
91				} else {
92					miles = 50;
93				}
94
95				let terms = {
96					org_name: orgName,
97					org_location: orgLocation,
98					org_radius: (orgLocation.length > 0) ? miles : 0,
99					org_special: orgSpecial,
100					org_page: 1,
101				}
102
103				$.ajax({
104					type: "POST",
105					url: cmh_organizations_ajax.url,
106					dataType: 'json',
107					data: {
108						action: "ajaxGetOrganizations",
109						nonce: cmh_organizations_ajax.nonce,
110						name: terms['org_name'],
111						location: terms['org_location'],
112						miles: terms['org_radius'],
113						speciality_type: terms['org_special'],
114						page_number: terms['org_page']
115					},
116					success: function (data) {
117						if (data.success == true) {
118							$('#organizations-results').empty();
119							let organizations = [];
120							$.each(data.data, function (key, value) {
121
122								let practiceHours = [];
123
124								$.each(value.hours.practice, function (day, time) {
125									if (time.open_at != null) {
126										practiceHours.push(time.open_at);
127									}
128
129								});
130
131								let walk_inHours = [];
132								$.each(value.hours.walk_in, function (day, time) {
133									if (time.open_at != null) {
134										walk_inHours.push(time.open_at);
135									}
136
137								});
138								document.getElementById('organizations-results').innerHTML += '<div class="col-md-4 col-6  search-result organization-result" itemprop="organization" itemscope itemtype="https://schema.org/Organization">' +
139
140									'<div class="card">' +
141
142
143
144									"<a  href ='/location/" + value.slug + "'>" +
145									((value.image !== null) ?
146										"<img class='thumbnail card-img-top' height='150' width='150' itemprop='image' src='" + value.image + "'>" : "<img class='image card-img-top' height='150' width='150' src='https://www.cmhc.org/wp-content/uploads/2026/02/cropped-logo-icon-central-maine-healthcare.png'>"
147									) +
148									"</a>" +
149
150
151									'<div class="card-body d-block">' +
152
153									"<a href ='/location/" + value.slug + "'>" +
154									"<div class='medium blue bold' itemprop='name'>" +
155									value.name +
156									"</div>" +
157									"</a>" +
158
159									"<div class='address-block' itemprop='postalAddress' itemscope itemtype='https://schema.org/PostalAddress'>" +
160
161									"<span class='small light grey lh-0' itemprop='streetAddress'>" + ((value.address_1 !== null) ? value.address_1 + ' ' : '') +
162
163									((value.address_2 !== null) ? value.address_2 + ' ' : '') + "</span><br>" +
164
165									"<span class='small light grey lh-0' itemprop='addressLocality'>" + ((value.city !== null) ? value.city + ', ' : '') + "</span>" +
166
167									"<span class='small light grey lh-0' itemprop='addressRegion'>" + ((value.state !== null) ? value.state + ' ' : '') + "</span>" +
168
169									"<span class='small light grey lh-0' itemprop='postalCode'>" + ((value.zip_code !== null) ? value.zip_code : '') + "</span>" +
170									"</div>" +
171									((value.phone !== null) ?
172										"<h6 >" +
173										"<a href='tel:" + value.phone + "' class='small light-blue mt-1 bold' itemprop='phone'>" + value.phone + "</a>" +
174										"</h6>" : ''
175									) +
176									'</div>' +
177									'</div>' +
178
179									'</div>';
180								organizations.push({
181									label: value.name,
182									id: value.id
183								});
184
185							});
186
187							if (organizations.length < 15) {
188								document.getElementById('load-more-orgs-button').style.display = 'none';
189							} else {
190								document.getElementById('load-more-orgs-button').style.display = 'block';
191							}
192
193
194							if (organizations.length < 1) {
195								document.getElementById('organizations-results').innerHTML = "<div class='alert alert-warning'> <p>There are no Locations for this search. Please broaden your search and try again</p>";
196								if (data.errors != null) {
197									for (i = 0; i < data.errors.location.length; i++) {
198										document.getElementById('providers-results').innerHTML += "<p>" + data.errors.location[i] + "</p>";
199									}
200								}
201								document.getElementById('organizations-results').innerHTML += "</div>"
202							}
203
204						} else {
205							alert("There was a problem with this request");
206						}
207					},
208					error: function (jqXHR, textStatus, errorThrown) {
209
210
211
212						alert('An error occurred with this request.');
213					}
214				});
215
216
217
218			});
219
220
221			$('#load-more-organizations').on('click', function () {
222
223
224				var orgName = $("input[name='org-name']").val();
225				var orgLocation = $("input[name='org-location']").val();
226				var orgMiles = $("select[name='org-miles'] option:selected").val();
227				var orgSpecial = $("select[name='org-speciality'] option:selected").val();
228				var miles = 0;
229				var currentResultsLength = document.getElementsByClassName('organization-result').length;
230				var pageMod = Math.ceil(currentResultsLength / 15);
231
232				if($.inArray(orgMiles, ["5", "10", "15", "25", "50", "75", "100", "200"]) !== -1) {
233					miles = orgMiles;
234				} else {
235					miles = 50;
236				}
237
238				let terms = {
239					org_name: orgName,
240					org_location: orgLocation,
241					org_radius: (orgLocation.length > 0) ? miles : 0,
242					org_special: orgSpecial,
243					org_page: pageMod + 1,
244				}
245
246				$.ajax({
247					type: "POST",
248					url: cmh_organizations_ajax.url,
249					dataType: 'json',
250					data: {
251						action: "ajaxGetOrganizations",
252						nonce: cmh_organizations_ajax.nonce,
253						name: terms['org_name'],
254						location: terms['org_location'],
255						miles: terms['org_radius'],
256						speciality_type: terms['org_special'],
257						page_number: terms['org_page'],
258					},
259					success: function (data) {
260						if (data.success == true) {
261
262							let organizations = [];
263							$.each(data.data, function (key, value) {
264								let practiceHours = [];
265
266								$.each(value.hours.practice, function (day, time) {
267									if (time.open_at != null) {
268										practiceHours.push(time.open_at);
269									}
270
271								});
272
273								let walk_inHours = [];
274								$.each(value.hours.walk_in, function (day, time) {
275									if (time.open_at != null) {
276										walk_inHours.push(time.open_at);
277									}
278
279								});
280								document.getElementById('organizations-results').innerHTML += '<div class="col-md-4 col-6  search-result organization-result" itemprop="organization" itemscope itemtype="https://schema.org/Organization">' +
281
282									'<div class="card">' +
283
284
285
286									"<a  href ='/location/" + value.slug + "'>" +
287									((value.image !== null) ?
288										"<img class='thumbnail card-img-top' height='150' width='150' itemprop='image' src='" + value.image + "'>" : "<img class='image card-img-top' height='150' width='150' src='https://www.cmhc.org/wp-content/uploads/2026/02/cropped-logo-icon-central-maine-healthcare.png'>"
289									) +
290									"</a>" +
291
292
293									'<div class="card-body d-block">' +
294
295									"<a href ='/location/" + value.slug + "'>" +
296									"<div class='medium blue bold' itemprop='name'>" +
297									value.name +
298									"</div>" +
299									"</a>" +
300
301									"<div class='address-block' itemprop='postalAddress' itemscope itemtype='https://schema.org/PostalAddress'>" +
302
303									"<span class='small light grey lh-0' itemprop='streetAddress'>" + ((value.address_1 !== null) ? value.address_1 + ' ' : '') +
304
305									((value.address_2 !== null) ? value.address_2 + ' ' : '') + "</span><br>" +
306
307									"<span class='small light grey lh-0 ' itemprop='addressLocality'>" + ((value.city !== null) ? value.city + ', ' : '') + "</span>" +
308
309									"<span class='small light grey lh-0' itemprop='addressRegion'>" + ((value.state !== null) ? value.state + ' ' : '') + "</span>" +
310
311									"<span class='small light grey lh-0' itemprop='postalCode'>" + ((value.zip_code !== null) ? value.zip_code : '') + "</span>" +
312									"</div>" +
313									((value.phone !== null) ?
314										"<h6 >" +
315										"<a href='tel:" + value.phone + "' class='small light-blue mt-1 bold' itemprop='phone'>" + value.phone + "</a>" +
316										"</h6>" : ''
317									) +
318									'</div>' +
319									'</div>' +
320
321									'</div>';
322								organizations.push({
323									label: value.name,
324									id: value.id
325								});
326							});
327
328
329
330							if (organizations.length < 15) {
331								document.getElementById('load-more-orgs-button').style.display = 'none';
332
333							}
334						} else {
335							alert("There was a problem with this request");
336						}
337					},
338					error: function (jqXHR, textStatus, errorThrown) {
339
340
341
342						alert('An error occurred with this request.');
343					}
344				});
345
346			});
347		}
348
349		$(document).ready(function () {
350			$('.bxslider').bxSlider({
351				auto: true,
352				autoControls: true,
353				stopAutoOnClick: true,
354				pager: true,
355				slideWidth: 600
356			  });
357		});
358
359	});
360
361})(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.