PageSourceSearch

https://americasvoice.org/wp-content/themes/amvoice2020/assets/js/functions.js?ver=1790272619

js americasvoice.org collected 2026-09-24 18:06:26 UTC 10,604 bytes, 362 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, adminbarOffset, top = false,
10	    bottom = false, windowWidth, windowHeight, lastWindowPos = 0,
11	    topOffset = 0, bodyHeight, sidebarHeight, resizeTimer,
12		secondary, button;
13
14
15	function textFitUpdater() {
16		var width = $(window).width();
17		if(width > 576){
18			textFit(document.getElementsByClassName('tflarge'), {
19				widthOnly: true,
20				maxFontSize: 50,
21				alignHoriz: true,
22				alignVertWithFlexbox: true
23			});
24			textFit(document.getElementsByClassName('tfsmall'), {
25				widthOnly: true,
26				maxFontSize: 29,
27				alignHoriz: true,
28				alignVertWithFlexbox: true
29			});
30		} else {
31			$('.hp-fact span, .hp-fact strong').removeAttr('style');
32		}
33	}
34
35	// Add dropdown toggle that display child menu items.
36	$( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
37
38	// Toggle buttons and submenu items with active children menu items.
39	$( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
40	$( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
41
42	$( '.dropdown-toggle' ).click( function( e ) {
43		var _this = $( this );
44		e.preventDefault();
45		_this.toggleClass( 'toggle-on' );
46		_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
47		_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
48		_this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
49	} );
50
51	secondary = $( '#secondary' );
52	button = $( '.site-branding' ).find( '.secondary-toggle' );
53
54	// Enable menu toggle for small screens.
55	( function() {
56		var menu, widgets, social;
57		if ( ! secondary || ! button ) {
58			return;
59		}
60
61		// Hide button if there are no widgets and the menus are missing or empty.
62		menu    = secondary.find( '.nav-menu' );
63		widgets = secondary.find( '#widget-area' );
64		social  = secondary.find( '#social-navigation' );
65		if ( ! widgets.length && ! social.length && ( ! menu || ! menu.children().length ) ) {
66			button.hide();
67			return;
68		}
69
70		button.on( 'click.amvoice2020', function() {
71			secondary.toggleClass( 'toggled-on' );
72			secondary.trigger( 'resize' );
73			$( this ).toggleClass( 'toggled-on' );
74			if ( $( this, secondary ).hasClass( 'toggled-on' ) ) {
75				$( this ).attr( 'aria-expanded', 'true' );
76				secondary.attr( 'aria-expanded', 'true' );
77			} else {
78				$( this ).attr( 'aria-expanded', 'false' );
79				secondary.attr( 'aria-expanded', 'false' );
80			}
81		} );
82	} )();
83
84	$(document).on('click', 'a.jump', function (event) {
85		event.preventDefault();
86
87		$('html, body').animate({
88			scrollTop: $($.attr(this, 'href')).offset().top
89		}, 1000, 'easeInOutQuad');
90	});
91
92
93	/**
94	 * @summary Add or remove ARIA attributes.
95	 * Uses jQuery's width() function to determine the size of the window and add
96	 * the default ARIA attributes for the menu toggle if it's visible.
97	 * @since America's Voice 2020.0
98	 */
99	function onResizeARIA() {
100		if ( 955 > $window.width() ) {
101			button.attr( 'aria-expanded', 'false' );
102			secondary.attr( 'aria-expanded', 'false' );
103			button.attr( 'aria-controls', 'secondary' );
104		} else {
105			button.removeAttr( 'aria-expanded' );
106			secondary.removeAttr( 'aria-expanded' );
107			button.removeAttr( 'aria-controls' );
108		}
109	}
110
111	// Sidebar scrolling.
112	function resize() {
113		windowWidth = $window.width();
114
115		if ( 955 > windowWidth ) {
116			top = bottom = false;
117			$sidebar.removeAttr( 'style' );
118		}
119	}
120
121	function scroll() {
122		var windowPos = $window.scrollTop();
123
124		if ( 955 > windowWidth ) {
125			return;
126		}
127
128		sidebarHeight = $sidebar.height();
129		windowHeight  = $window.height();
130		bodyHeight    = $body.height();
131
132		if ( sidebarHeight + adminbarOffset > windowHeight ) {
133			if ( windowPos > lastWindowPos ) {
134				if ( top ) {
135					top = false;
136					topOffset = ( $sidebar.offset().top >
136 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
137					$sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
138				} else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) {
139					bottom = true;
140					$sidebar.attr( 'style', 'position: fixed; bottom: 0;' );
141				}
142			} else if ( windowPos < lastWindowPos ) {
143				if ( bottom ) {
144					bottom = false;
145					topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
146					$sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
147				} else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) {
148					top = true;
149					$sidebar.attr( 'style', 'position: fixed;' );
150				}
151			} else {
152				top = bottom = false;
153				topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
154				$sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
155			}
156		} else if ( ! top ) {
157			top = true;
158			$sidebar.attr( 'style', 'position: fixed;' );
159		}
160
161		lastWindowPos = windowPos;
162	}
163
164	function resizeAndScroll() {
165		resize();
166		scroll();
167	}
168
169	$( document ).ready( function() {
170		$body          = $( document.body );
171		$window        = $( window );
172		$sidebar       = $( '#sidebar' ).first();
173		adminbarOffset = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
174
175		// Scaling text based facts
176		textFitUpdater();
177
178		$window
179			.on( 'scroll.amvoice2020', scroll )
180			.on( 'load.amvoice2020', onResizeARIA )
181			.on( 'resize.amvoice2020', function() {
182				clearTimeout( resizeTimer );
183				resizeTimer = setTimeout( resizeAndScroll, 500 );
184				onResizeARIA();
185			} );
186		$sidebar.on( 'click.amvoice2020 keydown.amvoice2020', 'button', resizeAndScroll );
187
188		resizeAndScroll();
189
190		for ( var i = 1; i < 6; i++ ) {
191			setTimeout( resizeAndScroll, 100 * i );
192		}
193
194
195		// Form Animations
196		$('input').focus(function(){
197			$(this).parents('.form-group').addClass('focused');
198		});
199		$('input').blur(function(){
200			var inputValue = $(this).val();
201			if ( inputValue == "" ) {
202				$(this).removeClass('filled');
203				$(this).parents('.form-group').removeClass('focused');
204			} else {
205				$(this).addClass('filled');
206			}
207		});
208
209
210		// Search Bar Reveal
211		$('#search-display').on('click', function(event){
212			$('#search-form').removeClass('hidden');
213			$('#search-field').focus();
214		});
215
216		// Click off search field to hide it again
217		$(document).mouseup(function(event){
218			var searchContainer = $("#search-form");
219			if (!searchContainer.is(event.target) && searchContainer.has(event.target).length === 0) {
220				$('#search-form').addClass('hidden');
221			}
222		});
223
224		// Hide search on escape button press too
225		document.onkeydown = function(evt) {
226			evt = evt || window.event;
227			var isEscape = false;
228			if ("key" in evt) {
229				isEscape = (evt.key === "Escape" || evt.key === "Esc");
230			} else {
231				isEscape = (evt.keyCode === 27);
232			}
233			if (isEscape && !$('#search-form').hasClass('hidden')){
234				$('#search-form').addClass('hidden');
235			}
236		};
237
238		/**
239		 * Mobile Menu Toggle
240		 */
241		$('#mobile-menu-button').on('click',function(e){
242			e.preventDefault();
243
244			// Toggle the active class
245			$('body').toggleClass('mobile-menu-active');
246
247			// Aria toggles
248			$(this).attr('aria-expanded', function (i, attr) {
249				return attr == 'true' ? 'false' : 'true'
250			});
251
252			// Toggle the text
253			var text = $('#mobile-menu-button .text').text();
254			$('#mobile-menu-button .text').text(text == 'Menu' ? 'Close' : 'Menu');
255		});
256
257		/**
258		 * Blog Archive Expansion List
259		 */
260		//$('#archive-list-all li').eq(19).after('</ol><ol class="archive-list" id="archive-list-more" style="display: none;">');
261		var archiveCounter = 1;
262		$('#archive-list-all li').each(function(){
263			if(archiveCounter > 20){
264				$(this).addClass('expand hide');
265			}
266			archiveCounter++;
267		});
268		$(document).on('click', '#archive-expand', function(){
269			$('#archive-list-all li.expand').toggleClass('hide');
270			$('#archive-expand').text(function(i, text){
271				return text === "SEE LESS" ? "SEE MORE" : "SEE LESS";
272			});
273		});
274
275
276    //Video carousel
277    //Active thumbnail state
278      $(function() {
279        $('.slick-current .video-slide:first').addClass('feature-loaded');
280      });
281
282      $('.featured-video').slick({
283       slidesToShow: 1,
284       slidesToScroll: 1,
285       arrows: false,
286       fade: true,
287       asNavFor: '.video-carousel'
288     });
289     $('.video-carousel').slick({
290       slidesToShow: 3,
291       slidesToScroll: 1,
292       asNavFor: '.featured-video',
293       dots: true,
294       focusOnSelect: true,
295       responsive: [
296        {
297          breakpoint: 1024,
298          settings: {
299            slidesToShow: 3,
300            slidesToScroll: 1,
301            infinite: true,
302            dots: true
303          }
304        },
305        {
306          breakpoint: 967,
307          settings: {
308            slidesToShow: 2,
309            slidesToScroll: 1
310          }
311        },
312        {
313          breakpoint: 480,
314          settings: {
315            slidesToShow: 1,
316            slidesToScroll: 1
317          }
318        }
319      ]
320     });
321
322     $('.video-slide button').on('click', function(e){
323       e.preventDefault();
324
325       console.log(this);
326       let bid = $(this).attr('data-slide-id');
327       // let iframe = $('textarea[data-slide-id="'+bid+'"]').val();
328       // $('.featured-video .responsive-video').html(iframe);
329       $('.video-slide').removeClass('feature-loaded');
330       $(this).parent('.video-slide').addClass('feature-loaded');
331       console.log(bid);
332       // console.log(iframe);
333     });
334     $('.slick-prev').on('click', function(e){
335       console.log(this);
336        $('.video-slide').removeClass('feature-loaded');
337     });
338     $('.slick-next').on('click', function(e){
339       console.log(this);
340        $('.video-slide').removeClass('feature-loaded');
341     });
342
343
344		// Social Share Dialogs
345		$('a.social-share').click(function(e){
346			e.preventDefault();
347			var url = $(this).attr('href');
348			window.open(url, '_blank', 'toolbar=yes, scrollbars=yes, resizable=no, top=200, left=200, width=570, height=400');
349		});
350
351	} );
352
353	/**
354	 * Window Resize Functions
355	 */
356	$(window).resize(function() {
357
358		textFitUpdater();
359
360	});
361
362} )( 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.