PageSourceSearch

https://bolenreport.com/wp-content/themes/twentyfifteen/js/functions.js?ver=20250729

js bolenreport.com collected 2026-10-01 13:57:55 UTC 5,048 bytes, 151 lines download raw bytes

1/* global screenReaderText */
2/**
3 * Theme functions file.
4 *
5 * Contains handlers for navigation and widget area.
6 */
7
8( function( $ ) {
9	var $body, $window, $sidebar, resizeTimer,
10		secondary, button;
11
12	function initMainNavigation( container ) {
13		// Add dropdown toggle that display child menu items.
14		container.find( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
15
16		// Toggle buttons and submenu items with active children menu items.
17		container.find( '.current-menu-ancestor > button' ).addClass( 'toggle-on' ).attr( 'aria-expanded', 'true' );
18		container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
19
20		container.find( '.dropdown-toggle' ).on( 'click', function( e ) {
21			var _this = $( this );
22			e.preventDefault();
23			_this.toggleClass( 'toggle-on' );
24			_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
25			_this.attr( 'aria-expanded', _this.hasClass( 'toggle-on' ) ? 'true' : 'false' );
26			_this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
27		} );
28	}
29	initMainNavigation( $( '.main-navigation' ) );
30
31	// Add unique ID to each .sub-menu and aria-controls to parent links
32	function addUniqueIDToSubMenus() {
33		var subMenus = document.querySelectorAll( '.main-navigation .sub-menu' );
34		subMenus.forEach( function( subMenu, index ) {
35			var parentLi = subMenu.closest( 'li.menu-item-has-children' );
36			subMenu.id = 'sub-menu-' + (index + 1);
37			if ( parentLi ) {
38				var parentLink = parentLi.querySelector( 'button' );
39				if ( parentLink ) {
40					parentLink.setAttribute( 'aria-controls', subMenu.id );
41				}
42			}
43		} );
44	}
45
46	addUniqueIDToSubMenus();
47
48	// Re-initialize the main navigation when it is updated, persisting any existing submenu expanded states.
49	$( document ).on( 'customize-preview-menu-refreshed', function( e, params ) {
50		if ( 'primary' === params.wpNavMenuArgs.theme_location ) {
51			initMainNavigation( params.newContainer );
52
53			// Re-sync expanded states from oldContainer.
54			params.oldContainer.find( '.dropdown-toggle.toggle-on' ).each(function() {
55				var containerId = $( this ).parent().prop( 'id' );
56				$( params.newContainer ).find( '#' + containerId + ' > .dropdown-toggle' ).triggerHandler( 'click' );
57			});
58		}
59	});
60
61	secondary = $( '#secondary' );
62	button = $( '.site-branding' ).find( '.secondary-toggle' );
63
64	// Enable menu toggle for small screens.
65	( function() {
66		var menu, widgets, social;
67		if ( ! secondary.length || ! button.length ) {
68			return;
69		}
70
71		// Hide button if there are no widgets and the menus are missing or empty.
72		menu    = secondary.find( '.nav-menu' );
73		widgets = secondary.find( '#widget-area' );
74		social  = secondary.find( '#social-navigation' );
75		if ( ! widgets.length && ! social.length && ( ! menu.length || ! menu.children().length ) ) {
76			button.hide();
77			return;
78		}
79
80		button.on( 'click.twentyfifteen', function() {
81			secondary.toggleClass( 'toggled-on' );
82			secondary.trigger( 'resize' );
83			$( this ).toggleClass( 'toggled-on' );
84			if ( $( this, secondary ).hasClass( 'toggled-on' ) ) {
85				$( this ).attr( 'aria-expanded', 'true' );
86				secondary.attr( 'aria-expanded', 'true' );
87			} else {
88				$( this ).attr( 'aria-expanded', 'false' );
89				secondary.attr( 'aria-expanded', 'false' );
90			}
91		} );
92	} )();
93
94	/**
95	 * Adds or removes ARIA attributes.
96	 *
97	 * Uses jQuery's width() function to determine the size of the window and add
98	 * the default ARIA attributes for the menu toggle if it's visible.
99	 *
100	 * @since Twenty Fifteen 1.1
101	 */
102	function onResizeARIA() {
103		if ( 955 > $window.width() ) {
104			button.attr( 'aria-expanded', 'false' );
105			secondary.attr( 'aria-expanded', 'false' );
106			button.attr( 'aria-controls', 'secondary' );
107		} else {
108			button.removeAttr( 'aria-expanded' );
109			secondary.removeAttr( 'aria-expanded' );
110			button.removeAttr( 'aria-controls' );
111		}
112	}
113
114	// Sidebar scrolling.
115	function resizeAndScroll() {
116		var windowPos = $window.scrollTop(),
117			windowHeight = $window.height(),
118			sidebarHeight = $sidebar.height(),
119			pageHeight = $( '#page' ).height();
120
121		if ( 955 < $window.width() && pageHeight > sidebarHeight && ( windowPos + windowHeight ) >= sidebarHeight ) {
122			$sidebar.css({
123				position: 'fixed',
124				bottom: sidebarHeight > windowHeight ? 0 : 'auto'
125			});
126		} else {
127			$sidebar.css('position', 'relative');
128		}
129	}
130
131	$( function() {
132		$body          = $( document.body );
133		$window        = $( window );
134		$sidebar       = $( '#sidebar' ).first();
135
136		$window
137			.on( 'scroll.twentyfifteen', resizeAndScroll )
138			.on( 'load.twentyfifteen', onResizeARIA )
139			.on( 'resize.twentyfifteen', function() {
140				clearTimeout( resizeTimer );
141				resizeTimer = setTimeout( resizeAndScroll, 500 );
142				onResizeARIA();
143			} );
144		$sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll );
145
146		for ( var i = 0; i < 6; i++ ) {
147			setTimeout( resizeAndScroll, 100 * i );
148		}
149	} );
150
151} )( jQuery );

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.