PageSourceSearch

https://wkup.org/wp-content/themes/wake-up-2026/assets/js/nav.js?ver=1790098898

js wkup.org collected 2026-10-02 03:41:04 UTC 3,128 bytes, 94 lines download raw bytes

1/**
2 * Toggles the header search panel. No framework dependency on purpose —
3 * kept vanilla JS throughout.
4 */
5( function () {
6	var toggle = document.querySelector( '.search-toggle' );
7	var panel = document.getElementById( 'site-search' );
8	if ( ! toggle || ! panel ) {
9		return;
10	}
11	toggle.addEventListener( 'click', function () {
12		var isOpen = ! panel.hidden;
13		panel.hidden = isOpen;
14		toggle.setAttribute( 'aria-expanded', isOpen ? 'false' : 'true' );
15		if ( ! isOpen ) {
16			var field = panel.querySelector( 'input[type="search"]' );
17			if ( field ) {
18				field.focus();
19			}
20		}
21	} );
22} )();
23
24/**
25 * In-page anchor links (e.g. the header's "Newsletter" button linking to
26 * the homepage's signup section) get two fixes here:
27 *
28 * 1. Clicking one while already on the target page is handled entirely
29 *    client-side (scrolled to, URL hash updated) instead of letting the
30 *    browser decide whether that counts as "the same page" — which
31 *    depends on an exact URL match (trailing slash, etc.) and can end
32 *    up looking like a full reload that lands back at the top.
33 * 2. After arriving on a page with a hash in the URL (a fresh load, or
34 *    a link from another page), the scroll position is corrected once
35 *    more after everything — images included — has finished loading.
36 *    A content-heavy homepage still loading images below the target
37 *    section can shift its position after the browser's own initial
38 *    jump, which looks exactly like it never scrolled at all.
39 */
40( function () {
41	function scrollToHash( hash, smooth ) {
42		var target = document.getElementById( hash.replace( '#', '' ) );
43		if ( target ) {
44			target.scrollIntoView( { behavior: smooth ? 'smooth' : 'auto', block: 'start' } );
45		}
46		return target;
47	}
48
49	document.addEventListener( 'click', function ( e ) {
50		var link = e.target.closest ? e.target.closest( 'a[href*="#"]' ) : null;
51		if ( ! link ) {
52			return;
53		}
54		var url;
55		try {
56			url = new URL( link.href, window.location.href );
57		} catch ( err ) {
58			return;
59		}
60		if ( url.pathname !== window.location.pathname || ! url.hash ) {
61			return; // Different page, or no fragment — let it navigate normally.
62		}
63		if ( scrollToHash( url.hash, true ) ) {
64			e.preventDefault();
65			history.pushState( null, '', url.hash );
66		}
67	} );
68
69	window.addEventListener( 'load', function () {
70		if ( window.location.hash ) {
71			scrollToHash( window.location.hash, false );
72		}
73	} );
74} )();
75
76/**
77 * Homepage hero photo carousel: crossfades between whichever recent
78 * post photos PHP found (see wakeup_hero_images() in functions.php).
79 * Pure CSS opacity transition — this just moves the .is-active class
80 * along at an interval. Does nothing if there's only one photo (or
81 * none), so nothing to configure when a site has little content yet.
82 */
83( function () {
84	var photos = document.querySelectorAll( '.hero-photo' );
85	if ( photos.length < 2 ) {
86		return;
87	}
88	var current = 0;
89	setInterval( function () {
90		photos[ current ].classList.remove( 'is-active' );
91		current = ( current + 1 ) % photos.length;
92		photos[ current ].classList.add( 'is-active' );
93	}, 5500 );
94} )();

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.