PageSourceSearch

https://fondani.ru/wp-content/themes/kandinsky/assets/js/scripts.js?ver=eb17f9b3fafd

js fondani.ru collected 2026-10-02 06:29:41 UTC 16,532 bytes, 583 lines download raw bytes

1/* Scripts */
2(function( $ ){
3	"use strict";
4
5	/** Has js **/
6	$( 'html' ).removeClass( 'no-js' ).addClass( 'js' );
7
8	/**
9	 * Add class body on load
10	 */
11	$(window).on('load', function(){
12		$('body').addClass('dom-loaded');
13	});
14
15	/** Window width **/
16	var windowWidth = $( '#top' ).width(),
17		$adminbar = $( '#wpadminbar' ),
18		$siteHeader = $( '#site_header, .knd-header' ),
19		breakPointSmall = 480, // Small screens break point
20		breakPointMedium = 767; // Medium screen break point
21
22	/**
23	 * Get Scrollbar width
24	 */
25	knd.getScrollBarWidth = function() {
26		const scrollbarWidth = window.innerWidth - document.body.clientWidth;
27		document.documentElement.style.setProperty('--scroll-bar-width', scrollbarWidth + 'px');
28	}
29
30	/**
31	 * Open Off-Canvas
32	 */
33	knd.openOffcanvas = function( e ){
34
35		$('.knd-header').addClass('menu-open');
36
37		setTimeout( function(){
38			kndUpdateScreenReaderAlert(knd.i18n.a11y.offCanvasIsOpen);
39			setTimeout( function(){
40				$('.knd-offcanvas-close').focus();
41			},500);
42		},400);
43
44	};
45
46	/**
47	 * Close Off-Canvas
48	 */
49	knd.closeOffcanvas = function( e ){
50
51		if ( $('.knd-header').hasClass( 'menu-open' ) ) {
52			$('.knd-header').removeClass( 'menu-open' );
53
54			$('.main-menu')
55				.find('.menu-item-has-children.open').removeClass('open')
56				.find('.submenu-trigger').attr('aria-expanded', 'false').attr('aria-label', knd.i18n.a11y.expand)
57				.next('.sub-menu').slideUp( 300 );
58
59			var focusButton = true;
60
61			if ( $(e.target).parents('.main-menu').length ) {
62				focusButton = false;
63			}
64
65			setTimeout( function(){
66				kndUpdateScreenReaderAlert(knd.i18n.a11y.offCanvasIsClosed);
67				if ( focusButton ) {
68					setTimeout( function(){
69						$('.knd-header__inner-desktop .knd-offcanvas-toggle').focus();
70					},500);
71				}
72			},400);
73		}
74
75	};
76
77	knd.openSearch= function( e ){
78		$('.knd-search').fadeIn().find('.knd-search__input').focus();
79		$('body').addClass('knd-search-open');
80	};
81
82	knd.closeSearch= function( e ){
83		if ( $('body').hasClass('knd-search-open') ) {
84			$('.knd-search')
85				.fadeOut()
86				.removeAttr('aria-modal')
87				.attr('aria-hidden', 'true' );
88			$('.knd-search-toggle').focus();
89			$('body').removeClass('knd-search-open');
90		}
91	};
92
93	/**
94	 * Accesibility Alert
95	 */
96	function kndUpdateScreenReaderAlert( message ){
97		$('.knd-screen-reader-alert').html( ' ' ).html( message );
98	}
99
100	/**
101	 * Search Open
102	 */
103	$('.knd-search-toggle').on('click', function(e){
104		e.preventDefault();
105		knd.openSearch(e);
106	});
107
108	/**
109	 * Search Close
110	 */
111	$('.knd-search-close').on('click', function(e){
112		e.preventDefault();
113		knd.closeSearch(e);
114	});
115
116	/** Off-Canvas **/
117	$('.knd-offcanvas-toggle').on( 'click', function(e) {
118		e.preventDefault();
119		knd.openOffcanvas(e);
120	});
121
122	$('.knd-offcanvas-close, .nav-overlay').on( 'click', function(e) {
123		e.preventDefault();
124		knd.closeOffcanvas(e);
125	});
126
127	/** Close offcanvas on keydown ESC */
128	$( document ).on( 'keydown', function(e) {
129		if ( 27 === e.keyCode ) {
130			knd.closeOffcanvas(e);
131			knd.closeSearch(e);
132		}
133	});
134
135	/** Submenu toggle  **/
136	$( '.submenu-trigger' ).on( 'click', function( e ) {
137		e.preventDefault();
138
139		var thisParent = $(this).parent('.menu-item-has-children');
140
141		if ( thisParent.hasClass('open') ) {
142			$(this).attr('aria-expanded', 'false').attr('aria-label', knd.i18n.a11y.expand);
143			$(this).next('.sub-menu' ).slideUp( 300, function(){
144				thisParent.removeClass('open');
145			});
146		} else {
147			$(this).attr('aria-expanded', 'true').attr('aria-label', knd.i18n.a11y.collapse);
148			thisParent.addClass('open');
149			$(this).next('.sub-menu' ).slideDown( 300 );
150		}
151
152	});
153
154	// Dropdown menu Accesibility.
155	$('.dropdown-nav-toggle').on('click', function(e){
156		e.preventDefault();
157		$(this).parent('.menu-item-has-children').toggleClass('focus');
158		if ( $(this).parent('.menu-item-has-children').hasClass('focus') ) {
159			$(this).attr('aria-expanded', 'true').attr('aria-label', knd.i18n.a11y.collapse);
160		} else {
161			$(this).attr('aria-expanded', 'false').attr('aria-label', knd.i18n.a11y.expand);
162		}
163	});
164
165	// Close dropdown menu on focusout.
166	$('.menu-item-has-children').on('focusout', function (e) {
167		var $elem = $(this);
168		setTimeout( function() {
169			var hasFocus = !! ($elem.find(':focus').length > 0);
170			if (! hasFocus) {
171				$elem.removeClass('focus')
172				$elem.find('.dropdown-nav-toggle').attr('aria-expanded', 'false').attr('aria-label', knd.i18n.a11y.expand);
173			}
174		}, 10);
175	});
176
177	/** Sticky elements **/
178	var position = $( window ).scrollTop(), //store intitial scroll position
179		scrollTopLimit = ($( 'body' ).hasClass( 'adminbar' )) ? 99 + 32 + 90 : 99 + 90,
180		fixedTopPosition = ($( 'body' ).hasClass( 'adminbar' )) ? 99 + 32 + 90 : 99 + 90;
181
182	$( window ).scroll(function() {
183		var scroll = $( window ).scrollTop(),
184			winW = $( '#top' ).width();
185
186		//no scroll when menu is open
187		if ( $siteHeader.hasClass( 'menu-open' ) ) {
188			$( window ).scrollTop( position );
189			return;
190		}
191
192		//scroll tolerance 3px and ignore out of boundaries scroll
193		if ( (Math.abs( scroll - position ) < 3) || kndScrollOutOfBounds( scroll ) ) {
194			return true;
195		}
196		
197		//stick header
198		if (scroll < position) { //upword
199			$siteHeader.removeClass('invisible').addClass('fixed-header');
200		}
201		else if(scroll >= scrollTopLimit) {
202			$siteHeader.removeClass('fixed-header').addClass('invisible');
203		}
204		else {
205			$siteHeader.removeClass('fixed-header').removeClass('invisible');
206		}
207		
208		//sticky sharing
209		if ( winW >= breakPointMedium && $( '#knd_sharing' ).length > 0 ) {
210			stickInParent( '#knd_sharing .social-likes-wrapper', '#knd_sharing', position, fixedTopPosition );
211		}
212
213		//kndSetupHeaderForSmallScreens();
214
215		position = scroll; //upd scroll position
216		return true;
217	});
218
219	/** Resize event **/
220	$( window ).resize(function() {
221		var winW = $( '#top' ).width();
222
223		if ( winW < breakPointMedium && $siteHeader.hasClass( 'newsletter-open' ) ) {
224			$siteHeader.removeClass( 'newsletter-open' );
225		}
226
227		//kndSetupHeaderForSmallScreens();
228	});
229
230	function kndSetupHeaderForSmallScreens() {
231		var scroll = $( window ).scrollTop(),
232			adminbarHeight = $adminbar.height();
233
234		if ( 'absolute' === $adminbar.css( 'position' ) ) {
235			if ( scroll > adminbarHeight ) {
236				$siteHeader.css( 'top', '0px' );
237			} else {
238				$siteHeader.css( 'top', '' + (adminbarHeight - scroll) + 'px' );
239			}
240		} else {
241			$siteHeader.css( 'top', '' );
242		}
243	}
244
245	// Stick element on scroll
246	function stickInParent( element, elementParent, elementPosition, elementFixedTopPosition ) {
247		var scroll = $( window ).scrollTop(),
248			$element = $( element ),
249			$elementParent = $( elementParent ),
250			topPos = $elementParent.offset().top,
251			height = $elementParent.outerHeight();
252
253		// Stick on bottom
254		if ( scroll > ((height + topPos) - $element.outerHeight() - elementFixedTopPosition) ) {
255			// Scroll down
256			if ( scroll > elementPosition ) {
257				$element.addClass( 'fixed-bottom' ).removeClass( 'fixed-top' );
258			}
259		} else if ( scroll > height + topPos - $element.outerHeight() - elementFixedTopPosition ) {
260			// Unstick on bottom
261			if ( scroll < elementPosition ) {
262				$element.removeClass( 'fixed-bottom' ).addClass( 'fixed-top' );
263			}
264		} else if ( scroll > topPos - elementFixedTopPosition ) { //stick on top
265			$element.removeClass( 'fixed-bottom' ).addClass( 'fixed-top' );
266		} else {
267			$element.removeClass( 'fixed-bottom' ).removeClass( 'fixed-top' ); //normal position
268		}
269	}
270
271	// Determines if the scroll position is outside of document boundaries
272	function kndScrollOutOfBounds( scroll ) {
273		return scroll < 0 || scroll > $( document ).height() + $( window ).height();
274	}
275
276	/** Responsive media **/
277	function kndResponsiveEmbeds() {
278		var proportion, parentWidth;
279
280		// Loop iframe elements.
281		document.querySelectorAll( 'iframe' ).forEach( function( iframe ) {
282			// Only continue if the iframe has a width & height defined.
283			if ( iframe.width && iframe.height ) {
284				// Calculate the proportion/ratio based on the width & height.
285				proportion = parseFloat( iframe.width ) / parseFloat( iframe.height );
286				// Get the parent element's width.
287				parentWidth = parseFloat( window.getComputedStyle( iframe.parentElement, null ).width.replace( 'px', '' ) );
288				// Set the max-width & height.
289				iframe.style.maxWidth = '100%';
290				iframe.style.maxHeight = Math.round( parentWidth / proportion ).toString() + 'px';
291			}
292		} );
293	}
294
295	// Run on initial load.
296	kndResponsiveEmbeds();
297
298	// Run on resize.
299	window.onresize = kndResponsiveEmbeds;
300
301	/**
302	 * Scroll To Element on click link with hash
303	 */
304	// a[href^="#"]
305	$( '.knd-nav-menu a, .main-menu a, .knd-toc a' ).on( 'click', function( e ) {
306
307		var lacationUrl = window.location.href.replace(/#.*$/, '');
308		var thisUrl     = this.href.replace(/#.*$/, '');
309
310		var offset = 0;
311		if ( $('#wpadminbar').length ) {
312			var adminbarHeight = $('#wpadminbar').height();
313			//console.log.style.position;
314			offset = adminbarHeight;
315		}
316
317		if ( this.hash && lacationUrl === thisUrl ) {
318
319			var target = $( this.hash ).offset();
320			if ( target) {
321
322				$( 'body, html' ).animate( {
323					scrollTop: target.top - offset
324				}, 400 );
325
326				if ( $(this).parents('.main-menu') ) {
327					window.knd.closeOffcanvas(e);
328				}
329
330			}
331
332			$( this ).blur();
333			e.preventDefault();
334		}
335
336	});
337
338	/**
339	 * Scroll To Element on window load
340	 */
341	$(window).on('load', function(){
342		if ( window.location.hash ) {
343			var target = $( window.location.hash ).offset();
344			if ( target) {
345
346				var offset = 0;
347				if ( $('#wpadminbar').length ) {
348					var adminbarHeight = $('#wpadminbar').height();
349					offset = adminbarHeight;
350				}
351
352				$( 'body, html' ).animate( {
353					scrollTop: target.top - offset
354				}, 400 );
355			}
356		}
357	});
358
359	/**
360	 * Scroll To Top Button
361	 */
362	$( document ).ready( function() {
363
364		var btnToTop = $( '.knd-to-top' );
365
366		$( window ).scroll( function() {
367			var offset = $( 'body' ).innerHeight() * 0.1;
368
369			if ( $( this ).scrollTop() > offset ) {
370				btnToTop.addClass( 'active' );
371			} else {
372				btnToTop.removeClass( 'active' );
373			}
374		} );
375
376		btnToTop.on( 'click', function() {
377
378			$( this ).blur();
379
380			$( 'body, html' ).animate( {
381				scrollTop: 0
382			}, 400 );
383
384			return false;
385		} );
386	} );
387
388	/**
389	 * FancyBox
390	 */
391	if ( $('#knd-fancybox-js').length) {
392		$('.entry-content .wp-block-image').find('a[href$=".jpg"], a[href$=".png"], a[href$=".jpeg"], a[href$=".gif"]').attr('data-fancybox','');
393
394		$( '.entry-content' ).find('a[href$=".jpg"], a[href$=".png"], a[href$=".jpeg"], a[href$=".gif"]').each( function( index ) {
395			if ( $(this).parents('.wp-block-image').length == 0 && $(this).parents('.wp-block-gallery').length == 0 ) {
396				$(this).attr('data-fancybox', '');
397			}
398		});
399
400		$('.entry-content .wp-block-gallery, .entry-content .gallery').each( function( index ) {
401			$( this ).find('a[href$=".jpg"], a[href$=".png"], a[href$=".jpeg"], a[href$=".gif"]').attr('data-fancybox', 'gallery-' + ( index + 1 ) );
402		});
403	}
404
405	/**
406	 * Archive Events View Type
407	 */
408	$('.knd-events__layouts > a').on( 'click', function( e ) {
409		e.preventDefault();
410		$(this).siblings('a').removeClass('active');
411		$(this).addClass('active');
412		var thisType = $(this).data('type');
413		$('.knd-events__main').addClass('knd-events__animate');
414		setTimeout( function(){
415			if ( 'grid' == thisType ) {
416				$('.knd-events__main').addClass('knd-events__grid');
417			} else {
418				$('.knd-events__main').removeClass('knd-events__grid');
419			}
420			$('.knd-events__main').removeClass('knd-events__animate');
421		}, 500 );
422		document.cookie = 'kndArchiveType=' + thisType + ';path=/';
423	});
424
425	/**
426	 * Sinble Events View Type
427	 */
428	$('.knd-event__cta-button').on( 'click', function( e ) {
429		e.preventDefault();
430		$('html, body').animate({
431			scrollTop: $('.knd-event__booking').offset().top - 50
432		}, 1000);
433	});
434
435	/**
436	 * Sinble Events View Type
437	 */
438	$('.knd-event__login-toggle a').on( 'click', function( e ) {
439		e.preventDefault();
440		$('.knd-event__login-form').slideToggle();
441	});
442
443	$(window).on('load resize', function () {
444		$( '.knd-block-carousel' ).flickity( 'resize' );
445	});
446
447	$('.knd-block-carousel').on( 'ready.flickity select.flickity', function( event ) {
448		var allSlides    = $(this).find('.flickity-slider .knd-block-item').length;
449		var activeSlides = $(this).find('.flickity-slider .knd-block-item.is-selected').length;
450		var sliderArrows = $(this).find('.flickity-button');
451		if ( Number( activeSlides ) < Number( allSlides ) ) {
452			sliderArrows.removeClass('flickity-button-hidden');
453		} else {
454			sliderArrows.addClass('flickity-button-hidden');
455		}
456	});
457
458	// Focus repeat in container.
459	function kndFocusInModal( selector ){
460
461		// add all the elements inside modal which you want to make focusable
462		const focusableElements = 'button, [href]:not([aria-hidden="true"]), input, [tabindex]:not
462([tabindex="-1"])';
463
464		const modal = document.querySelector( selector ); // select the modal by it's id
465
466		if ( ! modal ) {
467			return;
468		}
469
470		const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal
471		const focusableContent = modal.querySelectorAll(focusableElements);
472		const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal
473
474		document.addEventListener('keydown', function(e) {
475			let isTabPressed = e.key === 'Tab' || e.keyCode === 9;
476
477			if (!isTabPressed) {
478				return;
479			}
480
481			if (e.shiftKey) { // if shift key pressed for shift + tab combination
482				if (document.activeElement === firstFocusableElement) {
483					lastFocusableElement.focus(); // add focus for the last focusable element
484					e.preventDefault();
485				}
486			} else { // if tab key is pressed
487				if (document.activeElement === lastFocusableElement) { // if focused has reached to last focusable element then focus first focusable element after pressing tab
488					firstFocusableElement.focus();
488 // add focus for the first focusable element
489					e.preventDefault();
490				}
491			}
492		});
493
494		firstFocusableElement.focus();
495	}
496
497	kndFocusInModal( '.site-nav' );
498	kndFocusInModal( '.knd-search' );
499
500	knd.getScrollBarWidth();
501
502	$('[href="#knd-remove-all-hints"]').on('click', function(e){
503		e.preventDefault();
504
505		var data = {
506			'nonce':   knd.nonce,
507			'action': 'knd_remove_all_hints',
508		};
509
510		$.post( knd.ajaxurl, data, function(response) {
511			console.log(response);
512			if ( response.success === true ) {
513				window.location.reload();
514			}
515		});
516	});
517
518	/**
519	 * Keeping sub menu inside screen
520	 */
521	function kndSubmenuLeft(){
522		var subMenus = $('.knd-header-nav .menu-item-has-children > .sub-menu');
523		subMenus.each(function( index ) {
524			var subMenuLeft = $(this).offset().left;
525			if ( subMenuLeft + $(this).outerWidth() > $(window).width()) {
526				$(this).addClass('sub-menu-left');
527			}
528		});
529	}
530
531	$(window).on('resize', function(){
532		kndSubmenuLeft();
533	});
534
535	/** Collapse long menu */
536	function kndTruncateMenu() {
537		var menuContainer = $('.knd-header-nav-truncate');
538		var menu = menuContainer.find('.knd-nav-menu');
539		var moreMenuItem = menu.find('.more-menu-item');
540
541		menuContainer.addClass('truncate-hidden');
542
543		if (moreMenuItem.length) {
544			var moreSubMenu = moreMenuItem.find('> ul');
545			moreSubMenu.children().insertBefore(moreMenuItem);
546			moreMenuItem.remove();
547		}
548
549		var moreMenuItemHtml = `
550			<li class="menu-item-has-children more-menu-item">
551				<a href="#">
552					<span></span>
553				</a>
554				<ul class="sub-menu"></ul>
555			</li>`;
556		
557		menu.append(moreMenuItemHtml);
558
559		var totalWidth = 0;
560		var maxWidth = menu.width() - 60;
561		var menuItems = menu.children('li:not(.more-menu-item)');
562
563		menuItems.each(function() {
564			totalWidth += $(this).outerWidth(true);
565
566			if (totalWidth > maxWidth) {
567				menu.find('.more-menu-item > ul').append($(this));
568			}
569		});
570
571		menuContainer.removeClass('truncate-hidden');
572
573		if (menu.find('.more-menu-item > ul').children().length === 0) {
574			menu.find('.more-menu-item').remove();
575		}
576		kndSubmenuLeft();
577	}
578
579	kndTruncateMenu();
580
581	$(window).resize(kndTruncateMenu);
582
583})( 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.