jQuery(".gfm-fundraisers").each(function (index) {
let indexNumber = index + 1;
jQuery(this).find("#gfm-fundraiser-grid").addClass(`list-${indexNumber}`);
jQuery(this).find(".gfm-fundraisers-list-wrapper").attr("id", `gfm-fundraisers-list-wrapper-${indexNumber}`);
/* Construct endpoint URL based on curated slugs.
-------------------------------------------------------------- */
const baseUrl = "https://gateway.gofundme.com/web-gateway/v1/feed/campaigns?";
// Get slugs from ACF field
let fundraiserSlugs = jQuery(this).find("#gfm-fundraiser-grid").attr("data-slugs");
// Convert to array and format
let fundraiserSlugsArray = fundraiserSlugs.split(",").map((slug) => `slugs=${slug}&`);
/* Get total number of fundraisers
-------------------------------------------------------------- */
let numberOfSlugs = fundraiserSlugsArray.length;
// Starts at 0 and will count up until equal to numberOfSlugs
let fundraisersShowing = 0;
let perPage = 12;
let lowNumber = 0;
let highNumber = perPage;
// Initialize an empty category list for each "gfm-fundraisers" section
const tabList = jQuery(this).find("#tab-list");
// This is a stateMap for mapping abbreviated states to their full name.
let stateMap = {
al: "Alabama",
ak: "Alaska",
az: "Arizona",
ar: "Arkansas",
ca: "California",
co: "Colorado",
ct: "Connecticut",
de: "Delaware",
dc: "Washington D.C.",
fl: "Florida",
ga: "Georgia",
hi: "Hawaii",
id: "Idaho",
il: "Illinois",
in: "Indiana",
ia: "Iowa",
ks: "Kansas",
ky: "Kentucky",
la: "Louisiana",
me: "Maine",
md: "Maryland",
ma: "Massachusetts",
mi: "Michigan",
mn: "Minnesota",
ms: "Mississippi",
mo: "Missouri",
mt: "Montana",
ne: "Nebraska",
nv: "Nevada",
nh: "New Hampshire",
nj: "New Jersey",
nm: "New Mexico",
ny: "New York",
nc: "North Carolina",
nd: "North Dakota",
oh: "Ohio",
ok: "Oklahoma",
or: "Oregon",
pa: "Pennsylvania",
ri: "Rhode Island",
sc: "South Carolina",
sd: "South Dakota",
tn: "Tennessee",
tx: "Texas",
ut: "Utah",
vt: "Vermont",
va: "Virginia",
wa: "Washington",
wv: "West Virginia",
wi: "Wisconsin",
wy: "Wyoming",
// Non US locals
on: "Ontario",
};
while (fundraisersShowing < numberOfSlugs) {
let showOnLoadString = fundraiserSlugsArray.slice(lowNumber, highNumber).join("").replace(/\s/g, "");
let finalUrl = baseUrl + showOnLoadString;
jQuery
.ajax({
method: "GET",
url: finalUrl,
dataType: "json",
async: true,
})
.done(function (fundraiserData) {
jQuery.each(fundraiserData.data, function (i, fundraiser) {
// Get correct currency based on fundraiser
let country = `${fundraiser.country}`;
let currencyCode = `${fundraiser.currency_code}`;
if (country === "US" || country === "CA" || country === "AU" || country === "GB") {
country = `EN-${fundraiser.country}`;
} else {
country = "EN-US";
}
// If currency_code JSON is null add manually
if (currencyCode === "") {
if (fundraiser.country === "GB") {
currencyCode = "GBP";
} else if (fundraiser.country === "DE" || fundraiser.country === "ES" || fundraiser.country === "FR" || fundraiser.country === "IT" || fundraiser.country === "NL" || fundraiser.country === "PT" || fundraiser.country === "IE") {
currencyCode = "EUR";
} else if (fundraiser.country === "CA") {
currencyCode = "CAD";
} else if (fundraiser.country === "AU") {
currencyCode = "AUD";
} else {
currencyCode = "USD";
}
}
// Format time since last donation. (Using moment.js)
let timeStamp = `${fundraiser.last_donation_at}`;
let currentTime = moment.tz("America/Los_Angeles").add(2, "hours");
let pastTime = moment.tz(timeStamp, "America/Los_Angeles");
let timeDifference = currentTime.diff(pastTime);
// Determine fill % of progress bar
const goalAmount = fundraiser.goal_amount;
const balance = fundraiser.balance;
const currentGoalPercentage = Math.round((100 * balance) / goalAmount);
// If location is null leave blank
let location = `${fundraiser.location}`;
if (location === "null") {
location = "";
}
let category = fundraiser.category;
let dataCategory = category.replace(/\s+/g, "-").toLowerCase();
let formattedCity = "";
let dataCity = "";
let formattedState = "";
let dataState = "";
let fullStateName = "";
if (!tabList.hasClass("notabs")) {
if (location.includes(",")) {
// Check if location contains a comma
formattedCity = location.substring(0, location.lastIndexOf(","));
dataCity = location.replace(/\s+/g, "-").toLowerCase().substring(0, location.lastIndexOf(","));
formattedState = location.split(",")[1].trim();
dataState = location.split(",")[1].trim().toLowerCase();
fullStateName = stateMap[dataState];
} else {
// If no comma, consider the entire location string as the city.
formattedCity = location;
dataCity = location.replace(/\s+/g, "-").toLowerCase();
formattedState = formattedCity; // Make formattedState same as formattedCity
}
}
// Fundraiser card markup
let thisFundraiserCard = `
`;
thisFundraiserCard += ``;
thisFundraiserCard += ``;
thisFundraiserCard += `

`;
thisFundraiserCard += `
`;
thisFundraiserCard += ``;
thisFundraiserCard += ``;
thisFundraiserCard += ``;
// Hide fundraisers that have met their goal
if (jQuery("#gfm-fundraiser-grid").hasClass("hide-met-goal")) {
if (currentGoalPercentage >= 100) {
thisFundraiserCard = "";
}
}
// Add each fundraiser to grid
jQuery("#gfm-fundraiser-grid.list-" + indexNumber).append(thisFundraiserCard);
if (!tabList.hasClass("notabs")) {
// Add items to #tab-list
if (tabList.hasClass("categories")) {
dataAttr = "data-category";
formattedData = dataCategory;
dataLabel = category;
} else if (tabList.hasClass("cities")) {
dataAttr = "data-city";
formattedData = dataCity;
dataLabel = formattedCity;
} else if (tabList.hasClass("states")) {
dataAttr = "data-state";
formattedData = dataState;
dataLabel = fullStateName;
}
if (!tabList.find(`li[${dataAttr}="${formattedData}"]`).length) {
tabList.append(`${dataLabel}`);
}
}
});
}); // End AJAX call
lowNumber += perPage;
highNumber += perPage;
fundraisersShowing += perPage;
} // end while loop
}); // end each loop
;
jQuery(window).on('load', function() {
// Set number of fundraisers per page
let perPage = '12';
// Define options for List.js list
let listOptions = {
valueNames: [
'name',
'location',
{ data: ['category'] },
{ data: ['city'] },
{ data: ['state'] },
{ data: ['fullState'] }
],
page: perPage,
pagination: [
{
item: '',
name: "gfm-pagination",
paginationClass: "gfm-pagination",
innerWindow: 1,
outerWindow: 1
}
]
};
// Loop through each block-fundraisers-v1 element on the page
jQuery('.block-fundraisers-v1').each(function(index) {
let $this = jQuery(this);
let blockId = index + 1;
let listContainer = "gfm-fundraisers-list-wrapper-" + blockId;
let numberOfFundraisers = $this.find('.gfm-fundraiser-grid > li').length;
// Function checks if search bar / pagination is necessary
function updatePagination() {
if (fundraiserList.matchingItems.length > perPage) {
$this.find('.gfm-search-nav').removeClass('no-pageing');
} else {
$this.find('.gfm-search-nav').addClass('no-pageing');
}
}
// Set up List.js list for current block-fundraisers-v1 element
let fundraiserList = new List(listContainer, listOptions);
// Update pagination on page load
updatePagination()
// Set up click event listener on each li in #tab-list
$this.find('#tab-list li').on('click', function() {
let category = jQuery(this).data('category');
let city = jQuery(this).data('city');
let state = jQuery(this).data('state');
let totalItems;
$this.find('#tab-list li').removeClass('active');
jQuery(this).addClass('active');
if (jQuery(this).hasClass('show-all')) {
// Remove all filters and get total number of items in list
fundraiserList.filter();
totalItems = fundraiserList.matchingItems.length;
} else {
// Filter the list based on clicked tab, and get the total number of items in the list
fundraiserList.filter(function(item) {
return item.values().category === category || item.values().city === city || item.values().state === state;
});
totalItems = fundraiserList.matchingItems.length;
}
// Update the list with the filtered items
fundraiserList.update();
// Show the first page of filtered results and reset pagination to page 1
fundraiserList.show(1, listOptions.page);
// Update pagination on page load
updatePagination();
});
});
});;
jQuery(document).ready(function (jQuery) {
// Smooth scroll for anchor links
jQuery(".greenhouse-departments a").on("click", function (event) {
event.preventDefault();
var target = jQuery(this.getAttribute("href"));
if (target.length) {
jQuery("html, body").animate(
{
scrollTop: target.offset().top - 25, // Offset by 25px
},
500 // Duration of the scroll animation in milliseconds
);
}
});
});
;
document.addEventListener('DOMContentLoaded', function () {
const searchInput = document.querySelector('#department-search');
const jobsContainer = document.querySelector('.greenhouse-jobs');
// Ensure search input and jobs container exist
if (!searchInput || !jobsContainer) {
console.error('Search input or jobs container not found.');
return;
}
const departments = jobsContainer.querySelectorAll('[id^="department-"]');
searchInput.addEventListener('input', function () {
const filter = searchInput.value.toLowerCase();
departments.forEach(function (department) {
const jobs = department.querySelectorAll('ul li');
let hasVisibleJobs = false;
jobs.forEach(function (job) {
const jobTitle = job.querySelector('a').textContent.toLowerCase();
const jobLocation = job.textContent.split('-')[1]?.trim().toLowerCase() || '';
const matches =
jobTitle.includes(filter) || jobLocation.includes(filter);
// Show or hide the job based on the filter
job.style.display = matches ? 'block' : 'none';
if (matches) hasVisibleJobs = true;
});
// Show or hide the department based on whether it has visible jobs
department.style.display = hasVisibleJobs ? 'block' : 'none';
});
});
});
;
function wordCountResize(e,t){jQuery("."+e).each(function(){let e=0;jQuery(this).find("p, h1").each(function(){e+=jQuery(this).text().split(/\s+/).length}),e>=t&&jQuery(this).addClass("modify-text")})}function smoothScroll(n=50){jQuery('a[href*="#"]').on("click",function(e){var t=jQuery(this).attr("href"),t=t.substring(t.indexOf("#"));1