(() => { "use strict"; function isWebp() { function testWebP(callback) { let webP = new Image; webP.onload = webP.onerror = function() { callback(2 == webP.height); }; webP.src = "data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA"; } testWebP((function(support) { let className = true === support ? "webp" : "no-webp"; document.documentElement.classList.add(className); })); } function getHash() { if (location.hash) return location.hash.replace("#", ""); } let bodyLockStatus = true; let bodyLockToggle = (delay = 500) => { if (document.documentElement.classList.contains("lock")) bodyUnlock(delay); else bodyLock(delay); }; let bodyUnlock = (delay = 500) => { let body = document.querySelector("body"); if (bodyLockStatus) { let lock_padding = document.querySelectorAll("[data-lp]"); setTimeout((() => { for (let index = 0; index < lock_padding.length; index++) { const el = lock_padding[index]; el.style.paddingRight = "0px"; } body.style.paddingRight = "0px"; document.documentElement.classList.remove("lock"); }), delay); bodyLockStatus = false; setTimeout((function() { bodyLockStatus = true; }), delay); } }; let bodyLock = (delay = 500) => { let body = document.querySelector("body"); if (bodyLockStatus) { let lock_padding = document.querySelectorAll("[data-lp]"); for (let index = 0; index < lock_padding.length; index++) { const el = lock_padding[index]; el.style.paddingRight = window.innerWidth - document.querySelector(".wrapper").offsetWidth + "px"; } body.style.paddingRight = window.innerWidth - document.querySelector(".wrapper").offsetWidth + "px"; document.documentElement.classList.add("lock"); bodyLockStatus = false; setTimeout((function() { bodyLockStatus = true; }), delay); } }; function menuInit() { if (document.querySelector(".icon-menu")) document.addEventListener("click", (function(e) { if (bodyLockStatus && e.target.closest(".icon-menu")) { bodyLockToggle(); document.documentElement.classList.toggle("menu-open"); } })); } function menuClose() { bodyUnlock(); document.documentElement.classList.remove("menu-open"); } function FLS(message) { setTimeout((() => { if (window.FLS) console.log(message); }), 0); } let gotoBlock = (targetBlock, noHeader = false, speed = 500, offsetTop = 0) => { const targetBlockElement = document.querySelector(targetBlock); if (targetBlockElement) { let headerItem = ""; let headerItemHeight = 0; if (noHeader) { headerItem = "header.header"; headerItemHeight = document.querySelector(headerItem).offsetHeight; } let options = { speedAsDuration: true, speed, header: headerItem, offset: offsetTop, easing: "easeOutQuad" }; document.documentElement.classList.contains("menu-open") ? menuClose() : null; if ("undefined" !== typeof SmoothScroll) (new SmoothScroll).animateScroll(targetBlockElement, "", options); else { let targetBlockElementPosition = targetBlockElement.getBoundingClientRect().top + scrollY; targetBlockElementPosition = headerItemHeight ? targetBlockElementPosition - headerItemHeight : targetBlockElementPosition; targetBlockElementPosition = offsetTop ? targetBlockElementPosition - offsetTop : targetBlockElementPosition; window.scrollTo({ top: targetBlockElementPosition, behavior: "smooth" }); } FLS(`[gotoBlock]: Юхуу...едем к ${targetBlock}`); } else FLS(`[gotoBlock]: Ой ой..Такого блока нет на странице: ${targetBlock}`); }; let addWindowScrollEvent = false; function pageNavigation() { document.addEventListener("click", pageNavigationAction); document.addEventListener("watcherCallback", pageNavigationAction); function pageNavigationAction(e) { if ("click" === e.type) { const targetElement = e.target; if (targetElement.closest("[data-goto]")) { const gotoLink = targetElement.closest("[data-goto]"); const gotoLinkSelector = gotoLink.dataset.goto ? gotoLink.dataset.goto : ""; const noHeader = gotoLink.hasAttribute("data-goto-header") ? true : false; const gotoSpeed = gotoLink.dataset.gotoSpeed ? gotoLink.dataset.gotoSpeed : 500; const offsetTop = gotoLink.dataset.gotoTop ? parseInt(gotoLink.dataset.gotoTop) : 0; gotoBlock(gotoLinkSelector, noHeader, gotoSpeed, offsetTop); e.preventDefault(); } } else if ("watcherCallback" === e.type && e.detail) { const entry = e.detail.entry; const targetElement = entry.target; if ("navigator" === targetElement.dataset.watch) { document.querySelector(`[data-goto]._navigator-active`); let navigatorCurrentItem; if (targetElement.id && document.querySelector(`[data-goto="#${targetElement.id}"]`)) navigatorCurrentItem = document.querySelector(`[data-goto="#${targetElement.id}"]`); else if (targetElement.classList.length) for (let index = 0; index < targetElement.classList.length; index++) { const element = targetElement.classList[index]; if (document.querySelector(`[data-goto=".${element}"]`)) { navigatorCurrentItem = document.querySelector(`[data-goto=".${element}"]`); break; } } if (entry.isIntersecting) navigatorCurrentItem ? navigatorCurrentItem.classList.add("_navigator-active") : null; else navigatorCurrentItem ? navigatorCurrentItem.classList.remove("_navigator-active") : null; } } } if (getHash()) { let goToHash; if (document.querySelector(`#${getHash()}`)) goToHash = `#${getHash()}`; else if (document.querySelector(`.${getHash()}`)) goToHash = `.${getHash()}`; goToHash ? gotoBlock(goToHash, true, 500, 20) : null; } } function headerScroll() { addWindowScrollEvent = true; const header = document.querySelector("header.header"); const headerShow = header.hasAttribute("data-scroll-show"); const headerShowTimer = header.dataset.scrollShow ? header.dataset.scrollShow : 500; const startPoint = header.dataset.scroll ? header.dataset.scroll : 1; let scrollDirection = 0; let timer; document.addEventListener("windowScroll", (function(e) { const scrollTop = window.scrollY; clearTimeout(timer); if (scrollTop >= startPoint) { !header.classList.contains("_header-scroll") ? header.classList.add("_header-scroll") : null; if (headerShow) { if (scrollTop > scrollDirection) header.classList.contains("_header-show") ? header.classList.remove("_header-show") : null; else !header.classList.contains("_header-show") ? header.classList.add("_header-show") : null; timer = setTimeout((() => { !header.classList.contains("_header-show") ? header.classList.add("_header-show") : null; }), headerShowTimer); } } else { header.classList.contains("_header-scroll") ? header.classList.remove("_header-scroll") : null; if (headerShow) header.classList.contains("_header-show") ? header.classList.remove("_header-show") : null; } scrollDirection = scrollTop <= 0 ? 0 : scrollTop; })); } setTimeout((() => { if (addWindowScrollEvent) { let windowScroll = new Event("windowScroll"); window.addEventListener("scroll", (function(e) { document.dispatchEvent(windowScroll); })); } }), 0); function video() { const videoPlayer = document.querySelector(".video-player"); const video = videoPlayer.querySelector(".video"); const playButton = videoPlayer.querySelector(".play-button"); playButton.addEventListener("click", (e => { if (video.paused) video.play(); else video.pause(); })); document.getElementById("play").onclick = function() { document.getElementById("play").classList.add("play--play-hidden"); }; } video(); const animItems = document.querySelectorAll("._anim-items"); if (animItems.length > 0) { window.addEventListener("scroll", animOnScroll); function animOnScroll() { for (let index = 0; index < animItems.length; index++) { const animItem = animItems[index]; const animItemHeight = animItem.offsetHeight; const animItemOffset = offset(animItem).top; const animStart = 4; let animItemPoint = window.innerHeight - animItemHeight / animStart; if (animItemHeight > window.innerHeight) animItemPoint = window.innerHeight - window.innerHeight / animStart; if (pageYOffset > animItemOffset - animItemPoint && pageYOffset < animItemOffset + animItemHeight) animItem.classList.add("_active"); else if (!animItem.classList.contains("_anim-no-hide")) ; } } function offset(el) { const rect = el.getBoundingClientRect(), scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document.documentElement.scrollTop; return { top: rect.top + scrollTop, left: rect.left + scrollLeft }; } setTimeout((() => { animOnScroll(); }), 300); } isWebp(); menuInit(); pageNavigation(); headerScroll(); })();