PageSourceSearch

https://pocahontascountywv.com/wp-content/themes/nmp/js/scripts.js?ver=48780964

js pocahontascountywv.com collected 2026-09-24 21:00:17 UTC 12,163 bytes, 371 lines download raw bytes

1// Lazyload background images
2// Requires the LazySizes library, which should be loaded in functions.php
3
4
5// 
6// document.addEventListener('lazybeforeunveil', function(e){
7// 	
8//     var bg = e.target.getAttribute('data-bg');
9//     if(bg){
10//         e.target.style.backgroundImage = 'url(' + bg + ')';
11//     }
12//     
13//     var loader = e.target.getAttribute('data-load');
14//     if(loader){
15// 		var request = new XMLHttpRequest();
16// 		request.open('GET', loader, true);
17// 		
18// 		request.onload = function() {
19// 		  if (this.status >= 200 && this.status < 400) {
20// 		    // Success!
21// 		    e.target.innerHTML = this.response;
22// 		  } else {
23// 		    // We reached our target server, but it returned an error
24// 		  }
25// 		};
26// 		
27// 		request.onerror = function() {
28// 		  // There was a connection error of some sort
29// 		};
30// 		
31// 		request.send();        
32//     }  
33//   
34//     var fa = e.target.getAttribute('data-fa');
35//     if(fa){
36// 		var request = new XMLHttpRequest();
37// 		request.open('GET', '/wp-content/themes/nmp/img/svg/'+fa+".svg", true);
38// 		
39// 		request.onload = function() {
40// 		  if (this.status >= 200 && this.status < 400) {
41// 		    // Success!
42// 		    e.target.innerHTML = this.response;
43// 		    //console.log(this.response);
44// 		    var callback = e.target.getAttribute("callback");
45// 		    if(callback){
46// 			    window[callback].call();
47// 		    }
48// 		  } else {
49// 		    // We reached our target server, but it returned an error
50// 		  }
51// 		};
52// 		
53// 		request.onerror = function() {
54// 		  // There was a connection error of some sort
55// 		};
56// 		
57// 		request.send();        
58//     }      
59// 
60// });	
61
62
63var htmlElement = document.getElementsByTagName("html");	
64htmlElement[0].classList.toggle("no-js");
65htmlElement[0].classList.toggle("js");
66
67
68$(document).ready(async function(){
69	
70
71	
72	htmlElement[0].classList.toggle("jquery");
73	
74	$(".cell__toggle button").click(function(e){
75		// console.log(1);
76		htmlElement[0].classList.toggle("mobile-menu-open");	
77	});
78	
79	var listingBody = $('.listing-body');
80	
81	// var listingSectionToggles = $(".listing-body section .toggle");
82	// listingSectionToggles.click(function(e){
83	listingBody.on('click', 'section .toggle', function(e){
84		$(this).parent().parent().parent().toggleClass("closed");
85	});
86	
87	var srchInput = $(".nmp-listings .srch");
88	
89	var orderSelect = $(".nmp-listings .orderby");
90	orderSelect.change(function(e){
91		var order = $(this).val();
92		window.listings.reverse();					
93		window.printToBlock();
94	});
95	
96	var dataBG = $("*[data-bg]").not(".lazyload");
97	dataBG.each(function(e){
98		var bg = $(this).attr('data-bg');
99		if(bg){
100			$(this).css("background-image",'url(' + bg + ')');
101		}		
102	});
103	
104	if(listingBody.length > 0){
105		if(window.present.length <= 3){
106			$(".button.more").addClass("hidden");
107			$(".nmp-listings .all").hide();
108		}		
109	}
110
111	
112	var orderSelect = $(".nmp-listings .srch");
113	window.searching = false;
114	orderSelect.keyup(function(e){
115		
116		var order = $(this).val().toUpperCase();
117
118		if(!window.searching && order.length > 2){
119			
120			// var order = $(this).val().toUpperCase();
121			
122			window.searching = true;
123			
124			for (var i in window.listings) {
125				window.listings[i].hidden = false;
126			}				
127			
128			for (var i in window.listings) {
129				var searchText = JSON.stringify(window.listings[i]).toUpperCase()
130				// console.log(searchText);
131				if(searchText.indexOf(order) == -1){
132					window.listings[i].hidden = true;
133				}
134			}
135			
136			$(".button.more").addClass("hidden");
137			
138			window.printToBlock();
139			
140		}
141		
142		if(order.length==0){
143			for (var i in window.listings) {
144				window.listings[i].hidden = false;
145			}	
146			$(".button.more").removeClass("hidden");
147			window.paging = 5;		
148			window.printToBlock();
149		}
150		
151	});	
152		
153	var listingsLoadMore = $(".nmp-listings .button.more");
154	var listingsLoadAll = $(".nmp-listings .all");
155	var listingGroup = $(".listing-body");
156	window.paging = 5;
157	
158	listingsLoadAll.click(function(e){
159		
160		e.preventDefault();
161		
162		listingGroup.empty();
163		window.present = [];
164		
165		var newHTML = "";
166		
167		for (var i in window.listings) {			
168			newHTML += '<section data-id="'+window.listings[i].ID+'" class="closed"><div class="grid"><a href="'+window.listings[i].link+'"><div class="thumb" style="background-image:url('+window.listings[i].img+');"></div></a><div class="copy"><a href="'+window.listings[i].link+'"><span class="city">'+window.listings[i].m.city[0]+', WV</span><h4>'+window.listings[i].post_title+'</h4></a><span class="toggle">See Description</span>
168<p class="exc pn">'+window.listings[i].excerpt+'…</p></div></div><p class="exc tgl">'+window.listings[i].excerpt+'…</p></section>';							
169			window.present.push(window.listings[i].ID);
170		}
171		
172		listingGroup.append(newHTML);
173		
174		$(".button.more").addClass("hidden");
175		$(".nmp-listings .all").hide();
176			
177	});
178	
179	listingsLoadMore.click(function(e){
180	
181		// console.log("pressed");
182		e.preventDefault();
183		
184		var count = 0;
185		
186		var newHTML = "";
187		
188		for (var i in window.listings) {
189			
190			// Make sure we're not dealing with a listing that is already visible 
191			if( window.present.indexOf(window.listings[i].ID) == -1 && count < 4 ){
192		
193				newHTML += '<section data-id="'+window.listings[i].ID+'" class="closed"><div class="grid"><a href="'+window.listings[i].link+'"><div class="thumb" style="background-image:url('+window.listings[i].img+');"></div></a><div class="copy"><a href="'+window.listings[i].link+'"><span class="city">'+window.listings[i].m.city[0]+', WV</span><h4>'+window.listings[i].post_title+'</h4></a><span class="toggle">See Description</span><p class="exc pn">'+window.listings[i].excerpt+'…</p></div></div><p class="exc tgl">'+window.listings[i].excerpt+'…</p></section>';	
194						
195				window.present.push(window.listings[i].ID);
196				count++;
197				
198			}
199		}
200		
201		listingGroup.append(newHTML);
202		
203		if(window.present.length === window.listings.length){
204			$(".button.more").addClass("hidden");
205			$(".nmp-listings .all").hide();
206		}
207	
208		
209	});	
210	
211	window.printToBlock = function(){
212		listingGroup.empty();
213		window.present = [];
214		
215		var count = 0;
216		var newHTML = "";
217		
218		for (var i in window.listings) {
219			
220			// Make sure we're not dealing with a listing that is already visible 
221			if( !window.listings[i].hidden && window.present.indexOf(window.listings[i].ID) == -1 && count < window.paging){
222				
223				newHTML += '<section data-tags="'+window.listings[i].comma_separated_tagnames+'" data-id="'+window.listings[i].ID+'" class="closed"><div class="grid"><a href="'+window.listings[i].link+'"><div class="thumb" style="background-image:url('+window.listings[i].img+');"></div></a><div class="copy"><a href="'+window.listings[i].link+'"><span class="city">'+window.listings[i].m.city[0]+', WV</span><h4>'+window.listings[i].post_title+'</h4></a><span class="toggle">See Description</span><p class="exc pn">'+window.listings[i].excerpt+'…</p>';
224				
225				//Insert badges
226				// console.log(window.listings[i].m.pet_friendly[0]);
227				// console.log(window.listings[i].m.mountain_bike_friendly[0]);
228				// console.log(window.listings[i].m.accessible[0]);
229				
230				newHTML += '<div class="features">';
231				
232				console.log(window.listings[i]);
233				
234					if(window.listings[i].pet_friendly == 1){
235						newHTML += '<div title="This location is pet friendly" aria-label="This location is pet friendly" class="badge badge__pet"><i data-fa="paw-solid" class="lazyload"></i><span>Pet Friendly</span></div>';
236					}
237						
238					if(window.listings[i].mtb == 1){
239						newHTML += '<div title="This location is mountain bike friendly" aria-label="This location is mountain bike friendly" class="badge badge__pet"><i data-fa="biking-mountain-solid" class="lazyload"></i><span>Mountain Bike Friendly</span></div>';
240					}	
241					
242					if(window.listings[i].accessible == 1){
243						newHTML += '<div title="This location is wheelchair accessible" aria-label="This location is wheelchair accessible" class="badge badge__pet"><i data-fa="wheelchair-regular" class="lazyload"></i><span>Handicap Accessible</span></div>';
244					}					
245				
246				newHTML += '</div>';			
247				
248				newHTML += '</div></div><div class="tgl"><p class="exc">'+window.listings[i].excerpt+'…</p>';
249				
250				//Insert badges
251				newHTML += '<div class="features">';
252				
253					if(window.listings[i].pet_friendly == 1){
254						newHTML += '<div title="This location is pet friendly" aria-label="This location is pet friendly" class="badge badge__pet"><i data-fa="paw-solid" class="lazyload"></i><span>Pet Friendly</span></div>';
255					}
256						
257					if(window.listings[i].mtb == 1){
258						newHTML += '<div title="This location is mountain bike friendly" aria-label="This location is mountain bike friendly" class="badge badge__pet"><i data-fa="biking-mountain-solid" class="lazyload"></i><span>Mountain Bike Friendly</span></div>';
259					}	
260					
261					if(window.listings[i].accessible == 1){
262						newHTML += '<div title="This location is wheelchair accessible" aria-label="This location is wheelchair accessible" class="badge badge__pet"><i data-fa="wheelchair-regular" class="lazyload"></i><span>Handicap Accessible</span></div>';
263					}		
264				
265				newHTML += '</div></div>';					
266				
267				newHTML += '</section>';				
268				window.present.push(window.listings[i].ID);
269				count++;				
270			}
271		}
272		
273		listingGroup.append(newHTML);
274		
275		if(window.present.length === window.listings.length){
276			$(".button.more").addClass("hidden");
277			$(".nmp-listings .all").hide();
278		}	
279		
280		window.searching = false;	
281		
282		var listingSectionToggles = $(".listing-body section .toggle");
283		listingSectionToggles.on('click', function(e){
284			$(this).parent().parent().parent().toggleClass("closed");
285		});		
286		
287	}
288
289	// Check the url to see if /thanks/ is in the url, then go into something to check the url params
290	if(window.location.href.indexOf("/thanks/") > -1){
291		var params = new URLSearchParams(window.location.search);
292		if(params.has('email')){
293			var email = params.get('email');
294			// Hash using SHA-256
295			email = await sha256(email);
296		}
297		if(params.has('fname')){
298			var fname = params.get('fname');
299			fname = await sha256(fname);
300		}
301		if(params.has('lname')){
302			var lname = params.get('lname');
303			lname = await sha256(lname);
304		}
305		if(params.has('phone')){
306			var phone = params.get('phone');
307			phone = await sha256(phone);
308		}
309		if(params.has('city')){
310			var city = params.get('city');
311			city = await sha256(city);
312		}
313		if(params.has('zip')){
314			var zip = params.get('zip');
315			zip = await sha256(zip);
316		}
317		if(params.has('state')){
318			var state = params.get('state');
319			state = await sha256(state);
320		}
321		var country = "US"; // Default country, can be changed if needed
322		country = await sha256(country);
323		// Push to data layer
324		window.dataLayer = window.dataLayer || [];
325		window.dataLayer.push({
326			// event: 'formSubmission',
327			email: email || '',
328			fname: fname || '',
329			lname: lname || '',
330			phone: phone || '',
331			city: city || '',
332			zip: zip || '',
333			state: state || '',
334			country: country || ''
335		});
336	}
337	
338	if(window.location.href.indexOf("/newsletter/") > -1){
339		var emailInput = document.getElementById("EMAIL");
340		// If there is changes to the email input, hash it and push to dataLayer
341		if(emailInput){
342			emailInput.addEventListener('change', async function(e){
343				var email = emailInput.value;
344				// Hash using SHA-256
345				email = await sha256(email);
346				// add it as a cookie that expires in 30 days
347				document.cookie = "brevoEmail=" + email + "; path=/; max-age=" + (30 * 24 * 60 * 60) + ";"; // 30 days
348			});
349		}
350	}
351});
352
353async function sha256(message) {
354    // encode as UTF-8
355    const msgBuffer = new TextEncoder().encode(message);                    
356
357    // hash the message
358    const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
359
360    // convert ArrayBuffer to Array
361    const hashArray = Array.from(new Uint8Array(hashBuffer));
362
363    // convert bytes to hex string                  
364    const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
365    return hashHex;
366}
367
368
369var observer = lozad(); // lazy loads elements with default selector as '.lozad'
370observer.observe();
371

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.