@@ -12,7 +12,19 @@ import { setupTagSearchForInput } from './searchInputHandler';
1212import { FilterModal } from './filterModal' ;
1313import { initClientSideFiltering } from './clientSideFiltering' ;
1414
15- /* eslint-enable sort-imports */
15+ function revealLoaded ( ) {
16+ document
17+ . querySelectorAll (
18+ '.breadcrumb.loading, .sf-container.loading, .page-main_content.loading' ,
19+ )
20+ . forEach ( ( el ) => {
21+ el . classList . remove ( 'loading' ) ;
22+ el . classList . add ( 'loaded' ) ;
23+ if ( el . hasAttribute ( 'aria-busy' ) ) {
24+ el . setAttribute ( 'aria-busy' , 'false' ) ;
25+ }
26+ } ) ;
27+ }
1628
1729function initConfiguration ( ) {
1830 window . DEFAULT_VISIBLE_TAGS_COUNT = 5 ;
@@ -57,13 +69,11 @@ function initFontChanger() {
5769
5870 setInterval ( ( ) => {
5971 currentFontIndex = ( currentFontIndex + 1 ) % fonts . length ;
60- // Use Array.prototype.at() for safer array access
6172 const currentFont = fonts . at ( currentFontIndex ) ;
6273 heroContent . style . fontFamily = currentFont ;
6374 } , 500 ) ;
6475}
6576
66- // Tag search filter for case studies page
6777function initCaseStudiesTagFilter ( {
6878 inputSelector = '.tag-search' ,
6979 containerSelector = '.filter-section' ,
@@ -92,30 +102,24 @@ function initializeAllComponents() {
92102 initClientSideFiltering ( ) ;
93103}
94104
95- // Barba pages
96105function initBarbaPageTransitions ( ) {
97106 if ( ! document . querySelector ( '[data-barba="container"]' ) ) return ;
98107
99108 apos . util . onReady ( ( ) => {
100- // Initialize case studies filter handler
101109 initCaseStudiesFilterHandler ( ) ;
102110
103- // Original Barba enter callback
104111 const originalEnterCallback = function ( data , hasFilterAnchor ) {
105- // Scroll to the top after page transition (unless we have a filter anchor)
106112 if ( ! hasFilterAnchor ) {
107113 window . scrollTo ( 0 , 0 ) ;
108114 }
109115
110- // Close menu if it's open
111116 const menuButton = document . getElementById ( 'nav-icon' ) ;
112117 const menu = document . querySelector ( '[data-menu]' ) ;
113118 if ( menuButton && menu ) {
114119 menu . classList . remove ( 'open' ) ;
115120 menuButton . classList . remove ( 'open' ) ;
116121 }
117122
118- // Trigger video play after transition
119123 const video = data . next . container . querySelector ( 'video' ) ;
120124 if ( video ) {
121125 video . play ( ) ;
@@ -160,7 +164,6 @@ function initBarbaPageTransitions() {
160164 cacheIgnore : false ,
161165 preventRunning : true ,
162166 timeout : 10000 ,
163-
164167 transitions : [
165168 {
166169 sync : false ,
@@ -175,28 +178,27 @@ function initBarbaPageTransitions() {
175178 ] ,
176179 } ) ;
177180
178- // Add after hook for updating menu state
179181 barba . hooks . after ( ( ) => {
180182 // Update menu active state
181183 const currentPath = window . location . pathname ;
182184 const menuLinks = document . querySelectorAll ( '.sf-nav__list a' ) ;
183-
184- // First, remove active class from all menu items
185185 menuLinks . forEach ( ( link ) => link . classList . remove ( 'active' ) ) ;
186-
187- // Then, add active class to the current menu item
188186 menuLinks . forEach ( ( link ) => {
189187 const href = link . getAttribute ( 'href' ) ;
190188 const hrefPath = new URL ( href , window . location . origin ) . pathname ;
191189 if ( hrefPath === currentPath ) {
192190 link . classList . add ( 'active' ) ;
193191 }
194192 } ) ;
193+
194+ revealLoaded ( ) ;
195+ if ( ! window . caseStudiesFilterModal ) {
196+ initFilterModal ( ) ;
197+ }
195198 } ) ;
196199 } ) ;
197200}
198201
199- // Anchor Navigation
200202function initAnchorNavigation ( ) {
201203 const anchors = document . querySelectorAll ( 'a[href^="#"]' ) ;
202204 if ( ! anchors . length ) return ;
@@ -216,7 +218,6 @@ function initAnchorNavigation() {
216218
217219function initMenuToggle ( ) {
218220 apos . util . onReady ( ( ) => {
219- // Menu Open
220221 const menuButton = document . getElementById ( 'nav-icon' ) ;
221222 const menu = document . querySelector ( '[data-menu]' ) ;
222223
@@ -227,7 +228,6 @@ function initMenuToggle() {
227228 menuButton . classList . toggle ( 'open' ) ;
228229 } ) ;
229230
230- // Close menu when clicking on menu items for non-logged users
231231 const menuLinks = menu . querySelectorAll ( 'a' ) ;
232232 menuLinks . forEach ( ( link ) => {
233233 link . addEventListener ( 'click' , ( ) => {
@@ -240,7 +240,6 @@ function initMenuToggle() {
240240 } ) ;
241241}
242242
243- // Filter Case Studies modal for Case Studies mobile page
244243function initFilterModal ( ) {
245244 if ( ! document . querySelector ( '.cs_list' ) ) {
246245 return ;
@@ -257,19 +256,23 @@ function initFilterModal() {
257256 } ) ;
258257}
259258
260- document . addEventListener ( 'DOMContentLoaded' , initFilterModal ) ;
261-
262- if ( typeof barba !== 'undefined' ) {
263- barba . hooks . after ( ( ) => {
264- initFilterModal ( ) ;
265- } ) ;
259+ if ( document . readyState === 'loading' ) {
260+ document . addEventListener ( 'DOMContentLoaded' , initFilterModal ) ;
261+ } else {
262+ initFilterModal ( ) ;
266263}
267264
268265export default ( ) => {
269266 initConfiguration ( ) ;
270267
271268 initializeAllComponents ( ) ;
272269
270+ if ( document . readyState === 'loading' ) {
271+ document . addEventListener ( 'DOMContentLoaded' , revealLoaded ) ;
272+ } else {
273+ revealLoaded ( ) ;
274+ }
275+
273276 apos . util . onReady ( ( ) => {
274277 initCaseStudiesFilterHandler ( ) ;
275278 } ) ;
@@ -278,17 +281,15 @@ export default () => {
278281 initAnchorNavigation ( ) ;
279282 initMenuToggle ( ) ;
280283
281- // Case studies anchor fix
282284 setTimeout ( ( ) => {
283285 const { pathname, search, hash } = window . location ;
284- const isCasesPage = pathname . includes ( '/cases' ) ;
285- const hasFilterParams =
286- search . includes ( 'industry' ) ||
287- search . includes ( 'stack' ) ||
288- search . includes ( 'caseStudyType' ) ||
289- hash . includes ( 'filter' ) ;
290-
291- if ( isCasesPage && hasFilterParams ) {
286+ if (
287+ pathname . includes ( '/cases' ) &&
288+ ( search . includes ( 'industry' ) ||
289+ search . includes ( 'stack' ) ||
290+ search . includes ( 'caseStudyType' ) ||
291+ hash . includes ( 'filter' ) )
292+ ) {
292293 const filterAnchor = document . getElementById ( 'filter' ) ;
293294 if ( filterAnchor ) filterAnchor . scrollIntoView ( { behavior : 'smooth' } ) ;
294295 }
0 commit comments