PageSourceSearch

https://dhsprogram.com/js/icf-responsive.js

js dhsprogram.com collected 2026-09-24 08:31:56 UTC 4,991 bytes, 244 lines download raw bytes

1/* icf-responsive.js */
2var gRemoveTries = 0;
3var gTime = performance.now();
4var gIsUsingTouch = false;
5
6
7$( document ).ready(function() {
8
9	setupMouseTouchHandling();
10	
11	// enable font-awesome to be used in suedo classes
12	FontAwesomeConfig = { searchPseudoElements: true };
13
14   // Mobile menu toggles
15   $('.mobile-menu-toggle').click(function() {
16		if( $(this).hasClass('active') ) 
17			closeMenu();
18      else 
19		{
20			closeSearchBox();
21			openMenu();
22		}
23			
24      return false;
25   });
26
27
28	/* menu click */	 
29	$('#primary-navigation > ul > li').on('click', function(){ 
30
31	 	// get URL
32	 	ul = $(this).find('ul');
33	 	
34	 	// expand / collapse nav.
35		if( $(this).hasClass('expanded') )
36		{
37			closeSubMenu(ul,this);
38		}
39		else
40		{
41			// close any other open menu
42			$('#primary-navigation > ul > li.expanded').each( function(){
43	 			var sub_ul = $(this).find('ul');
44				closeSubMenu(sub_ul,this);
45			});			
46
47			closeSearchBox();
48			
49			openSubMenu(ul,this);
50		}
51	});
52	 
53/*
54	// Click Search
55	$('#quick-links li:first-child').on('click', function(){
56debugger;
57		if( $('#search-box').hasClass('shown') )
58			closeSearchBox();
59		else
60		{
61			closeMenu();
62			openSearchBox();		
63		}
64	});	 
65	
66	// Close search box close
67	$('#search-box i').on('click', function(){
68		closeSearchBox();		
69	});
70*/
71
72	/* 2018-11-30 ssmith Commented out this function since it no longer works with the current version of Google Translate */
73	/* setTimeout( removeGoogleTranslateText, 500 ); */
74	 
75});
76
77/*  moved to all pages
78function closeSearchBox() 			
79{
80	$('#search-box').removeClass('shown');
81	$('#search-box').hide();
82}
83function openSearchBox() 			
84{
85	$('#search-box').addClass('shown');
86	$('#search-box').show();
87}
88*/
89
90function closeMenu()
91{
92	$('.mobile-menu-toggle').removeClass('active');
93	$('#primary-navigation').removeClass('active');
94}
95
96function openMenu() 
97{
98	$('.mobile-menu-toggle').addClass('active');
99	$('#primary-navigation').addClass('active');
100	
101	setOuterHeight(200);
102}
103
104
105function closeSubMenu(ul,el)
106{
107	// Remove Overview Menu
108   if( gIsUsingTouch )
109   	$(ul).find('.overview').remove();
110
111	// collapse
112	$(ul).css('visibility','hidden');
113	// $(ul).css('max-height',0);
114	$(el).removeClass('expanded');
115	// $(ul).css('max-height',0);
116	setTimeout( function(){ 
117		$(ul).css('visibility','visible');
118		setOuterHeight(100);
119	}, 100);
120}
121
122
123function openSubMenu(ul, el)
124{
125	// create new Overview Menu
126   if( gIsUsingTouch )
127   {
128   	var href = $(el).find('a').attr('data-h');
129   	$(ul).prepend('<li class="overview"><a href="' + href + '">Overview</a></li>');
130   }
131   
132	$(el).addClass('expanded');
133	
134	setOuterHeight(200);
135}
136
137
138function setOuterHeight(wait)
139{
140	setTimeout( function(){
141		var h = $('#primary-navigation > ul').height();
142		$('#primary-navigation').height( h );
143	}, wait );
144}
145
146/* 2018-11-30 ssmith Commented out this function since it no longer works with the current version of Google Translate */
147/*
148function removeGoogleTranslateText()
149{
150	if( gRemoveTries > 20 )
151		return;
152	gRemoveTries++;	
153	
154	var el = $('div.skiptranslate.goog-te-gadget');
155	if( el.length )
156	{
157		var html = el.html().toLowerCase(); 
158		if( html.indexOf('powered by') >= 0 )
159		{
160			html = $('div.skiptranslate.goog-te-gadget > div').html();
161			$('div.skiptranslate.goog-te-gadget').html(html);
162		}
163	}	
164	else
165	{
166		setTimeout( removeGoogleTranslateText, 500 );
167	}	
168}
169*/
170
171function checkSearchOptions()
172{
173}
174
175
176
177function setupMouseTouchHandling()
178{
179	// take main menu's hrefs and move them to data attributes
180	$('#primary-navigation > ul > li > a').each( function(event) {
181		var href = $(this).attr('href');
182		$(this).attr('data-h',href);
183		$(this).attr('href','#');		
184	});
185		
186	
187	// Handle Main Menu click
188	$('#primary-navigation > ul > li > a').click( function(event) {
189	
190		// if touch, do nothing - let propigate up to LI
191		if( $('#primary-navigation').hasClass('touch') )
192		{
193			return true;	
194		}
195		else	// get href and go there
196		{
197			var href = $(this).data('h');
198			window.location.href = href;
199			return false;
200		}
201	});
202
203	// Open touch emulator
204	var supportsTouch = true; //'ontouchstart' in window;
205	
206	
207	// add listeners
208	if( supportsTouch ) 
209	  document.addEventListener('touchstart', touchHandler);
210	else if (navigator.maxTouchPoints || navigator.msMaxTouchPoints) 
211	  document.addEventListener('pointerdown', touchHandler);
212}
213
214
215// `touchstart`, `pointerdown`
216function touchHandler() 
217{
218  gIsUsingTouch = true;
219  // You ARE using touch....
220  $('#primary-navigation').addClass('touch');
221  document.addEventListener('mousemove', mousemoveHandler);
222};
223
224
225// use a simple closure to store previous time as internal state
226function mousemoveHandler ()
227{
228  	var now = performance.now();
229	
230   if( now - gTime < 20 ) 
231	{
232      gIsUsingTouch = false;
233     
234		// You are NOT using touch...
235		$('#primary-navigation').removeClass('touch');
236		
237		// remove any overview menus added
238		$('#primary-navigation ul.child-navigation li.overview').remove();
239		
240      document.removeEventListener('mousemove', mousemoveHandler);
241   }
242
243   gTime = now;
244}

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.