PageSourceSearch

https://riw.jp/wp-content/themes/belise-lite/js/functions.js?ver=20120206

js riw.jp collected 2026-09-27 07:28:29 UTC 9,630 bytes, 399 lines download raw bytes

1/**
2 * functions.js
3 *
4 * Handles toggling the navigation menu for small screens and enables tab
5 * support for dropdown menus.
6 */
7
8( function($) {
9
10	( function() {
11		var containers = $( '.site-navigation' );
12		if ( containers.length === 0 ) {
13			return;
14		}
15
16		$.each(
17			containers, function(i){
18				var container = containers.eq( i );
19				var button    = container.parent().find( '.menu-toggle' );
20				if ( 'undefined' !== typeof button ) {
21					var menu = container.find( 'ul' );
22					if ( 'undefined' !== typeof menu ) {
23						menu.attr( 'aria-expanded','false' );
24						if ( ! menu.hasClass( 'nav-menu' )) {
25							menu.addClass( 'nav-menu' );
26						}
27						button.click(
28							function(){
29								if (container.hasClass( 'toggled' )) {
30									container.removeClass( 'toggled' );
31									button.attr( 'aria-expanded', 'false' );
32									menu.attr( 'aria-expanded', 'false' );
33								} else {
34									container.addClass( 'toggled' );
35									button.attr( 'aria-expanded', 'true' );
36									menu.attr( 'aria-expanded', 'true' );
37								}
38							}
39						);
40					} else {
41						button.hide();
42					}
43
44					// Get all the link elements within the menu.
45					var links    = menu[ 0 ].getElementsByTagName( 'a' );
46					var subMenus = menu[ 0 ].getElementsByTagName( 'ul' );
47
48					// Set menu items with submenus to aria-haspopup="true".
49					for ( i = 0; i < subMenus.length; i++ ) {
50						subMenus[i].parentNode.setAttribute( 'aria-haspopup', 'true' );
51					}
52
53					// Each time a menu link is focused or blurred, toggle focus.
54					for ( i = 0; i < links.length; i++ ) {
55						links[i].addEventListener( 'focus', toggleFocus, true );
56						links[i].addEventListener( 'blur', toggleFocus, true );
57					}
58				}
59
60			}
61		);
62
63		/**
64		 * Sets or removes .focus class on an element.
65		 */
66		function toggleFocus() {
67			var self = this;
68
69			// Move up through the ancestors of the current link until we hit .nav-menu.
70			while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
71
72				// On li elements toggle the class .focus.
73				if ( 'li' === self.tagName.toLowerCase() ) {
74					if ( -1 !== self.className.indexOf( 'focus' ) ) {
75						self.className = self.className.replace( ' focus', '' );
76					} else {
77						self.className += ' focus';
78					}
79				}
80
81				self = self.parentElement;
82			}
83		}
84	} )();
85
86	$( document ).ready(
87		function() {
88
89				callback_mobile_dropdown();
90				dropdownHorizontalAlign();
91
92		}
93	);
94
95	$( window ).load(
96		function(){
97			'use strict';
98
99			/* PRE LOADER */
100			jQuery( '.status' ).fadeOut();
101			jQuery( '.preloader' ).delay( 1000 ).fadeOut( 'slow' );
102
103		}
104	);
105
106	$( window ).resize(
107		function() {
108
109			dropdownHorizontalAlign();
110
111			/* Hide menu on resize */
112			if ( getWidth() >= 992 ) {
113				if ( $( '.site-navigation' ).hasClass( 'toggled' ) ) {
114					$( '.site-navigation' ).removeClass( 'toggled' );
115				}
116				if ( $( '.site-navigation li.has_children' ).hasClass( 'opened' ) ) {
117					$( '.site-navigation li.has_children' ).removeClass( 'opened' );
118				}
119			}
120
121		}
122	);
123
124	/*** DROPDOWN FOR MOBILE MENU */
125	var callback_mobile_dropdown = function () {
126		var $navLi = $( '#site-navigation li' );
127		$navLi.each(
128			function(){
129				if ( $( this ).find( 'ul' ).length > 0 && ! $( this ).hasClass( 'has_children' ) ) {
130					$( this ).addClass( 'has_children' );
131				}
132			}
133		);
134		$( '.dropdownmenu' ).click(
135			function(){
136				if ( $( this ).parent( 'li' ).hasClass( 'this-open' ) ) {
137					$( this ).parent( 'li' ).removeClass( 'this-open' );
138				} else {
139					$( this ).parent( 'li' ).addClass( 'this-open' );
140				}
141			}
142		);
143	};
144
145	jQuery( document ).ready(
146		function($){
147
148			/* Dropdown menu delay */
149			if ( getWidth() >= 992 ) {
150				var timeout_submenu;
151
152				$( '.main-navigation > div > ul > li' ).on(
153					'mouseleave', function () {
154						var ul          = $( this ).find( '>ul' );
155						timeout_submenu = setTimeout(
156							function () {
157								ul.hide();
158							}, 100
159						);
160					}
161				);
162				$( '.main-navigation > div > ul > li' ).on(
163					'mouseenter', function () {
164						var th = $( this );
165						th.find( '>ul' ).show();
166
167					}
168				);
169
170				$( '.main-navigation > div > ul > li > ul' ).on(
171					'mouseenter', function () {
172						clearTimeout( timeout_submenu );
173					}
174				);
175
176			} else {
177
178				$( '.site-navigation' ).find( '.menu-item-has-children > a' ).after( '<span class="dropdown-toggle"></span>' );
179
180				$( '.dropdown-toggle' ).on(
181					'click', function () {
182						var th = $( this );
183
184						if ( th.parent().hasClass( 'opened' ) ) {
185							th.parent().removeClass( 'opened' );
186							th.removeClass( 'angle-up' );
187						} else {
188							th.parent().addClass( 'opened' );
189							th.addClass( 'angle-up' );
190						}
191
192					}
193				);
194			}
195
196			/* Social icons menu toggle */
197			$( '.social-icons-toggle' ).click(
198				function(){
199					$( '.social-icons-wrapper' ).slideToggle();
200				}
201			);
202		}
203	);
204
205	function dropdownHorizontalAlign() {
206		$( '#site-navigation li.menu-item-has-children , #site-navigation li.page_item_has_children' ).each(
207			function(){
208					var thLi    = $( this ),
209					windowWidth = getWidth(),
210					liOffset    = $( thLi ).offset().left - parseInt( $( '.header-container' ).css( 'margin-left' ) ) + $( thLi ).width() / 2;
211				if ( windowWidth <= ( liOffset + $( thLi ).find( 'ul' ).width() / 2 ) ) {
212					$( thLi ).find( 'ul' ).css( 'left', windowWidth - $( thLi ).find( 'ul' ).width() / 2 );
213				} else {
214					$( thLi ).find( 'ul' ).css( 'left', liOffset );
215				}
216			}
217		);
218	}
219
220	/* Modal */
221	if ( $( '#siteModal' ).hasClass( 'site-modal-open' ) ) {
222		$( '#siteModal' ).modal( 'show' );
223	}
224
225	$( '.open-modal' ).click(
226		function() {
227				$( '#siteModal' ).modal( 'show' );
228		}
229	);
230
231	/* Search field */
232	$( '.top-bar form.search-form' ).submit(
233		function(){
234
235				var form     = $( this ),
236				$searchField = $( '.top-bar form .search-field' );
237
238			if (form.hasClass( 'search-visible' )) {
239
240				return true;
241
242			}
243
244				$searchField.animate(
245					{
246
247						marginLeft: parseInt( $searchField.css( 'marginLeft' ),10 ) === 0 ?
248						$searchField.outerWidth() : 0
249
250					}
251				);
252
253				/* Responsive search form */
254			if ( getWidth() > 992 ) {
255
256				$searchField.parent().parent().addClass( 'search-visible' ).find( '.search-field' ).focus();
257
258				/* Hide search field when click outside on desktop devices */
259				$( '.top-bar form.search-form' ).outside(
260					'click', function() {
261
262						if ( form.hasClass( 'search-visible' ) ) {
263							$searchField.animate(
264								{
265
266									marginLeft: -(parseInt( $searchField.css( 'marginLeft' ) + 10,10 ) === 0 ?
267									$searchField.outerWidth() : 0)
268
269								}
270							);
271
272							form.removeClass( 'search-visible' );
273						}
274					}
275				);
276
277			} else {
278
279				$searchField.parent().parent().addClass( 'search-visible' ).css( 'margin-left', 0 ).find( '.search-field' );
280
281				$searchField.closest( '.top-bar-icons-wrapper' ).find( '.social-icons-toggle' ).animate(
282					{
283						opacity: 0,
284						width: 0,
285						}
286				);
287
288				$searchField.closest( '.top-bar-icons-wrapper' ).find( '.menu-shopping-cart' ).animate(
289					{
290						opacity: 0,
291						width: 0,
292						}
293				);
294
295				if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) {
296					$( 'body' ).addClass( 'belise-cursor-pointer' );
297				}
298
299				/* Hide search field when click outside on mobile devices */
300				$( '.top-bar form.search-form' ).outside(
301					'click', function() {
302						if ( form.hasClass( 'search-visible' ) ) {
303							$searchField.animate(
304								{
305
306									marginLeft: -(parseInt( $searchField.css( 'marginLeft' ),10 ) === 0 ?
307									$searchField.outerWidth() : 0)
308
309								}
310							);
311
312							$searchField.closest( '.top-bar-icons-wrapper' ).find( '.social-icons-toggle' ).animate(
313								{
314									opacity: 100,
315									width: 48,
316								 }
317							);
318
319							$searchField.closest( '.top-bar-icons-wrapper' ).find( '.menu-shopping-cart' ).animate(
320								{
321									opacity: 100,
322									width: 48,
323								 }
324							);
325
326							form.removeClass( 'search-visible' );
327
328							if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) {
329								$( 'body' ).removeClass( 'belise-cursor-pointer' );
330							}
331
332						}
333					}
334				);
335
336			}
337
338				return false;
339		}
340	);
341
342	/* Smooth scroll */
343	$( '#hero a[href*="#"]:not([href="#"])' ).click(
344		function() {
345			if (location.pathname.replace( /^\//,'' ) === this.pathname.replace( /^\//,'' ) && location.hostname === this.hostname) {
346				var target = $( this.hash );
347				target     = target.length ? target : $( '[name=' + this.hash.slice( 1 ) + ']' );
348				if (target.length) {
349					$( 'html, body' ).animate(
350						{
351							scrollTop: target.offset().top
352						}, 500
353					);
354					return false;
355				}
356			}
357		}
358	);
359
360} )( jQuery,window );
361
362
363/* Detecting outside clicks of an element */
364(function($){
365	$.fn.outside = function(ename, cb){
366		return this.each(
367			function(){
368				var self = this;
369
370				$( document ).bind(
371					ename, function tempo(e){
372					if (e.target !== self && ! $.contains( self, e.target )) {
373						cb.apply( self, [e] );
374						if ( ! self.parentNode) {
375							$( document.body ).unbind( ename, tempo );
376						}
377					}
378					}
379				);
380			}
381		);
382	};
383}(jQuery));
384
385
386											/* Get window width depending on the browser */
387											function getWidth() {
388												if (this.innerWidth) {
389													return this.innerWidth;
390												}
391
392												if (document.documentElement && document.documentElement.clientWidth) {
393													return document.documentElement.clientWidth;
394												}
395
396												if (document.body) {
397													return document.body.clientWidth;
398												}
399											}

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.