ACC SHELL

Path : /srv/www/vhosts/laboserv/wp-content/themes/laboserv2020/js/
File Upload :
Current File : //srv/www/vhosts/laboserv/wp-content/themes/laboserv2020/js/functions.js

/* global screenReaderText */
/**
 * Theme functions file.
 *
 * Contains handlers for navigation and widget area.
 */

( function( $ ) {
	var body, masthead, menuToggle, siteNavigation, socialNavigation, siteHeaderMenu, resizeTimer;
	
	// sirka stranky
	var windowWidth = $( window ).outerWidth();
	
	// sirka produktu
	var prodWidth = $( 'section.products article.product-item' ).outerWidth();
	// sirka nabidky
	var offerWidth = $( 'section.month_offer article.offer' ).outerWidth();
	// pocet nabidek
	var	numOffers = $( 'section.month_offer article.offer' ).length;
	var offerVisible = $( 'section.month_offer article.offer' ).length;
	
	var showOffer = readCookie( 'showOffer' );
	
	var scrollProducts = null;
	
	/*
	function initMainNavigation( container ) {

		// Add dropdown toggle that displays child menu items.
		var dropdownToggle = $( '<button />', {
			'class': 'dropdown-toggle',
			'aria-expanded': false
		} ).append( $( '<span />', {
			'class': 'screen-reader-text',
			text: screenReaderText.expand
		} ) );

		container.find( '.menu-item-has-children > a' ).after( dropdownToggle );

		// Toggle buttons and submenu items with active children menu items.
		container.find( '.current-menu-ancestor > button' ).addClass( 'toggled-on' );
		container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );

		// Add menu items with submenus to aria-haspopup="true".
		container.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' );

		container.find( '.dropdown-toggle' ).click( function( e ) {
			var _this            = $( this ),
				screenReaderSpan = _this.find( '.screen-reader-text' );

			e.preventDefault();
			_this.toggleClass( 'toggled-on' );
			_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );

			// jscs:disable
			_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
			// jscs:enable
			screenReaderSpan.text( screenReaderSpan.text() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
		} );
	}
	initMainNavigation( $( '.main-navigation' ) );*/

	masthead         = $( '#masthead' );
	menuToggle       = masthead.find( '#menu-toggle' );
	siteHeaderMenu   = masthead.find( '#site-header-menu' );
	siteNavigation   = masthead.find( '#site-navigation' );
	socialNavigation = masthead.find( '#social-navigation' );

	// Enable menuToggle.
	( function() {

		// Return early if menuToggle is missing.
		if ( ! menuToggle.length ) {
			return;
		}

		// Add an initial values for the attribute.
		menuToggle.add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded', 'false' );

		menuToggle.on( 'click.twentysixteen', function() {
			$( this ).add( siteHeaderMenu ).toggleClass( 'toggled-on' );

			// jscs:disable
			$( this ).add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded', $( this ).add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
			// jscs:enable
		} );
	} )();

	// Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility.
	( function() {
		if ( ! siteNavigation.length || ! siteNavigation.children().length ) {
			return;
		}

		// Toggle `focus` class to allow submenu access on tablets.
		function toggleFocusClassTouchScreen() {
			if ( window.innerWidth >= 910 ) {
				$( document.body ).on( 'touchstart.twentysixteen', function( e ) {
					if ( ! $( e.target ).closest( '.main-navigation li' ).length ) {
						$( '.main-navigation li' ).removeClass( 'focus' );
					}
				} );
				siteNavigation.find( '.menu-item-has-children > a' ).on( 'touchstart.twentysixteen', function( e ) {
					var el = $( this ).parent( 'li' );

					if ( ! el.hasClass( 'focus' ) ) {
						e.preventDefault();
						el.toggleClass( 'focus' );
						el.siblings( '.focus' ).removeClass( 'focus' );
					}
				} );
			} else {
				siteNavigation.find( '.menu-item-has-children > a' ).unbind( 'touchstart.twentysixteen' );
			}
		}

		if ( 'ontouchstart' in window ) {
			$( window ).on( 'resize.twentysixteen', toggleFocusClassTouchScreen );
			toggleFocusClassTouchScreen();
		}

		siteNavigation.find( 'a' ).on( 'focus.twentysixteen blur.twentysixteen', function() {
			$( this ).parents( '.menu-item' ).toggleClass( 'focus' );
		} );
	} )();

	// Add the default ARIA attributes for the menu toggle and the navigations.
	function onResizeARIA() {
		if ( window.innerWidth < 910 ) {
			if ( menuToggle.hasClass( 'toggled-on' ) ) {
				menuToggle.attr( 'aria-expanded', 'true' );
			} else {
				menuToggle.attr( 'aria-expanded', 'false' );
			}

			if ( siteHeaderMenu.hasClass( 'toggled-on' ) ) {
				siteNavigation.attr( 'aria-expanded', 'true' );
				socialNavigation.attr( 'aria-expanded', 'true' );
			} else {
				siteNavigation.attr( 'aria-expanded', 'false' );
				socialNavigation.attr( 'aria-expanded', 'false' );
			}

			menuToggle.attr( 'aria-controls', 'site-navigation social-navigation' );
		} else {
			menuToggle.removeAttr( 'aria-expanded' );
			siteNavigation.removeAttr( 'aria-expanded' );
			socialNavigation.removeAttr( 'aria-expanded' );
			menuToggle.removeAttr( 'aria-controls' );
		}
	}

	// Add 'below-entry-meta' class to elements.
	function belowEntryMetaClass( param ) {
		if ( body.hasClass( 'page' ) || body.hasClass( 'search' ) || body.hasClass( 'single-attachment' ) || body.hasClass( 'error404' ) ) {
			return;
		}

		$( '.entry-content' ).find( param ).each( function() {
			var element              = $( this ),
				elementPos           = element.offset(),
				elementPosTop        = elementPos.top,
				entryFooter          = element.closest( 'article' ).find( '.entry-footer' ),
				entryFooterPos       = entryFooter.offset(),
				entryFooterPosBottom = entryFooterPos.top + ( entryFooter.height() + 28 ),
				caption              = element.closest( 'figure' ),
				figcaption           = element.next( 'figcaption' ),
				newImg;

			// Add 'below-entry-meta' to elements below the entry meta.
			if ( elementPosTop > entryFooterPosBottom ) {

				// Check if full-size images and captions are larger than or equal to 840px.
				if ( 'img.size-full' === param || '.wp-block-image img' === param ) {

					// Create an image to find native image width of resized images (i.e. max-width: 100%).
					newImg = new Image();
					newImg.src = element.attr( 'src' );

					$( newImg ).on( 'load.twentysixteen', function() {
						if ( newImg.width >= 840 ) {

							// Check if an image in an image block has a width attribute; if its value is less than 840, return.
							if ( '.wp-block-image img' === param && element.is( '[width]' ) && element.attr( 'width' ) < 840 ) {
								return;
							}

							element.addClass( 'below-entry-meta' );

							if ( caption.hasClass( 'wp-caption' ) ) {
								caption.addClass( 'below-entry-meta' );
								caption.removeAttr( 'style' );
							}

							if ( figcaption ) {
								figcaption.addClass( 'below-entry-meta' );
							}
						}
					} );
				} else {
					element.addClass( 'below-entry-meta' );
				}
			} else {
				element.removeClass( 'below-entry-meta' );
				caption.removeClass( 'below-entry-meta' );
			}
		} );
	}

	$( document ).ready( function() {
		body = $( document.body );

		$( window )
			.on( 'load.twentysixteen', onResizeARIA )
			.on( 'resize.twentysixteen', function() {
				clearTimeout( resizeTimer );
				resizeTimer = setTimeout( function() {
					belowEntryMetaClass( 'img.size-full' );
					belowEntryMetaClass( 'blockquote.alignleft, blockquote.alignright' );
					belowEntryMetaClass( '.wp-block-image img' );
				}, 300 );
				onResizeARIA();
			} );

		belowEntryMetaClass( 'img.size-full' );
		belowEntryMetaClass( 'blockquote.alignleft, blockquote.alignright' );
		belowEntryMetaClass( '.wp-block-image img' );
		
		//upravy na hlavni strance
		if ( $( 'body' ).hasClass( 'home' ) )
		{			
			// pocet produktu
			numProducts = $( 'section.products article.product-item' ).length;
						
			// sirka scrollable area s produkty
			$( 'section.products div.scrollable-area' ).css( 'width', ( numProducts * prodWidth ) );
			
			if ( showOffer == 0 )
			{
				$( 'section.month_offer' ).addClass( 'minimal', 1000 );				
				$( 'section.month_offer' ).css( 'top', '-106px' );
				
				offerWidth = $( 'section.month_offer article.offer' ).outerWidth();
			}
			
			if ( numProducts > 3 && windowWidth > 720 )
			{
				scrollProducts = setInterval(function () {
					$( 'section.products div.scrollable-area' ).animate({ left: '-' + prodWidth + 'px', }, 1500, function() {
						$( 'section.products .scrollable-area article:first-child' ).insertAfter(	$( 'section.products .scrollable-area article:last-child' ) );
						$( 'section.products div.scrollable-area' ).css( 'left', '0px' );
					} );
				}, 3000); 
			}
			else
			{
			
			}			
			
		}
		else
		{
				
		}
		
		$( 'section.month_offer .show-hide-button' ).click( function() {
			if ( $( 'section.month_offer' ).hasClass( 'minimal' ) )
			{
				$( 'section.month_offer' ).removeClass( 'minimal', 1000 );				
				$( 'section.month_offer' ).animate({ top: "62px", }, 1500 );
				createCookie( 'showOffer', 1, 10 );
				
				// zmen sirku scrollable area
				offerWidth = $( 'section.month_offer article.offer' ).outerWidth();
				$( 'section.month_offer span.scroll-articles' ).css( 'width', ( numOffers * offerWidth ) );
				
				showOffer = 1;
			}
			else
			{
				$( 'section.month_offer' ).addClass( 'minimal', 1000 );				
				$( 'section.month_offer' ).animate({ top: "-106px", }, 1500 );
				createCookie( 'showOffer', 0, 10 );
				
				// zmen sirku scrollable area
				offerWidth = $( 'section.month_offer article.offer' ).outerWidth();
				$( 'section.month_offer span.scroll-articles' ).css( 'width', ( numOffers * offerWidth ) );
				
				showOffer = 0;
			}
		
		} );
		
		// newsletter panel
		$( '.newsletter-button' ).click( function() {
			$( '.newsletter-panel' ).parent( 'div' ).fadeIn();
		} );
		$( '.newsletter-panel .close' ).click( function() {
			$( '.newsletter-panel' ).parent( 'div' ).fadeOut();
		} );
		
		// catalogue panel
		$( 'li.show-catalogue-panel a' ).click( function() {
			$( '.catalogue-panel' ).parent( 'div' ).fadeIn();
		} );
		$( '.catalogue-panel .close' ).click( function() {
			$( '.catalogue-panel' ).parent( 'div' ).fadeOut();
		} );
		
		//uprava menu
		$( 'li.menu-item-has-children' ).each( function() {
			$( this ).children( 'a' ).after( '<div class="show-hide-submenu"><span class="none">&darr;</span></div>' );
			//$( this ).text( 'button' );
		} );
		
		$( 'li.menu-item-has-children .show-hide-submenu' ).click( function() {
			submenu = $( this ).parent( 'li' ).children( '.sub-menu' );
			if ( submenu.is( ':hidden' ) )
			{
				submenu.show();
				$( this ).addClass( 'arrow-up' );
			}
			else
			{
				submenu.hide();
				$( this ).removeClass( 'arrow-up' );
			}			
		} );
		
		// ukaz responzivni menu
		$( 'div.show-hide-menu' ).click( function() {
			if ( $( 'header.supheader ul.menu' ).is( ':hidden' ) )
			{
				$( 'header.supheader ul.menu' ).slideDown();
			}
			else
			{
				$( 'header.supheader ul.menu' ).slideUp();
			}
		} );
		
		// upravy zahlavi s posunovanim nabidek		
		// sirka scrollable area s nabidkami
		$( 'section.month_offer span.scroll-articles' ).css( 'width', ( numOffers * offerWidth ) );
		
		// posun na predchozi nabidku mesice
		$( 'section.month_offer nav.prev span' ).click( function() {
			if ( offerVisible > 1 )
			{
				
				offset = ( (offerVisible - 1) - numOffers ) * offerWidth;
				
				$( 'section.month_offer span.scroll-articles' ).animate({ right: offset + 'px', }, 1500, function() {
						
					} );
				
				if ( $( 'section.month_offer .content nav.next span' ).is( ':hidden' ) )
				{
					$( 'section.month_offer .content nav.next span' ).show();
				}				
				
				--offerVisible;
				if ( offerVisible == 1 )
				{
					$( 'section.month_offer .content nav.prev span' ).hide();	
				}
			}
		} );
		
		// posun na nasledujici nabidku mesice
		$( 'section.month_offer nav.next span' ).click( function() {
			if ( offerVisible < numOffers )
			{				
				offset = ( (offerVisible + 1) - numOffers ) * offerWidth;
				
				$( 'section.month_offer span.scroll-articles' ).animate({ right: offset + 'px', }, 1500, function() {
						
					} );
				
				if ( $( 'section.month_offer .content nav.prev span' ).is( ':hidden' ) )
				{
					$( 'section.month_offer .content nav.prev span' ).show();
				}				
				
				++offerVisible;
				if ( offerVisible == numOffers )
				{
					$( 'section.month_offer .content nav.next span' ).hide();	
				}
			}
		} );
		
		// pridani subject do formulare		
		$( 'body' ).on( 'click', 'section.advice-form form input#nf-field-38', function() {
				
			subject = $( 'article.single header h1' ).text();			
			$( 'section.advice-form form input#nf-field-38' ).attr( 'value', subject );
			
		} );		
		
		//kliknuti na sipku nahoru
		$( '.big-arrow-up' ).click(function()
		{
			$('html, body').animate(
				{
					scrollTop: (0)
				}, 2000);
		});
		
	} );
	
	$(window).resize(function () 
	{
		offerWidth = $( 'section.month_offer article.offer' ).outerWidth();
		
		if ( $( 'body' ).hasClass( 'home' ) )
		{
			prodWidth = $( 'section.products article.product-item' ).outerWidth();
		}
		
		windowWidth = $( 'body' ).outerWidth();
		if ( windowWidth >= 1260 )
		{
			$( 'header.supheader ul.menu' ).show();	
		}
		
		if ( windowWidth < 720 )
		{
			clearInterval( scrollProducts );
			scrollProducts = null;
		}
		else
		{
			if ( ! scrollProducts )
			{
				scrollProducts = setInterval(function () {
					$( 'section.products div.scrollable-area' ).animate({ left: '-' + prodWidth + 'px', }, 1500, function() {
						$( 'section.products .scrollable-area article:first-child' ).insertAfter(	$( 'section.products .scrollable-area article:last-child' ) );
						$( 'section.products div.scrollable-area' ).css( 'left', '0px' );
					} );
				}, 3000);
			}
		}
		
		// upravy zahlavi s posunovanim nabidek		
		// sirka scrollable area s nabidkami
		$( 'section.month_offer span.scroll-articles' ).css( 'width', ( numOffers * offerWidth ) );
		
		offset = ( (offerVisible) - numOffers ) * offerWidth;
		
		$( 'section.month_offer span.scroll-articles' ).css( 'right', ( offset ) );
		
	} );
	
	$( window ).scroll( function () {
		if ( posTop() > ( $(window).height() / 2 ) ) 
		{
			$( '.big-arrow-up' ).fadeIn(600);
		} 
		else 
		{
			$( '.big-arrow-up' ).fadeOut(600);
		}	
	} );
	
	//zjisti posunutou pozici
	function posTop( ) 
	{	
		return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;
    }
	
} )( jQuery );


/* - - - COOKIES - - - */
/* COOKIES */
function createCookie(name, value, days) {
    var expires;

    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = encodeURIComponent(name) + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) === 0)
            return decodeURIComponent(c.substring(nameEQ.length, c.length));
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

ACC SHELL 2018