1const fundraiserHeader=document.getElementById("fundraiser-header"),fundraiserHeaderMessage=document.getElementById("fundraiser-header-message"),fundraiserRemove=document.getElementById("fundraiser-remove"),fundraiserTitle=document.getElementById("fundraiser-search-title"),fundraiserSearchControls=document.getElementById("fundraiser-search-controls"),fundraiserSearchInstructions=document.getElementById("fundraiser-search-instructions"),fundraiserSearchInput=document.getElementById("fundraiser-search-input"),fundraiserSearchResults=document.getElementById("fundraiser-search-results"),fundraiserSelectedBlock=document.getElementById("fundraiser-selected"),fundraiserChangeLink=document.getElementById("fundraiser-change-link"),searchIcon=document.getElementById("fa-search-icon");fundraiserHeader&&(async()=>await initFundraiserHeader())(),fundraiserSearchInput&&(async()=>await initFundraiserSearch())();async function initializeFundraiser(){const selectedFundraiser=getSelectedFundraiser(),urlHasRfsn=new URLSearchParams(window.location.search).has("rfsn");if(selectedFundraiser)return urlHasRfsn||refreshWithRfsn(selectedFundraiser),selectedFundraiser;if(urlHasRfsn){const rfsn=new URLSearchParams(window.location.search).get("rfsn");return await lookupAndSaveFundraiserByRfsn(rfsn)}return null}async function initFundraiserHeader(){const fundraiser=await initializeFundraiser();fundraiser&&(displaySelectedFundraiser(fundraiser),fundraiserRemove.addEventListener("click",()=>{openFundraiserModal()}))}async function initFundraiserSearch(){const fundraiser=await initializeFundraiser();fundraiser&&displaySelectedFundraiser(fundraiser),fundraiserChangeLink.addEventListener("click",()=>{toggleFundraiserSelection(!0),fundraiserSearchInput.focus()});const options=await buildFundraiserOptions();fundraiserSearchInput.addEventListener("keyup",({target:{value}})=>{const results=getSearchResults(options,value);updateSearchResults(results)})}function displaySelectedFundraiser(fundraiser){const supportMessage=`You're Supporting - ${fundraiser.label}`;fundraiserHeaderMessage&&(fundraiserHeader.style.display="flex",fundraiserHeaderMessage.textContent=supportMessage),fundraiserTitle&&(fundraiserTitle.textContent=supportMessage,toggleFundraiserSelection(!1))}function toggleFundraiserSelection(showSearch){fundraiserSearchInput&&(showSearch&&(fundraiserTitle.textContent="Search for Your School or Organization"),fundraiserSearchControl
1s.style.display=showSearch?"block":"none",fundraiserSearchInstructions.style.display=showSearch?"block":"none",fundraiserSelectedBlock.style.display=showSearch?"none":"block")}async function fetchFundraisers(){return(await fetch("https://api.refersion.namebubbles-prod.com/affiliates")).json()}async function buildFundraiserOptions(){const fundraisers=await fetchFundraisers(),options=[],companyMap=new Map;return fundraisers.forEach(({company,last_name,first_name,rfsn_parameter,city})=>{const trimmedCompany=company?.trim();trimmedCompany?(companyMap.has(trimmedCompany)||companyMap.set(trimmedCompany,[]),companyMap.get(trimmedCompany).push({last_name,first_name,rfsn_parameter,city})):options.push({label:`${last_name}, ${first_name}`,key:rfsn_parameter})}),companyMap.forEach((fundraisers2,company)=>{const hasMultiple=fundraisers2.length>1;fundraisers2.forEach(({last_name,first_name,rfsn_parameter,city})=>{let label=company;hasMultiple&&(label+=` (${city||`${last_name}, ${first_name}`})`),options.push({label,key:rfsn_parameter})})}),options.sort((a,b)=>a.label.localeCompare(b.label,void 0,{sensitivity:"base"})),options}async function lookupAndSaveFundraiserByRfsn(rfsn){try{const fundraiser=(await buildFundraiserOptions()).find(option=>option.key===rfsn);return fundraiser?(saveSelectedFundraiser(fundraiser),fundraiser):null}catch(error){return console.error("Error looking up fundraiser by rfsn:",error),null}}function getSearchResults(options,value){if(!value)return[];const valueUpper=value.toUpperCase(),startsWithValue=[],containsValue=[];options.forEach(option=>{const labelUpper=option.label.toUpperCase();labelUpper.startsWith(valueUpper)?startsWithValue.push(option):labelUpper.includes(valueUpper)&&containsValue.push(option)});const compareLabels=(a,b)=>a.label.localeCompare(b.label,void 0,{sensitivity:"base"});return[...startsWithValue.sort(compareLabels),...containsValue.sort(compareLabels)]}function updateSearchResults(results){fundraiserSearchResults.innerHTML="",results.forEach(fundraiser=>{const div=document.createElement("div");div.className="fundraiser-search-result",div.textContent=fundraiser.label,div.addEventListener("click",()=>selectFundraiser(fundraiser)),fundraiserSearchResults.appendChild(div)})}function selectFundraiser(fundraiser){saveSelectedFundraiser(fundraiser),refreshWithRfsn(fundraiser)}function refreshWithRfsn({key}){const currentUrl=new URL(window.location.href);currentUrl.searchParams.set("rfsn",key),window.location.href=currentUrl.toString()}function saveSelectedFundraiser(fundraiser){const expires=Date.now()+2592e6;localStorage.setItem("selectedFundraiser",JSON.stringify({...fundraiser,expires}))}function getSelectedFundraiser(){const stored=localStorage.getItem("selectedFundraiser");if(stored){const fundraiser=JSON.parse(stored);if(Date.now()<fundraiser.expires)return fundraiser;localStorage.removeItem("selectedFundraiser")}return null}function removeSelectedFundraiser(){localStorage.removeItem("selectedFundraiser")}function openFundraiserModal(){const overlay=document.createElement("div");overlay.id="fundraiser-modal-overlay";function closeModal(){overlay.remove()}overlay.addEventListener("click",event=>{event.target===overlay&&closeModal()});const modal=document.createElement("div");modal.id="fundraiser-modal";const modalContent=document.createElement("div"),modalTitle=document.createElement("h4");modalTitle.id="fundraiser-modal-title",modalTitle.innerHTML="Do you want to stop supporting this fundraiser?";const buttons=document.createElement("div");buttons.style.display="flex",buttons.style.justifyContent="space-evenly",buttons.style.margin="2rem 0";const yesButton=document.createElement("button");yesButton.classList.add("button","button--wide"),yesButton.textContent="Yes",yesButton.addEventListener("click",()=>{removeSelectedFundraiser();const currentUrl=new URL(window.location.href);currentUrl.searchParams.delete("rfsn"),window.location.href=currentUrl.toString()});const noButton=document.createElement("button");noButton.classList.add("button","button--wide"),noButton.textContent="No",noButton.addEventListener("click",closeModal),buttons.appendChild(yesButton),buttons.appendChild(noButton);const changePartnerLink=document.createElement("a");changePartnerLink.id="fundraiser-modal-change",changePartnerLink.textContent="Support a different fundraiser",changePartnerLink.href="/pages/fundraiser-search",modalContent.appendChild(modalTitle),modalContent.appendChild(buttons),modalContent.appendChild(changePartnerLink),modal.appendChild(modalContent),overlay.appendChild(modal),document.body.appendChild(overlay)} 2//# sourceMappingURL=/cdn/shop/t/281/assets/fundraisers.js.map?v=152214151142593267891787862473
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.