PageSourceSearch

https://www.allbirds.co.uk/cdn/shop/t/3608/assets/main-search.js

js allbirds.co.uk collected 2026-10-02 06:17:50 UTC 16,826 bytes, 1 lines download raw bytes

1import{g as L,e as P}from"./ScrollTrigger.js";import{c as er,r as f,o as rr,n as tr,x as ar,w as sr}from"./vue.esm-bundler.js";import{k as or,m as nr,e as ir}from"./analytics-data.js";import{u as cr}from"./use-filter-dropdown.js";import{u as lr}from"./use-master-product-card.js";import{u as ur}from"./use-quick-add-modal.js";import{b as I}from"./animations.js";import{F as n,N as ue,S as ee,n as we,E as re,O as Pe,L as de,P as dr,R as Sr,e as hr}from"./wunderkind-api.js";import{B as Tr,r as Rr}from"./base-section.js";import"./validator.js";import"./use-scroll-lock.js";import"./use-viewport-size.js";import"./use-amplitude-experiment.js";import"./use-focus-management.js";import"./use-post-atc-modal.js";import"./navigation.js";import"./create-element-if-not-defined.js";import"./swiper-core.js";import"./pagination.js";import"./classes-to-selector.js";import"./swiper.js";import"./currency.js";import"./cookies.js";import"./_commonjsHelpers.js";const fr=()=>{const Y=new Set,F=new Set,t={FAST:.15,SLOW:.5,STANDARD:.25},z=()=>{const i=L.timeline();return Y.add(i),i};return{activeTimeouts:F,animateFadeOut:i=>!i||Array.isArray(i)&&i.length===0?Promise.resolve():new Promise(R=>{L.to(i,{duration:t.FAST,ease:I.POWER3_IN_OUT,onComplete:R,opacity:0})}),animateFeaturedCollectionFadeIn:i=>{if(!i)return null;const R=z();R.to(i,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1});const p=i.querySelectorAll("[data-product-card]");return p.length>0&&(L.set(p,{opacity:0}),R.to(p,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},0)),R},animateGridTransition:(i,R,p,J,$)=>{const y=z();i&&y.to(i,{duration:t.FAST,ease:I.POWER3_IN_OUT,opacity:0});const N=i?t.FAST:0;if(J&&y.to(J,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},N),p&&y.to(p,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},N),$&&y.to($,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},N),R){y.to(R,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},N);const B=R.querySelectorAll("[data-product-card], [data-article-card]");B.length>0&&(L.set(B,{opacity:0}),y.to(B,{duration:t.STANDARD,ease:I.POWER3_OUT,opacity:1},N))}return y},ANIMATION_DURATION:t,animationTimelines:Y,cleanup:()=>{Y.forEach(i=>{i&&i.kill&&i.kill()}),Y.clear(),F.forEach(i=>{clearTimeout(i)}),F.clear()},createTrackedTimeout:(i,R)=>{const p=setTimeout(()=>{F.delete(p),i()},R);return F.add(p),p}}},c={FEATURED_COLLECTION_GRID:"[data-featured-collection-grid]",FILTER_DROPDOWN:"[data-filter-dropdown], [data-search-filter-dropdown]",FILTER_SORT_CONTAINER:"[data-search-filter-sort-container]",FILTER_SORT_DESKTOP:"[data-filter-and-sort-desktop], [data-search-filter-and-sort-desktop]",FILTER_SORT_MOBILE:"[data-filter-and-sort-mobile], [data-search-filter-and-sort-mobile]",RESULTS_COUNT:"[data-search-results-count]",RESULTS_GRID:"[data-search-results-grid]",SEARCH_INPUT:"[data-search-input]",SEARCH_TABS:"[data-search-tabs]",SORT_SELECT:"[data-search-sort-select]"},T={ARTICLES:"articles",PRODUCTS:"products"},h={ARTICLES:"[data-article-results-grid]",FEATURED:"[data-featured-collection-grid]",PRODUCTS:"[data-search-results-grid]"},u={PAGE:"page",TAB:"tab"},x="main-search",W="search-filter-dropdown-state";class pr extends Tr{constructor(){super(`[data-section-type="${x}"]`)}init(F){const t=F.container;er({name:"MainSearchSection",setup(){const{addToCartWithoutEvent:z,cardRefs:V,getVariantDescription:Se,getVariantLabel:he,handleAddToCart:Te,handleImageHover:Re,handleImageLeave:i,initializeAllCards:R,isDesktopQuickAddEnabled:p,isHoverGalleryEnabled:J,nextGalleryImage:$,prevGalleryImage:y,setActiveColorway:N,setActiveVariant:B,toggleSizeSelector:Ie}=lr(),{activeTimeouts:K,animateFadeOut:j,animateFeaturedCollectionFadeIn:fe,animateGridTransition:pe,ANIMATION_DURATION:te,animationTimelines:Ue,cleanup:U,createTrackedTimeout:H}=fr(),me=f(t),b=ur({cardRefs:V,containerRef:me,setActiveVariant:B}),Ae=new URL(window.location.href),g=f(Ae.searchParams.get(n.QUERY)||ue.EMPTY_QUERY),_e=f(t.dataset.enableFilteringSorting==="true"),De=f(t.dataset.hasActiveFilters==="true"),q=f(Ae.searchParams.get(n.SORT_BY)||ee.RELEVANCE),Le=parseInt(t.dataset.searchResultsCount||"0",10),ae=f(Le>0);let A=null;
1const o=f(!1),Ee=f(!1),se=f(0),O=f(ae.value?1:0),_=f(0),oe=f(null),m=f(T.PRODUCTS),Ce=3,ge=300,ve=()=>{try{window.sessionStorage.setItem(W,JSON.stringify({isOpen:X.value}))}catch{}},Fe=()=>{try{const e=window.sessionStorage.getItem(W);return e?(window.sessionStorage.removeItem(W),!!JSON.parse(e)?.isOpen):!1}catch{return window.sessionStorage.removeItem(W),!1}};let ye=!1;try{const e=window.sessionStorage.getItem(W);e&&(ye=!!JSON.parse(e)?.isOpen)}catch{}const{activeFilterDropdowns:Ne,cleanupFilterDropdown:Me,closeFilterDropdown:Be,handleFilterDropdownChange:be,handlePriceRangeChange:qe,initializeFilterDropdown:Ge,showFilterDropdown:X,syncPriceCheckboxStates:G,toggleFilterMenu:Ye}=cr({containerRef:me,preserveParams:[n.QUERY,n.SORT_BY,u.TAB],rerenderCallback:async({triggerType:e})=>{ve(),U(),await v({animationType:"search",errorContext:{trigger:e},errorMessage:`[Allbirds section] - MainSearch - Filter ${e} - Error rerendering`,gridSelector:"[data-search-results-grid]",refocusInput:!1}),G()},sectionName:x});ye&&(Fe(),X.value=!0);const He=async e=>{if(e.preventDefault(),!o.value){o.value=!0;try{ve();const r=e.target.closest("form")||e.target,a=new FormData(r),s=new URLSearchParams;for(const[S,w]of a.entries())w!=null&&String(w).length>0&&s.append(S,w);const l=new URLSearchParams(window.location.search);l.has(n.QUERY)&&!s.has(n.QUERY)&&s.set(n.QUERY,l.get(n.QUERY)),l.has(n.SORT_BY)&&!s.has(n.SORT_BY)&&s.set(n.SORT_BY,l.get(n.SORT_BY)),l.has(u.TAB)&&!s.has(u.TAB)&&s.set(u.TAB,l.get(u.TAB)),s.delete(u.PAGE);const d=new URL(window.location.href);d.search=s.toString(),re(d,!0),U(),await v({animationType:"search",errorContext:{trigger:"filters-submit"},errorMessage:"[Allbirds section] - MainSearch - handleFilterSubmit - Error rerendering with new filters",gridSelector:c.RESULTS_GRID,refocusInput:!1}),G()}catch(r){Xe(r,{trigger:"filters-submit"})}finally{o.value=!1}}},ke=async e=>{if(m.value===e||o.value)return;const r=t.querySelector(h.PRODUCTS),a=t.querySelector(h.ARTICLES);if(!(e===T.PRODUCTS?O.value>0:_.value>0)){o.value=!0,Pe({[u.TAB]:e});const E=new URLSearchParams(window.location.search).get(u.PAGE),C=[];r&&C.push(r),a&&C.push(a),C.length>0&&await j(C),await v({animationType:"search",errorContext:{newTab:e,trigger:"tab-switch-pagination-reset",wasOnPage:E},errorMessage:"[Allbirds section] - MainSearch - setActiveTab - Error rerendering to page 1",gridSelector:e===T.PRODUCTS?h.PRODUCTS:h.ARTICLES,refocusInput:!1});return}const l=new URLSearchParams(window.location.search);l.set(u.TAB,e),de({searchParams:Object.fromEntries(l)});const d=m.value===T.PRODUCTS?r:a,S=e===T.PRODUCTS?r:a;m.value=e,d?L.to(d,{duration:te.FAST,onComplete:()=>{S?L.to(S,{duration:te.STANDARD,onComplete:()=>{o.value&&(o.value=!1)},opacity:1}):o.value&&(o.value=!1)},opacity:0}):S&&L.to(S,{duration:te.STANDARD,onComplete:()=>{o.value&&(o.value=!1)},opacity:1})},Qe=()=>{const e=t.querySelector(c.SEARCH_INPUT);e&&e.focus()},Oe=e=>{const r=new URLSearchParams(window.location.search),a={[n.QUERY]:e,[u.PAGE]:null,[u.TAB]:null};return r.has(n.SORT_BY)&&(a.sort_by=r.get(n.SORT_BY)),a},xe=()=>{const e=new URLSearchParams(window.location.search);return Array.from(e.keys()).some(r=>r.startsWith(n.FILTER))},ne=()=>{const e=xe();Ee.value=e},Z=async(e,r={force:!1})=>{const a=e?.trim()??"";o.value=!0,U();const d=(new URL(window.location.href).searchParams.get(n.QUERY)||ue.EMPTY_QUERY).trim().length>0,S=r.force?a.length>0:a.length>=Ce;if(a.length===0){const w=Oe(ue.EMPTY_QUERY),E=t.querySelector(h.PRODUCTS),C=t.querySelector(c.FILTER_SORT_CONTAINER),k=t.querySelector(c.SEARCH_TABS),Q=t.querySelector(h.ARTICLES);if(de({searchParams:w}),E||C){const D=[];E&&D.push(E),C&&D.push(C),k&&D.push(k),Q&&D.push(Q),await j(D)}await v({animationType:"featured",errorContext:{newSearchTerm:e},errorMessage:"[Allbirds section] - MainSearch - handleSearchTermChange - Error rerendering initial search content",gridSelector:c.FEATURED_COLLECTION_GRID,refocusInput:!0});return}if(!S){o.value=!1;return}if(S){const w=Oe(a);if(de({searchParams:w}),d){const E=t.querySelector(h.PRODUCTS),C=t.querySelector(c.FILTER_SORT_CONTAINER),k=t.querySelector(c.RESULTS_COUNT),Q=t.querySelector(c.SEARCH_TABS),D=t.querySelector(h.ARTICLES),M=[];E&&M.push(E),C&&M.push(C),k&&M.push(k),Q&&M.push(Q),D&&M.push(D),M.length>0&&await j(M),await v({animationType:"search",errorContext:{newSearchTerm:e},errorMessage:"[Allbirds section] - MainSearch - handleSearchTermChange - Error rerendering search results",gridSelector:c.RESULTS_GRID,refocusInput:!0})}else{const E=t.querySelector(c.FEATURED_COLLECTION_GRID);E&&await j(E),await v({animationType:"search",errorContext:{newSearchTerm:e},errorMessage:"[Allbirds section] - MainSearch - handleSearchTermChange - Error rerendering search results",gridSelector:c.RESULTS_GRID,refocusInput:!0})}}},We=e=>{e.preventDefault(),A&&(clearTimeout(A),K.delete(A)),Z(g.value,{force:!0})},ze=e=>{g.value=e,A&&(clearTimeout(A),K.delete(A)),Z(e,{force:!0})},Ve=async e=>{q.value=e.target.value,Pe({[n.SORT_BY]:e.target.value}),o.value=!0,U(),await v({animationType:"sort",errorContext:{sortBy:q.value},errorMessage:"[Allbirds section] - MainSearch - handleSortByChange - Error rerendering with new sort",gridSelector:c.RESULTS_GRID,refocusInput:!1})},Je=async(e,r)=>{if(e.preventDefault(),!o.value){o.value=!0;try{const a=new URL(r,window.location.origin);a.searchParams.delete(u.PAGE);const s=new URLSearchParams(window.location.search);s.has(n.QUERY)&&!a.searchParams.has(n.QUERY)&&a.searchParams.set(n.QUERY,s.get(n.QUERY)),s.has(u.TAB)&&!a.searchParams.has(u.TAB)&&a.searchParams.set(u.TAB,s.get(u.TAB)),re(a,!0),U(),await v({animationType:"search",errorContext:{trigger:"filter-clear"},errorMessage:"[Allbirds section] - MainSearch - handleFilterClear - Error rerendering after clearing filter",gridSelector:c.RESULTS_GRID,refocusInput:!1}),G()}catch(a){P("[Allbirds section] - MainSearch - Failed to clear filter",{filterUrl:r},a),o.value=!1}finally{o.value=!1}}},$e=async e=>{if(e.preventDefault(),!o.value){o.value=!0;try{const r=dr([n.QUERY,n.SORT_BY,u.TAB]);re(r,!0),U(),await v({animationType:"search",errorContext:{trigger:"filters-clear-all"},errorMessage:"[Allbirds section] - MainSearch - handleClearAllFilters - Error rerendering after clearing all filters",gridSelector:c.RESULTS_GRID,refocusInput:!1}),G()}catch(r){P("[Allbirds section] - MainSearch - Failed to clear all filters",{},r),o.value=!1}finally{o.value=!1}}},Ke=async e=>{if(e.preventDefault(),!o.value){o.value=!0;try{const r=Sr(),a=new URLSearchParams(window.location.search);a.has(n.QUERY)&&!r.searchParams.has(n.QUERY)&&r.searchParams.set(n.QUERY,a.get(n.QUERY)),a.has(u.TAB)&&!r.searchParams.has(u.TAB)&&r.searchParams.set(u.TAB,a.get(u.TAB)),re(r,!0),U(),await v({animationType:"search",errorContext:{trigger:"price-filter-clear"},errorMessage:"[Allbirds section] - MainSearch - handleClearPriceFilter - Error rerendering after clearing price filter",gridSelector:c.RESULTS_GRID,refocusInput:!1}),G()}catch(r){P("[Allbirds section] - MainSearch - Failed to clear price filter",{},r),o.value=!1}finally{o.value=!1}}},ie=()=>
1{const r=new URL(window.location.href).searchParams.get(n.SORT_BY);r?q.value=r:q.value=ee.RELEVANCE;const a=t.querySelector(c.SORT_SELECT);a&&(a.value=q.value||ee.RELEVANCE)},ce=()=>{try{if(!t){P("[Allbirds section] - MainSearch - updateResultsCount - Container not found",{},new Error("Container not found in updateResultsCount"));return}const e=t.querySelector(h.PRODUCTS);if(e){const s=e.querySelectorAll("[data-product-json]");O.value=s.length>0?1:0}else{const s=parseInt(t.dataset.searchResultsCount||"0",10);O.value=s>0?1:0}const r=t.querySelector(h.ARTICLES);if(r){const s=r.querySelectorAll("[data-article-card]");_.value=s.length>0?1:0}else _.value=0;se.value=O.value+_.value;const a=parseInt(t.dataset.searchResultsCount||"0",10);ae.value=a>0}catch(e){P("[Allbirds section] - MainSearch - updateResultsCount - Error updating results count",{},e);const r=parseInt(t?.dataset?.searchResultsCount||"0",10);O.value=r>0?1:0,_.value=0,se.value=O.value}},le=()=>{const r=new URLSearchParams(window.location.search).get(u.TAB);if(r===T.ARTICLES){m.value=T.ARTICLES;return}if(r===T.PRODUCTS){m.value=T.PRODUCTS;return}O.value===0&&_.value>0?m.value=T.ARTICLES:m.value=T.PRODUCTS},je=(e,r={animationType:"search",refocusInput:!1})=>{ne(),ie(),ce(),le(),r.refocusInput&&Qe(),H(()=>{G();let a=null;r.animationType==="search"||r.animationType==="sort"?m.value===T.PRODUCTS?a=t.querySelector(h.PRODUCTS):m.value===T.ARTICLES&&(a=t.querySelector(h.ARTICLES)):a=t.querySelector(e);const s=t.querySelector(c.FILTER_SORT_CONTAINER),l=t.querySelector(c.RESULTS_COUNT),d=t.querySelector(c.SEARCH_TABS);r.animationType==="featured"&&a?fe(a):(r.animationType==="search"||r.animationType==="sort")&&(a||s||l)&&(X.value&&s&&L.set(s,{opacity:1}),pe(null,a,s,l,d)),r.animationType==="search"&&g.value&&ir({query:g.value,searchEntry:hr.SEARCH_PAGE,searchResultsCount:O.value+_.value,searchSource:window.location.href})},50),o.value=!1},v=({animationType:e="search",errorContext:r={},errorMessage:a="[Allbirds section] - MainSearch - rerenderSearchResults - Error rerendering",gridSelector:s=c.RESULTS_GRID,refocusInput:l=!1}={})=>Rr(["main-search"],{},()=>{if(window.BaseSection&&typeof window.BaseSection.getInstance=="function")try{const d=t.getAttribute("data-section-id"),S=window.BaseSection.getInstance(d);S&&S.section&&(S.initialized=!1,S.section._initInstance(S))}catch(d){P("[Allbirds section] - MainSearch - rerenderSearchResults - Error reinitializing section",{},d)}je(s,{animationType:e,refocusInput:l}),H(()=>{ie()},0)},d=>{P(a,r,d),o.value=!1}),Xe=(e,r={})=>{P("[Allbirds section] - MainSearch - Search operation failed",{activeTab:m.value,searchTerm:g.value,section:x,...r},e),o.value=!1},Ze=e=>
1{const r=t.querySelector(`[data-product-card][data-product-id="${e}"]`);if(r?.getAttribute("data-product-one-size")==="true"){z(e);return}const a=V.value[e],s=r?.getAttribute("data-product-name")||"",l=r?.getAttribute("data-product-unisex")==="true",d=a?.currentVariants||[],S=d.length>0&&d[0].title?.includes("UK ");b.open(e,{colorway:a?.selectedColorway||"",isUkSize:S,isUnisex:l,productImage:a?.selectedImage?.src||"",productName:s,variants:d})};return rr(()=>{Ge(t),oe.value=t.querySelector(c.SEARCH_INPUT),oe.value&&tr(()=>{oe.value?.focus()});const e=new URL(window.location.href);if(q.value=e.searchParams.get(n.SORT_BY)||ee.RELEVANCE,ne(),ce(),le(),R(t),b.init(),g.value){const r=t.querySelectorAll("[data-product-json]"),s={handle:"search-results",products:Array.from(r).map(l=>{try{return JSON.parse(l.dataset.productJson)}catch(d){return P("[Allbirds section] - MainSearch - onMounted - Error parsing product JSON",{productJson:l.dataset.productJson},d),null}}).filter(Boolean),title:`Search: ${g.value}`,url:window.location.pathname};or({collection:s,sectionName:x})}nr({locationParam:we.LOCATIONS.SEARCH,sectionName:x,typeParam:we.TYPES.CARD,valueParam:window.location.pathname}),H(()=>{if(ne(),ie(),ce(),le(),g.value){const r=m.value===T.ARTICLES?t.querySelector(h.ARTICLES):t.querySelector(h.PRODUCTS),a=t.querySelector(c.FILTER_SORT_CONTAINER),s=t.querySelector(c.RESULTS_COUNT),l=t.querySelector(c.SEARCH_TABS);(r||a||s)&&pe(null,r,a,s,l)}else{const r=t.querySelector(h.FEATURED);r&&fe(r)}},50)}),ar(()=>{Me(),U(),b.cleanup(),Ue.clear(),K.clear(),t._sizeSelectorMouseLeaveHandler&&(t.removeEventListener("mouseleave",t._sizeSelectorMouseLeaveHandler),t._sizeSelectorMouseLeaveHandler=null)}),sr(g,(e,r)=>{if(A&&(clearTimeout(A),K.delete(A)),e!==r){const a=e?.trim()??"";if(a.length===0){A=H(()=>{Z(a)},ge);return}a.length>=Ce?(o.value||(o.value=!0),A=H(()=>{Z(a)},ge)):o.value=!1}}),{activeFilterDropdowns:Ne,activeTab:m,articleResultsCount:_,cardRefs:V,closeFilterDropdown:Be,closeSizeModal:b.close,enableFilteringSorting:_e,getVariantDescription:Se,getVariantLabel:he,handleAddToCart:Te,handleClearAllFilters:$e,handleClearPriceFilter:Ke,handleFilterClear:Je,handleFilterDropdownChange:be,handleFilterSubmit:He,handleImageHover:Re,handleImageLeave:i,handlePriceRangeChange:qe,handleQuickAddVariantSelect:b.handleVariantSelect,handleSearchSubmit:We,handleSortByChange:Ve,handleTrendingTermClick:ze,hasActiveFilters:De,hasServerResults:ae,isDesktopQuickAddEnabled:p,isHoverGalleryEnabled:J,isSearching:o,nextGalleryImage:$,openSizeModal:Ze,prevGalleryImage:y,productResultsCount:O,quickAddModalState:b.quickAddModal,searchTerm:g,setActiveColorway:N,setActiveTab:ke,setActiveVariant:B,showClearFilters:Ee,showFilterDropdown:X,toggleFilterMenu:Ye,toggleSizeSelector:Ie,totalResultsCount:se}}}).mount(t)}}document.addEventListener("DOMContentLoaded",()=>{new pr});

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.