1/** 2 * Yoast FAQ block â hybrid accordion (GYM-19109) 3 * - First 3 questions open by default, rest collapsed 4 * - Click / Enter / Space toggles a section 5 * - Strips Yoast's leading "N. " from question text (CSS counter handles numbering) 6 * - Pre-hydration markup stays fully readable for no-JS + crawlers 7 */ 8( function () { 9 'use strict'; 10 11 var LEADING_NUM_RE = /^\s*\d+\.\s*/; 12 13 function stripLeadingNumber( node ) { 14 if ( ! node ) { return; } 15 var walker = document.createTreeWalker( node, NodeFilter.SHOW_TEXT, null ); 16 var first = walker.nextNode(); 17 if ( first && LEADING_NUM_RE.test( first.nodeValue ) ) { 18 first.nodeValue = first.nodeValue.replace( LEADING_NUM_RE, '' ); 19 } 20 } 21 22 function hydrateBlock( block, blockIndex ) { 23 var sections = block.querySelectorAll( '.schema-faq-section' ); 24 if ( ! sections.length ) { return; } 25 26 sections.forEach( function ( section, idx ) { 27 var question = section.querySelector( '.schema-faq-question' ); 28 var answer = section.querySelector( '.schema-faq-answer' ); 29 if ( ! question || ! answer ) { return; } 30 31 stripLeadingNumber( question ); 32 33 var answerId = answer.id || ( 'gb-faq-' + blockIndex + '-' + idx ); 34 answer.id = answerId; 35 36 section.setAttribute( 'role', 'button' ); 37 section.setAttribute( 'tabindex', '0' ); 38 section.setAttribute( 'aria-controls', answerId ); 39 40 var open = idx < 3; 41 section.classList.toggle( 'is-open', open ); 42 section.setAttribute( 'aria-expanded', open ? 'true' : 'false' ); 43 44 section.addEventListener( 'click', function ( e ) { 45 if ( e.target.tagName === 'A' ) { return; } 46 toggle( section ); 47 } ); 48 49 section.addEventListener( 'keydown', function ( e ) { 50 if ( e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar' ) { 51 e.preventDefault(); 52 toggle( section ); 53 } 54 } ); 55 } ); 56 57 block.classList.add( 'is-ready' ); 58 } 59 60 function toggle( section ) { 61 var open = ! section.classList.contains( 'is-open' ); 62 section.classList.toggle( 'is-open', open ); 63 section.setAttribute( 'aria-expanded', open ? 'true' : 'false' ); 64 } 65 66 function init() { 67 var blocks = document.querySelectorAll( '.wp-block-yoast-faq-block.schema-faq' ); 68 blocks.forEach( hydrateBlock ); 69 } 70 71 if ( document.readyState === 'loading' ) { 72 document.addEventListener( 'DOMContentLoaded', init ); 73 } else { 74 init(); 75 } 76} )();
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.