PageSourceSearch

https://www.rhconst.com/wp-content/plugins/portfolio-filters/portfolio.js?ver=1

js rhconst.com collected 2026-10-04 03:53:53 UTC 18,532 bytes, 598 lines download raw bytes

1$ = jQuery;
2
3var perPage = 20;
4var loadMoreTrigger = false;
5var totalPosts;
6var postType;
7var teamPage = 1;
8
9$(document).on('ready', function () {
10	//attach event listener to filters
11	filterSelection();
12
13	if ($('#leadership, #operations').length > 0) {
14		infoBoxes();
15		squareLeaders();
16
17		tileClick();
18	}
19
20	if ($('section[data-post_type="posts"]')) {
21		squareNews();
22	}
23
24
25
26	let selectedLocation = getUrlParameter('loc');
27	let selectedType = getUrlParameter('type');
28	let selectedSector = getUrlParameter('sector');
29	let initSearch = getUrlParameter('search');
30
31
32	if (selectedLocation) {
33		selectedLocation = selectedLocation.toUpperCase();
34		jQuery('ul[data-filter="office"] div li').each(function () {
35			let thisContent = jQuery(this).html();
36			if (thisContent.toUpperCase() === selectedLocation.toUpperCase()) {
37				jQuery(this).click();
38			} else if (thisContent.toLowerCase().includes(selectedLocation.toLowerCase())) {
39				jQuery(this).click();
40			}
41
42		});
43	}
44	if (selectedType) {
45		selectedType = selectedType.toUpperCase();
46		jQuery('ul[data-filter="1_project_type"] div li').each(function () {
47			let thisContent = jQuery(this).html();
48			thisContent = thisContent.replace(/[^\w\s]/gi, '');
49			//console.log(thisContent);		
50			if (thisContent.toUpperCase() === selectedType.toUpperCase()) {
51				jQuery(this).click();
52			} else if (thisContent.toLowerCase().includes(selectedType.toLowerCase())) {
53				jQuery(this).click();
54			}
55
56		});
57	}
58	if (selectedSector) {
59		selectedSector = selectedSector.toUpperCase();
60		jQuery('ul[data-filter="0_market_sector"] div li').each(function () {
61			let thisContent = jQuery(this).html();
62			thisContent = thisContent.replace(/[^\w\s]/gi, '');
63			if (thisContent.toUpperCase() === selectedSector.toUpperCase()) {
64				jQuery(this).click();
65			} else if (thisContent.toLowerCase().includes(selectedSector.toLowerCase())) {
66				jQuery(this).click();
67			}
68
69		});
70	}
71
72	if (!selectedLocation && !selectedType && !selectedSector && !initSearch) {
73		updatePortfolio();
74	}
75
76
77	if ($('#portfolio').attr('data-post_type') == 'team_member') {
78
79		$(window).on('scroll', function () {
80			let scrollTarget = $('#portfolio').offset().top + $('#portfolio').height() - $(window).height();
81
82			if (jQuery(window).scrollTop() >= scrollTarget) {
83				loadMore();
84			}
85
86		});
87	}
88	postType = $('#portfolio').attr('data-post_type');
89
90	if ($('#search').length) {
91		//reset search input on page load
92		$('#search').val('');
93
94		//search functionality has a slight delay to it
95		$('#search').keyup(typeDelay(function () {
96			// console.log($('#search').val());
97			let theQuery = $('#search').val();
98			//if(theQuery.length > 2 || theQuery.length === 0){
99			teamPage = 1;
100			$('#portfolio-filter ul').each(function () {
101				$(this).removeAttr('data-selected');
102			});
103			$('.selected-filter').removeClass('selected-filter');
104			$('.active-filter').each(function () {
105				$(this).html($(this).attr('data-default'));
106			});
107			$('#portfolio').html('');
108			updatePortfolio();
109			//}
110		}, 500));
111
112		if (initSearch) {
113			$('#search').val(initSearch);
114			$('#portfolio').html('');
115			updatePortfolio();
116		}
117	}
118});
119
120$(window).on('resize', function () {
121	if ($('#leadership, #operations').length > 0) {
122		squareLeaders();
123		infoBoxes();
124	} else {
125		// normalizeHeight('.portfolio-tile .titles');
126		if (jQuery(window).width() > 800) {
127			sizeTiles();
128
129			//infoBoxes();
130		}
131		if ($('section[data-post_type="posts"]')) {
132			squareNews();
133		}
134	}
135});
136
137function typeDelay(fn, ms) {
138	let timer = 0
139	return function (args) {
140		clearTimeout(timer)
141		timer = setTimeout(fn.bind(this, args), ms || 0)
142	}
143}
144
145function clearInfoboxes() {
146	$('.infobox').html('');
147	$('.open').removeClass('open');
148	//console.log('clearInfoboxes');
149	$('body').removeClass('infobox-open');
150}
151
152function tileClick() {
153	$('.leadership-tile, .operations-tile').each(function () {
154		$(this).on('click', function () {
155			if ($(this).hasClass('open')) {
156				clearInfoboxes();
157			} else {
158				infobox = $(this).parents('.tile-container').nextAll('.infobox')[0];
159				clearInfoboxes();
160				infobox_content = $(this).find('.infobox-content').html();
161				$(this).addClass('open');
162				$(infobox).addClass('open');
163				$('body').addClass('infobox-open');
164				$(infobox).html(infobox_content);
165			}
166		})
167	})
168}
169
170
171//normalize size of portfolio items
172function sizeTiles() {
173	var slug = $('#portfolio').attr('data-post_type');
174	var rowWidth = $('#portfolio.row').width();
175	if (slug !== 'posts') {
176		if (slug === 'projects') {
177			$('.portfolio-tile').each(function () {
178				$(this).height(Math.ceil(rowWidth / 4 * 0.895));
179			});
180		} else {
181			$('.portfolio-tile').each(function () {
182				$(this).height(rowWidth / 4 + 25);
183			});
184		}
185	}
186}
187
188function getLocationName(taxId) {
189	output = 0;
190	$('[data-default="Office"] + div > li').each(function () {
191		if (jQuery(this).attr('data-value') == taxId) output = jQuery(this).html();
192	});
193	return output;
194}
195
196//get infobox content (dependent on post type, styling, etc)
197function getInfobox(portfolio) {
198	infobox_stored_content = '';
199	// WARNING: Team Member post type doesn't use excerpts
200	if (portfolio['type'] === "team_member") {
201
202		infobox_stored_content += '<div>' + portfolio['acf_fields']['leadership_bio'] + '</div>';
203	} else if (portfolio['type'] === "projects") {
204
205		infobox_stored_content += '<h3>' + portfolio['title']['rendered'] + '</h3>';
206		infobox_stored_content += portfolio['project_location']; //getLocationName(portfolio['office'][0])+'</p>';
207		if (portfolio['excerpt']['rendered']) {
208			infobox_stored_content += '<span class="max-excerpt">' + portfolio['excerpt']['rendered'] + '</span>';
209		} else {
210			infobox_stored_content += '<span class="max-excerpt">' + portfolio['filtered_excerpt'] + '</span>';
211		}
212		infobox_stored_content += '<a href="' + portfolio['link'] + '" class="fusion-button fusion-button-default fusion-button-square fusion-button-flat">View Project</a>';
213	}
214
215	return infobox_stored_content;
216}
217
218//build individual portfolio tiles
219function createTile(portfolio) {
220	linkedID = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
221	if (portfolio['type'] === 'projects') {
222		var tile = '<div href="' + portfolio['link'] + '" class="col-sm-3 portfolio-tile portfolio-' + portfolio['id'] + '" data-content="' + linkedID + '">';
223		tile += '<div class="tile-bg"';
224
225		if (portfolio['featured_image_src'].indexOf('/wp-content/plugins/portfolio-filters/assets/default.jpg') === -1) {
226			tile += ' style="background-image:url(' + portfolio['featured_image_src'] + ')"></div>';
227		} else {
228			//change for project
229			tile += ' style="background-image:url(/wp-content/plugins/portfolio-filters/assets/default.jpg)"></div>';
230		}
231
232		tile += '<div class="tile-overlay"><h4>' + portfolio['title']['rendered'] + '</h4></div>';
233
234		infobox_rendered_content = getInfobox(portfolio);
235		tile += '<div class="hidden infobox-content" id="' + linkedID + '">' + infobox_rendered_content + '</div>';
236		tile += '</div>';
237	} //projects
238	else if (portfolio['type'] === 'post') {
239		var tile = '<a href="' + portfolio['link'] + '" class="col-sm-3 portfolio-tile news portfolio-' + portfolio['id'] + '"';
240		tile += ' data-content="' + linkedID + '"';
241		tile += '>';
242		tile += '<div class="tile-bg"';
243		if (portfolio['featured_image_src'].indexOf('/wp-includes/images/media/default.svg') === -1) {
244			if (portfolio['acf_fields']['grid_image'].length > 1) {
245				photo = portfolio['acf_fields']['grid_image'];
246			} else {
247				photo = portfolio['featured_image_src'];
248			}
249			tile += ' style="background-image:url(' + photo + ')"></div>';
250		} else {
251			//change for project
252			tile += ' style="background-image:url(/wp-content/plugins/portfolio-filters/assets/default.jpg)"></div>';
253		}
254		if (portfolio['type'] !== "wrvi_portfolio") {
255			tile += '<div class="tile-overlay"><h4>' + portfolio['title']['rendered'] + '</h4>';
256			// if(portfolio['acf_fields']['years']) tile += '<p class="title"><strong>'+portfolio['acf_fields']['title']+'</strong>';
257			// if(portfolio['acf_fields']['start_date']) {
258			// 	tile += '<p><strong>'+portfolio['acf_fields']['start_date']+'</strong></p>';
259			// } else {
260			// 	tile += '</p>';
261			// }
262			tile += '</div>';
263		}
264		infobox_rendered_content = getInfobox(portfolio);
265		tile += '<div class="hidden infobox-content" id="' + linkedID + '">' + infobox_rendered_content + '</div>';
266		tile += '</div>';
267	}//projects
268	else if (portfolio['type'] === 'team_member') {
269		console.log('testing')
270		var tile = '<div class="col-sm-3 portfolio-tile portfolio-' + portfolio['id'] + '"';
271		tile += ' data-content="' + linkedID + '"';
272		tile += '>';
273		tile += '<div class="tile-bg"';
274		if (portfolio['featured_image_src'].indexOf('/wp-content/plugins/portfolio-filters/assets/default-team.jpg') === -1) {
275			tile += ' style="background-image:url(' + portfolio['featured_image_src'] + ')"></div>';
276		} else {
277
278			tile += ' style="background-image:url(/wp-content/plugins/portfolio-filters/assets/default-team.jpg)"></div>';
279		}
280		if (portfolio['type'] !== "wrvi_portfolio") {
281			// console.log(portfolio['acf_fields']['start_date']);
282			tile += '<div class="tile-overlay"><h4>' + portfolio['title']['rendered'] + '</h4>';
283			tile += '<p class="title"><strong>' + portfolio['acf_fields']['title'] + '</strong>';
284			if (portfolio['acf_fields']['start_date']) {
285				tile += '<p><strong>' + portfolio['acf_fields']['start_date'] + '</strong></p>';
286			} else {
287				tile += '</p>';
288			}
289			tile += '</div>';
290		}
291		infobox_rendered_content = getInfobox(portfolio);
292		tile += '<div class="hidden infobox-content" id="' + linkedID + '">' + infobox_rendered_content + '</div>';
293		tile += '</div>';
294	}
295	else {
296
297		var tile = '<div class="col-sm-3 portfolio-tile portfolio-' + portfolio['id'] + '"';
298		tile += ' data-content="' + linkedID + '"';
299		tile += '>';
300		tile += '<div class="tile-bg"';
301		if (portfolio['featured_image_src'].indexOf('/wp-content/plugins/portfolio-filters/assets/default.jpg') === -1) {
302			tile += ' style="background-image:url(' + portfolio['featured_image_src'] + ')"></div>';
303		} else {
304
305			tile += ' style="background-image:url(/wp-content/plugins/portfolio-filters/assets/default.jpg)"></div>';
306		}
307		if (portfolio['type'] !== "wrvi_portfolio") {
308			// console.log(portfolio['acf_fields']['start_date']);
309			tile += '<div class="tile-overlay"><h4>' + portfolio['title']['rendered'] + '</h4>';
310			tile += '<p class="title"><strong>' + portfolio['acf_fields']['title'] + '</strong>';
311			if (portfolio['acf_fields']['start_date']) {
312				tile += '<p><strong>' + portfolio['acf_fields']['start_date'] + '</strong></p>';
313			} else {
314				tile += '</p>';
315			}
316			tile += '</div>';
317		}
318		infobox_rendered_content = getInfobox(portfolio);
319		tile += '<div class="hidden infobox-content" id="' + linkedID + '">' + infobox_rendered_content + '</div>';
320		tile += '</div>';
321	} // not default post type 
322	return tile;
323}
324
325
326
327//add infobox receptacles to every row
328function infoBoxes() {
329	$('.infobox').remove();
330	$('.open').removeClass('open');
331
332	var breakpoint = $(window).width();
333	var infoboxHTML = '<div class="col-sm-12 infobox"></div>';
334
335	if (breakpoint <= 785) {
336		$('#leadership .tile-container, #operations .tile-container').after(infoboxHTML);
337	} else if (breakpoint <= 991) {
338		$('#leadership .tile-container:nth-of-type(2n-0), #operations .tile-container:nth-of-type(2n-0)').after(infoboxHTML);
339	} else {
340		$('#leadership .tile-container:nth-of-type(3n-0), #operations .tile-container:nth-of-type(3n-0)').after(infoboxHTML);
341	}
342	$('#leadership, #operations').append('<div class="col-xs-12 infobox"></div>');
343
344	squareLeaders();
345	return true;
346}
347
348function squareLeaders() {
349	$('#leadership .tile-container, .leadership-tile, #operations .tile-container, .operations-tile').height($('#leadership .tile-container, #operations .tile-container').width());
350	$('#leadership, #operations').css('opacity', 1);
351}
352
353function squareNews() {
354	$('#portfolio .col-sm-3.news').height($('#portfolio .col-sm-3').width());
355	$('#portfolio .col-sm-3.news').css('opacity', 1);
356}
357
358function updatePortfolio() {
359	filters = $('#portfolio-filter ul');
360	args = [];
361	for (var i = filters.length - 1; i >= 0; i--) {
362		filtername = $(filters[i]).attr('data-filter');
363		// console.log(filtername)
364		filtervalue = $(filters[i]).attr('data-selected');
365		args[filtername] = filtervalue;
366	}
367	if (postType == 'team_member') {
368		args['page'] = teamPage;
369	} else {
370		if ($('#pagination').length) {
371			args['page'] = $('#pagination a.current').html();
372		}
373	}
374
375	if ($('#search').val()) {
376		args['search'] = $('#search').val();
377	}
378	getPosts(args);
379}
380
381//update portfolio grid with filters
382function filterSelection() {
383	$('#portfolio-filter li').on('click', function () {
384		$('#search').val('');
385		$(this).parents('ul').attr('data-selected', $(this).attr('data-value'));
386		$(this).siblings('li').removeClass('selected-filter');
387		$(this).addClass('selected-filter');
388		$(this).parents('ul').find('.active-filter').html($(this).html());
389		$('#pagination a.current').removeClass('current');
390		if (postType === 'team_member') {
391			teamPage = 1;
392			$('#portfolio').html('');
393		}
394
395		updatePortfolio();
396	});
397}
398
399function resetFilters() {
400	$('#portfolio-filter ul').each(function () {
401		$(this).removeAttr('data-selected');
402	});
403	$('.selected-filter').removeClass('selected-filter');
404	$('.active-filter').each(function () {
405		$(this).html($(this).attr('data-default'));
406	});
407	$('#pagination a.current').removeClass('current');
408	$('#search').val('');
409
410	getPosts();
411}
412
413function paginatePortfolio() {
414	$('#pagination a').click(function (e) {
415		e.preventDefault();
416		$('#pagination a.current').removeClass('current');
417		$(this).addClass('current');
418		updatePortfolio();
419		$(document).one('ajaxSuccess', function () {
420			$('html,body').animate({ scrollTop: $('#portfolio').offset().top - 300 }, 'slow');
421		});
422	});
423
424	$('#pagination li.next').click(function () {
425		if ($('#pagination li .current').parent().next().find('a').length) {
426			$('#pagination li .current').parent().next().find('a').click();
427		}
428	});
429
430	$('#pagination li.prev').click(function () {
431		if ($('#pagination li .current').parent().prev().find('a').length) {
432			$('#pagination li .current').parent().prev().find('a').click();
433		}
434	});
435}
436
437function adjustPagination(length) {
438	currentPage = 1;
439	var pageCount = Math.ceil(length / perPage);
440	// console.log('perPage ' + perPage);
441	// console.log('length ' + length);
442
443	if ($("#pagination a.current").length) currentPage = Number($('#pagination a.current').html());
444
445	$("#pagination li").remove();
446
447	if (length > 0) {
448		//console.log(currentPage);
449		if (currentPage !== 1) $("#pagination").append('<li class="prev"></li>');
450
451		for (i = 1; i <= pageCount; i++) {
452			if (i == currentPage) {
453				$("#pagination").append('<li><a href="#' + i + '" class="current">' + i + '</a></li>');
454			} else {
455				$("#pagination").append('<li><a href="#' + i + '">' + i + '</a></li>');
456			}
457		}
458
459		//console.log('currentPage ' + currentPage + '\npageCount ' + pageCount);
460		if (currentPage !== pageCount) $("#pagination").append('<li class="next"></li>');
461
462
463		paginatePortfolio();
464	}
465
466}
467
468// If we end up putting the search functionality on this page we 
469// will need to disable this if the search field is active
470function loadMore() {
471	if (!loadMoreTrigger) {
472
473		loadMoreTrigger = true;
474		if (teamPage < Math.ceil(totalPosts / 20)) {
475			teamPage += 1;
476			console.log('teamPage' + teamPage);
477			updatePortfolio();
478			console.log('loading more...');
479		} else {
480			console.log('NOT loading more...');
481		}
482	}
483	$(document).bind('ajaxComplete', function () {
484		loadMoreTrigger = false;
485	});
486}
487
488
489
490
491//get portfolio posts, call to child functions
492function getPosts(args) {
493	slug = $('#portfolio').attr('data-post_type');
494	leadership = $('#portfolio').attr('data-leadership');
495	console.log({ slug, leadership })
496	if (leadership == 'true') { infoBoxes(); }
497
498	var base_url = '/wp-json/wp/v2/' + slug + '?';
499
500	if (slug == 'projects') {
501		base_url += '&orderby=menu_order&order=asc';
502	}
503	if ($('body').hasClass('home')) {
504		perPage = '6';
505	} else if ($('body').hasClass('page-id-19') || $('body').hasClass('page-id-17')) {
506		perPage = '4';
507	}
508
509	base_url += '&per_page=' + String(perPage);
510
511	if (slug == 'team_member') {
512		base_url += '&orderby=title&order=asc';
513	}
514
515	if ($('#selector').length) {
516		var default_selection = $('#selector').attr('data-selector');
517		args[default_selection] = $('#selector').attr('value');
518	}
519	if ($('#portfolio').attr('data-featured-posts')) {
520		featured = $('#portfolio').attr('data-featured-posts').split(' ');
521		console.log(featured);
522		base_url += '&orderby=include';
523		for (i in featured) {
524			if (featured[i] !== '' && featured[i] !== ' ') {
525				base_url += '&include[]=' + featured[i];
526			}
527		}
528	} else {
529		// iterate through filters, adding to URL for wp api request
530		if (args) {
531			for (i in args) {
532				if (args[i]) {
533					base_url += '&' + i + '=' + args[i];
534				}
535			}
536		}
537	}
538
539	$.ajax({
540		url: base_url,
541		beforeSend: function () {
542			$('#portfolio').addClass('loading');
543		},
544		complete: function () {
545			$('#portfolio').removeClass('loading');
546		}
547	}).done(function (data, textStatus, xhr) {
548
549		//console.log('length: ' + xhr.getResponseHeader('x-wp-total')); 
550		totalPosts = xhr.getResponseHeader('x-wp-total');
551
552		var portfolio = '';
553
554		for (var i = 0; i <= data.length - 1; i++) {
555			if (data[i]['type'] === 'team_member' && data[i]['featured_image_src'].includes('/wp-includes/images/media/default.svg')) {
556				data[i]['featured_image_src'] = '/wp-content/plugins/portfolio-filters/assets/default-team.jpg';
557			}
558
559			if (leadership == 'true') {
560				if (data[i]['acf_fields']['leadership'] == 'true') {
561					portfolio += createTile(data[i]);
562				}
563			} else {
564				portfolio += createTile(data[i]);
565			}
566		}
567
568
569
570		portfolio += '<script>$(".hidden.infobox-content").click(function(){if($("body").hasClass("fusion-no-touch")) {window.location.assign($(this).find(".fusion-button").attr("href"));}});</script>';
571
572		if (postType === 'team_member') {
573
574			$('#portfolio').html($('#portfolio').html() + portfolio);
575		}
576		else {
577			$('#portfolio').html(portfolio);
578		}
579
580		sizeTiles();
581		squareNews();
582		//infoBoxes();
583		tileClick();
584
585
586		adjustPagination(totalPosts, false);
587	});
588}
589
590function getUrlParameter(name, url) {
591	if (!url) url = window.location.href;
592	name = name.replace(/[\[\]]/g, '\\$&');
593	var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
594		results = regex.exec(url);
595	if (!results) return null;
596	if (!results[2]) return '';
597	return decodeURIComponent(results[2].replace(/\+/g, ' '));
598}

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.