const $body = $('body'); // JS detection $('html') .removeClass('no-js') .addClass('has-js'); // Touch detection $body.one('touchstart', () => { $('html').addClass('has-touch'); window.removeEventListener('keydown', handleFirstTab); }); // keyboard nav detection function handleFirstTab(e) { if (e.keyCode === 9) { document.documentElement.classList.add('tab-key'); window.removeEventListener('keydown', handleFirstTab); window.addEventListener('mousedown', handleMouseDownOnce); } } function handleMouseDownOnce() { document.documentElement.classList.remove('tab-key'); window.removeEventListener('mousedown', handleMouseDownOnce); window.addEventListener('keydown', handleFirstTab); } window.addEventListener('keydown', handleFirstTab); $('#login').login({ addBodyPadding: true, disableScroll: true }); $('[data-toggle="search"]').on('click', function() { const $search_form = $('[data-search-form]'); $search_form.toggleClass('active'); const $searchInput = $('input[name=search]').get(0); if ($searchInput && $search_form.hasClass('active')) { $searchInput.focus(); } return false; }); const search_clear_selector = '[data-search-clear]'; const search_input_selector = '[data-search-input-resp]'; $body.on('keyup change', search_input_selector, function() { const value = $(this).val(); wpj.domUtils.resetTimer('main-search', 200, function() { $(search_clear_selector).toggleClass('visible', (value.length > 0)); }); }).on('click', search_clear_selector, function() { $(search_input_selector).val('').change().get(0).focus(); return false; }); $('[data-toggle="burger"]').on('click', function() { //, .sections-responsive [data-toggle="search"] $('.header [data-toggle="burger"]').toggleClass('active'); $('[data-sections-responsive]').toggleClass('active'); $('body').toggleClass('scroll-disable'); return false; }); $('[data-scrollto]').on('click', function(e) { e.preventDefault(); const $target = $($(this).attr('href')); wpj.domUtils.scrollTo($target); return false; }); $('[data-toggle-password]').on('click', function() { const $this = $(this); // fallback pro starší implementaci custom na shopech, mají prázdný data atr. if ($this.data('toggle-password') === '') { return; } const $input = $($this.data('toggle-password')); if ($input.length) { if ($input.attr('type') === 'password') { $input.attr('type', 'text'); $this.text($this.data('trans-hide') ?? 'Skrýt'); } else { $input.attr('type', 'password'); $this.text($this.data('show') ?? 'Zobrazit'); } return false; } }); $('[data-sections="header"] .has-submenu').on({ mouseenter: function() { var self = this; setTimeout(function() { if ($(self).is(':hover')) { var imgs = $(self).find('img').filter(function() { return !$(this).attr('src'); }); imgs.each(function(i) { $(this).attr('src', $(this).data('src')); }); $(self).addClass('hover'); } }, 200); }, mouseleave: function() { var self = this; setTimeout(function() { if (!$(self).is(':hover')) { $(self).removeClass('hover'); } }, 200); }, });