/** * tilda-cover создает фон в блоках CR... Так же, здесь есть функции, которые отвечают за эффекты * этих фонов - паралакс или фиксация. * * В tilda-cover есть код, который работает со стрелками на обложках, обспечивая плавный скролл для * перехода с текущего блока к следующему. * * tilda-cover взаимодействует со скриптом tilda-video-processor. Из tilda-cover передаются параметры, * заданные для видео в соответствующие функции видео-процессора t_videoprocessor__processHTML5Video - для .webm или .mp4; * и processYoutubeVideo - для YouTube-видео. * * Фиксация обложки работает в фоновых HTML5 видео, если их высота превышает высоту вьюпорта. */ window.t_cover__isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); /** * This function check current size of cover element, get speed factor, and create parallax. * Using only in desktop * * @param {HTMLElement} el */ function t_cover__parallax(el) { var windowHeight = window.innerHeight; window.addEventListener('resize', function () { windowHeight = window.innerHeight; }); if (document.body.style.webkitTransform) el.style.position = 'relative'; var elementHeight = t_cover__getFullHeight(el); var speedFactor = 0.2; var events = ['scroll', 'resize']; events.forEach(function (event) { window.addEventListener(event, function () { t_cover__parallaxUpdate(el, speedFactor, windowHeight, elementHeight); }); }); if (document.readyState !== 'complete') { window.addEventListener('load', function () { t_cover__parallaxUpdate(el, speedFactor, windowHeight, elementHeight); }); } t_cover__parallaxUpdate(el, speedFactor, windowHeight, elementHeight); } /** * update parallax state * * @param {HTMLElement} el * @param {number} speedFactor * @param {number} windowHeight * @param {number} elementHeight */ function t_cover__parallaxUpdate(el, speedFactor, windowHeight, elementHeight) { var viewportTopPos = window.pageYOffset; var elementAbsoluteTop = el.getBoundingClientRect().top + viewportTopPos; var elementRelativeTop = el.getBoundingClientRect().top; var elementBottomPos = elementAbsoluteTop + elementHeight; var viewportBottom = viewportTopPos + windowHeight; if (elementBottomPos < viewportTopPos || elementAbsoluteTop > viewportBottom) return; var bgVerticalShift = -1 * Math.round(elementRelativeTop * speedFactor); if (document.body.style.webkitTransform) { el.style.webkitTransform = 'translateY(' + bgVerticalShift + 'px)'; } else { el.style.top = bgVerticalShift + 'px'; } } /** * Initing cover after DOM is loaded. * Get current cover element rom it data-attributes, update covers height, if it's necessary. * Naming without prefix, because this function used in edit mode. * * @param {string} id - current cover id */ function cover_init(id) { var allRec = document.getElementById('allrecords'); var isLazy = allRec ? allRec.getAttribute('data-tilda-lazy') === 'yes' : false; var record = document.getElementById('rec' + id); var el = document.getElementById('coverCarry' + id); // cover logo used in blocks CR34 and CR35 var coverLogo = record ? record.querySelector('img[data-hook-clogo]') : null; if (!el) return; // create object with empty values var coverParams = { 'cover-bg': '', 'cover-height': '', 'cover-parallax': '', 'video-url-mp4': '', 'video-url-webm': '', 'video-url-youtube': '', 'video-url-vimeo': '', 'video-url-rutube': '', 'video-url-kinescope': '', 'video-url-vkvideo': '', 'video-noloop': '', 'video-nomute': '', 'video-nocover': '', 'bg-base64': '', 'use-image-for-mobile-cover': '', }; // iterating keys from created object and append to it current values for (var key in coverParams) { var elAttribute = el.getAttribute('data-content-' + key); if (elAttribute || key === 'use-image-for-mobile-cover') coverParams[key] = elAttribute; } var recordBG = record ? record.getAttribute('data-bg-color') : ''; if (recordBG) coverParams['parent-bg'] = recordBG; var videoFormats = ['mp4', 'webm', 'youtube', 'vimeo', 'rutube', 'kinescope', 'vkvideo']; // if element has parameter nocover - switch off video url if (coverParams['video-nocover'] === 'yes') { videoFormats.forEach(function (videoFormat) { coverParams['video-url-' + videoFormat] = ''; }); } else { // force mute, if video placed inside cover coverParams['video-nomute'] = ''; } // checking if one of the video-url params keys has URL as its value var isContainsVideo = videoFormats.some(function (videoFormat) { return !!coverParams['video-url-' + videoFormat]; }); if ((window.t_cover__isMobile || 'ontouchend' in document) && isContainsVideo && !isLazy) { el.style.backgroundImage = 'url("' + coverParams['cover-bg'] + '")'; } // fix content height, // need setTimeout for correct calculate elements height setTimeout(function () { t_cover__recalcContentHeight(id, false, 0); t_cover__fixBgFixedNode(id); }, 300); if (coverLogo) { coverLogo.onload = function () { t_cover__recalcContentHeight(id, false, 500); }; } if (window.t_cover__isMobile || 'ontouchend' in document) { if (screen?.orientation) { screen.orientation.addEventListener('change', function () { // need setTimeout to change height, after device rotating, // otherwise height will be calculated at time, which orientationchange be triggered t_cover__recalcContentHeight(id, true, 200); }); } else { window.addEventListener('orientationchange', function () { // need setTimeout to change height, after device rotating, // otherwise height will be calculated at time, which orientationchange be triggered t_cover__recalcContentHeight(id, true, 200); }); } } else { window.addEventListener('resize', function () { t_cover__recalcContentHeight(id, false, 0); }); } t_cover__setListenerToArrow(id); t_cover__setCoverParams(el, coverParams, isContainsVideo); el.addEventListener('displayChanged', function () { t_cover__recalcContentHeight(id, false, 0); }); } /** * recalc content height * * @param {string} id * @param {Boolean} isOrientationChange * @param {number} timeout */ function t_cover__recalcContentHeight(id, isOrientationChange, timeout) { if (timeout) { setTimeout(function () { t_cover__fixBgFixedStyles(id); t_cover__recalcCoverHeight(id, isOrientationChange); }, timeout); } else { t_cover__fixBgFixedStyles(id); t_cover__recalcCoverHeight(id, isOrientationChange); } } /** * append to current cover some styles/element, * depending on type of parallax, contains video url etc. * * @param {HTMLElement} el * @param {Object} coverParams * @param {Boolean} isContainsVideo */ function t_cover__setCoverParams(el, coverParams, isContainsVideo) { var isFixedParallax = coverParams['cover-parallax'] === 'fixed'; var isDynamicParallax = coverParams['cover-parallax'] === 'dynamic'; var isbgBase64 = coverParams['bg-base64'] === 'yes'; var parentBG = coverParams['parent-bg']; if (parentBG) { var cover = el.closest('.t-cover'); if (cover) cover.classList.add('t-cover__transparent'); } t_cover__setCoverVideoParams(el, coverParams, isContainsVideo, isFixedParallax); if (isFixedParallax && window.isOpera) el.style.transform = 'unset'; if (isDynamicParallax && !window.t_cover__isMobile) { var coverHeight = t_cover__getPureHeight(el); var isScaled = t_cover__isScaled(el); if (coverHeight < window.innerHeight) { var heightPadding = window.innerHeight * 0.2; const finalHeight = coverHeight + heightPadding + 'px'; el.style.height = isScaled ? `calc(${finalHeight} / var(--t-zoom, 1))` : finalHeight; } t_cover__parallax(el); } if (isbgBase64 && coverParams['cover-bg'] && !isContainsVideo) { var bgIsLoaded = false; var img = document.createElement('img'); img.src = coverParams['cover-bg']; img.onload = function () { if (img.parentElement) img.parentElement.removeChild(img); el.style.backgroundImage = 'url("' + coverParams['cover-bg'] + '")'; el.style.opacity = '1'; bgIsLoaded = true; }; if (!bgIsLoaded) { el.style.backgroundImage = ''; el.style.opacity = '0'; el.style.transition = 'opacity 25ms'; } } } function t_cover__isScaled(element) { const scaledRecord = element?.closest('.t-record_scaled'); if (!scaledRecord) return false; const userHeightElement = scaledRecord.querySelector('[data-content-cover-height]'); const userHeightValue = userHeightElement?.getAttribute('data-content-cover-height'); return userHeightValue && userHeightValue.includes('vh'); } /** * set for created video (if it existed) params from data-attributes and process it. * Different ways to create video depend on them types * * @param {HTMLElement} el * @param {Object} coverParams * @param {Boolean} isContainsVideo * @param {Boolean} isFixedParallax */ function t_cover__setCoverVideoParams(el, coverParams, isContainsVideo, isFixedParallax) { var videoType = ''; if (coverParams['video-url-youtube']) videoType = 'youtube'; if ( coverParams['video-url-vimeo'] || coverParams['video-url-rutube'] || coverParams['video-url-kinescope'] || coverParams['video-url-vkvideo'] ) videoType = 'iframe'; if ( ((window.t_cover__isMobile || 'ontouchend' in document) && ['on', null].indexOf(coverParams['use-image-for-mobile-cover']) !== -1) || !isContainsVideo ) return; t_cover__setStylesForCoverVideo(el, videoType === 'youtube' ? 'youtube' : ''); switch (videoType) { case 'youtube': t_cover__processYouTubeVideo(el, coverParams); break; case 'iframe': t_cover__processIframeVideo(el, coverParams); break; default: t_cover__processHTML5Video(el, coverParams, isFixedParallax); } } /** * process YouTube video, when it inside viewport * * @param {HTMLElement} el - cover * @param {Object} coverParams */ function t_cover__processYouTubeVideo(el, coverParams) { if ('IntersectionObserver' in window) { var youTubeVideoObserver = new IntersectionObserver(function (entries, youTubeVideoObserver) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; var target = entry.target; youTubeVideoObserver.unobserve(target); t_onFuncLoad('processYoutubeVideo', function () { window.processYoutubeVideo(target, coverParams['cover-height']); }); }); }); youTubeVideoObserver.observe(el); } else { t_cover__createYoutubeCover(el, coverParams['cover-height']); window.addEventListener( 'scroll', t_throttle(function () { t_cover__createYoutubeCover(el, coverParams['cover-height']); }, 100) ); } } /** * process HTML5 video, when it inside viewport * * @param {HTMLElement} el * @param {Object} coverParams * @param {Boolean} isFixedParallax */ function t_cover__processHTML5Video(el, coverParams, isFixedParallax) { el.style.backgroundSize = 'auto'; var isHeightInVH = coverParams['cover-height'].indexOf('vh') !== -1; var isMoreVH = isHeightInVH ? parseInt(coverParams['cover-height'], 10) > 100 : false; var isHeightInPX = coverParams['cover-height'].indexOf('px') !== -1; var isMoreWinHeight = isHeightInPX ? parseInt(coverParams['cover-height'], 10) > window.innerHeight : false; var isHeightMoreVH = false; if (isFixedParallax && (isMoreVH || isMoreWinHeight)) { el.style.height = '100vh'; isHeightMoreVH = true; } var hasLoop = !coverParams['video-noloop']; var isMuted = !coverParams['video-nomute']; if ('IntersectionObserver' in window) { var htmlVideoObserver = new IntersectionObserver(function (entries, htmlVideoObserver) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; var target = entry.target; htmlVideoObserver.unobserve(target); t_cover__createAndProcessHTML5Video(target, coverParams, hasLoop, isMuted); }); }); htmlVideoObserver.observe(el); } else { t_cover__createHTMLVideoCover(el, coverParams, isHeightMoreVH, isFixedParallax, hasLoop, isMuted); window.addEventListener( 'scroll', t_throttle(function () { t_cover__createHTMLVideoCover(el, coverParams, isHeightMoreVH, isFixedParallax, hasLoop, isMuted); }, 100) ); } // update html5 video styles, if it has fixed parallax, and it's height larger than viewport height window.addEventListener('scroll', function () { if (!isFixedParallax || !isHeightMoreVH) return; var currentElementParent = el.parentElement; var windowScrollTop = window.pageYOffset; var windowHeight = window.innerHeight; var windowBottomPos = windowScrollTop + windowHeight; var parentHeight = t_cover__getPureHeight(currentElementParent); var parentTopPos = currentElementParent.getBoundingClientRect().top + windowScrollTop; var parentBottomPos = parentTopPos + parentHeight; if (windowBottomPos >= parentBottomPos) { el.style.position = 'absolute'; el.style.bottom = '0px'; el.style.top = 'auto'; } else if (windowScrollTop >= parentTopPos) { el.style.position = 'fixed'; el.style.top = '0px'; } else if (windowScrollTop < parentTopPos) { el.style.position = 'relative'; el.style.top = 'auto'; } }); } /** * process Iframe video, when it inside viewport * * @param {HTMLElement} el - cover * @param {Object} coverParams */ function t_cover__processIframeVideo(el, coverParams) { if ('IntersectionObserver' in window) { var iframeVideoObserver = new IntersectionObserver(function (entries, iframeVideoObserver) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; var target = entry.target; iframeVideoObserver.unobserve(target); t_onFuncLoad('t_videoprocessor__processIframeVideo', function () { window.t_videoprocessor__processIframeVideo(target, coverParams); }); }); }); iframeVideoObserver.observe(el); } else { t_cover__createIframeCover(el, coverParams); window.addEventListener( 'scroll', t_throttle(function () { t_cover__createIframeCover(el, coverParams); }, 100) ); } } /** * set styles before video has been loaded * * @param {HTMLElement} el - video wrapper * @param {string} type - YouTube- or HTML5-video */ function t_cover__setStylesForCoverVideo(el, type) { el.style.backgroundColor = '#000000'; el.style.backgroundImage = type === 'youtube' ? '' : 'url("https://tilda.ws/img/spinner-white.gif")'; el.style.backgroundSize = type === 'youtube' ? '' : 'unset'; el.style.backgroundPosition = type === 'youtube' ? '' : 'center'; el.style.backgroundRepeat = type === 'youtube' ? '' : 'no-repeat'; el.setAttribute('data-content-cover-bg', ''); } /** * find arrow and set listener scroll to the next section * * @param {string} id */ function t_cover__setListenerToArrow(id) { var rec = document.getElementById('rec' + id); if (!rec) return; var coverArrow = rec.querySelector('.t-cover__arrow-wrapper'); if (!coverArrow) return; coverArrow.addEventListener('click', function () { var recHeight = rec.offsetHeight; if (!recHeight) return; var recBottomPos = rec.offsetHeight + rec.getBoundingClientRect().top + window.pageYOffset; t_cover__scrollToNextSection(recBottomPos); }); } function t_cover__initCovers() { var records = document.querySelector('.t-records'); var isEditMode = records && records.getAttribute('data-tilda-mode') === 'edit'; if (isEditMode) return; var coverList = Array.from(document.querySelectorAll('.t-cover__carrier')); coverList.forEach(function (cover) { var id = cover.getAttribute('data-content-cover-id'); if (id) cover_init(id); }); } /** * Задаём принудительный перенос строки, если текстовый контент обложки не вмещается по ширине страницы. * Текстовый контент в слайдерах игнорируется, так как позиция слайда может превышать ширину экрана. */ function t_cover__setWordWrapOnInit() { var coverWrapperList = Array.from(document.querySelectorAll('.t-cover__wrapper')); var windowWidth = window.t_cover__isMobile ? document.documentElement.clientWidth : window.innerWidth; coverWrapperList.forEach(function (coverWrapper) { if (coverWrapper.closest('.t-slds')) return; if (Math.floor(coverWrapper.getBoundingClientRect().right) > windowWidth) { coverWrapper.style.wordBreak = 'break-all'; } }); } t_onReady(function () { // in t_onFuncLoad function check the readiness of the block editor to execute the script t_onFuncLoad('t_cover__initCovers', function () { t_cover__initCovers(); if (document.readyState === 'complete') { t_cover__setWordWrapOnInit(); } else { window.addEventListener('load', t_cover__setWordWrapOnInit); } }); }); /** * create cover for YouTube, when user will scroll to the current video * * @param {HTMLElement} el - current element * @param {string} height - height of el */ function t_cover__createYoutubeCover(el, height) { if (el.querySelector('iframe')) return; var windowScrollTop = window.pageYOffset; var windowHeight = window.innerHeight; var elHeight = t_cover__getPureHeight(el); var elTopPos = el.getBoundingClientRect().top + windowScrollTop; var elBottomPos = elTopPos + elHeight; var windowBottomPos = windowScrollTop + windowHeight; var padding = 500; if (windowBottomPos > elTopPos - padding && elBottomPos + padding >= windowScrollTop) { t_onFuncLoad('processYoutubeVideo', function () { window.processYoutubeVideo(el, height); }); } } /** * create cover for HTML5 video when user will scroll to the current video * * @param {HTMLElement} el - current element * @param {object} coverParams - current params for cover * @param {Boolean} isHeightMoreVH - boolean value of height the largest then viewport height * @param {Boolean} isFixedParallax - parallax fixed * @param {Boolean} hasLoop - is cover video looped * @param {Boolean} isMuted - is cover video muted */ function t_cover__createHTMLVideoCover(el, coverParams, isHeightMoreVH, isFixedParallax, hasLoop, isMuted) { if (el.querySelector('video')) return; var windowScrollTop = window.pageYOffset; var windowHeight = window.innerHeight; var elHeight = t_cover__getPureHeight(el); var elTopPos = el.getBoundingClientRect().top + windowScrollTop; var elBottomPos = elHeight + elTopPos; var windowBottom = windowScrollTop + windowHeight; var padding = 500; if (windowBottom > elTopPos - padding && windowScrollTop <= elBottomPos + padding) { t_cover__createAndProcessHTML5Video(el, coverParams, hasLoop, isMuted); } } /** * create cover for iframe videos, when user will scroll to the current video * * @param {HTMLElement} el - current element * @param {string} height - height of el */ function t_cover__createIframeCover(el, params) { if (el.querySelector('iframe')) return; var windowScrollTop = window.pageYOffset; var windowHeight = window.innerHeight; var elHeight = t_cover__getPureHeight(el); var elTopPos = el.getBoundingClientRect().top + windowScrollTop; var elBottomPos = elTopPos + elHeight; var windowBottomPos = windowScrollTop + windowHeight; var padding = 500; if (windowBottomPos > elTopPos - padding && elBottomPos + padding >= windowScrollTop) { t_onFuncLoad('t_videoprocessor__processIframeVideo', function () { window.t_videoprocessor__processIframeVideo(el, params); }); } } /** * delivery current element to tilda-video-processor function t_videoprocessor__processHTML5Video, * and process html5 video * * @param {HTMLElement} el * @param {Object} coverParams * @param {Boolean} hasLoop * @param {Boolean} isMuted */ function t_cover__createAndProcessHTML5Video(el, coverParams, hasLoop, isMuted) { t_onFuncLoad('t_videoprocessor__processHTML5Video', function () { t_videoprocessor__processHTML5Video(el, { mp4: coverParams['video-url-mp4'], ogv: '', webm: coverParams['video-url-webm'], poster: '', autoplay: true, loop: hasLoop, scale: true, position: 'absolute', opacity: 1, textReplacement: false, zIndex: 0, width: '100%', height: 0, volume: 1, muted: isMuted, fullscreen: false, imgFallback: true, }); }); } /** * this function responsible for recalculating the height of the cover, * if the content inside the cover has a highter height then set * * @param {string} id - of inited record * @param {boolean} isOrientationChange - if orientation change - true */ function t_cover__recalcCoverHeight(id, isOrientationChange) { var rec = document.getElementById('rec' + id); if (!rec) return; const isScaled = t_cover__isScaled(rec); var cover = rec.querySelector('.t-cover'); var recordType = rec.getAttribute('data-parenttplid') || rec.getAttribute('data-record-type'); if (!cover || recordType === '935') return; // don't process Tilda Main Page cover var coverCarrier = rec.querySelector('.t-cover__carrier'); var coverSetByUserHeight = coverCarrier ? coverCarrier.getAttribute('data-content-cover-height') : ''; if (!coverSetByUserHeight) { var coverHeightElem = rec.querySelector('[data-content-cover-height]'); coverSetByUserHeight = coverHeightElem ? coverHeightElem.getAttribute('data-content-cover-height') : ''; } var isFixedBgEarly = rec.getAttribute('data-fixed-bg') === 'y'; var selectorsList = ['.t-cover', '.t-cover__filter', '.t-cover__carrier', '.t-cover__wrapper']; // for support CR30N (querySelector need for Edit-mode) if (recordType === '734' || rec.querySelector('.t734')) selectorsList.push('.t-slds__items-wrapper'); var isParallax = coverCarrier.getAttribute('data-content-cover-parallax') === 'dynamic'; var elHeight = t_cover__getHeightFromAttr(coverSetByUserHeight); if (elHeight) { const processedHeight = `${Math.round(elHeight)}px`; const finalHeight = isScaled ? `calc(${processedHeight} / var(--t-zoom, 1))` : processedHeight; selectorsList.forEach(function (selector) { if (isParallax && selector === '.t-cover__carrier') return; var elementList = Array.prototype.slice.call(rec.querySelectorAll(selector)); elementList.forEach(function (element) { if (element) element.style.height = finalHeight; }); }); } var heightSetByUser = t_cover__getHeightFromAttr(coverSetByUserHeight); var calculatedHeight = t_cover__getPureHeight(cover); var coverHeight = heightSetByUser || calculatedHeight; // if it is not cover with fixed parallax, calculate pure cover height without appended height after previous calculation if (!isFixedBgEarly) { var cachedCoverHeight = cover.style.height; cover.style.height = ''; coverHeight = calculatedHeight; if (cachedCoverHeight) cover.style.height = cachedCoverHeight; } var contentHeight = t_cover__getContentHeight(rec); var coverPadding = 40; var minCheckedContentHeight = 300; var isCoverFullVH = coverCarrier ? coverCarrier.getAttribute('data-content-cover-height') === '100vh' : false; // if content highter then cover height; if cover has fixed bg in Safari if ((contentHeight > minCheckedContentHeight && coverHeight < contentHeight + coverPadding) || isFixedBgEarly) { t_cover__setRecalculatedHeight(rec, contentHeight); t_cover__updateResizeElem(rec); } else if ((window.t_cover__isMobile || 'ontouchend' in document) && isOrientationChange) { t_cover__setRecalculatedHeight(rec, contentHeight); t_cover__updateResizeElem(rec); } else if (window.t_cover__isMobile && isCoverFullVH) { selectorsList.forEach(function (selector) { var element = rec.querySelector(selector); if (element) element.style.height = document.documentElement.clientHeight + 'px'; }); } else if (coverHeight > contentHeight + coverPadding) { // исправляет ошибку, когда после условия: coverHeight < contentHeight + coverPadding // высота cover_carrier больше не обновлялась t_cover__setRecalculatedHeight(rec, contentHeight); t_cover__updateResizeElem(rec); } } function t_cover__getContentHeight(rec) { var contentList = Array.prototype.slice.call(rec.querySelectorAll('div[data-hook-content]')); if (contentList.length <= 1) return t_cover__getPureHeight(contentList[0]); // support for CR30N var contentHeight = contentList.map(function (content) { return t_cover__getPureHeight(content); }); contentHeight.sort(function (a, b) { return b - a; }); // return max possible height from content list return contentHeight[0] || 0; } /** * get height from data-attribute * * @param {string} height * @return {number} - calculated height */ function t_cover__getHeightFromAttr(height) { if (!height) return 0; if (height.indexOf('vh') !== -1) { return (parseInt(height, 10) * document.documentElement.clientHeight) / 100; } else { return parseInt(height, 10); } } /** * update cover height * * @param {HTMLElement} rec - current record * @param {number} contentHeight - height of content without padding */ function t_cover__setRecalculatedHeight(rec, contentHeight) { var coverCarrier = rec.querySelector('.t-cover__carrier'); var coverCarrierHeight = coverCarrier ? coverCarrier.getAttribute('data-content-cover-height') : ''; if (!coverCarrierHeight) { var coverHeightElem = rec.querySelector('[data-content-cover-height]'); coverCarrierHeight = coverHeightElem ? coverHeightElem.getAttribute('data-content-cover-height') : '0'; } var setByUserHeight = t_cover__getHeightFromAttr(coverCarrierHeight); var isDynamicParallax = coverCarrier ? coverCarrier.getAttribute('data-content-cover-parallax') === 'dynamic' : ''; const recordType = t_cover__getRecordType(rec); const isCR30N = recordType === '734'; const isTS208 = recordType === '942'; var contentHeightPadding = window.innerWidth <= 568 ? 40 : 120; var contentHeightExtraPadding = window.innerWidth <= 568 ? 50 : 100; if (isCR30N || isTS208) { contentHeightPadding = 0; contentHeightExtraPadding = 0; } const isScaled = t_cover__isScaled(rec); const zoomValue = isScaled ? parseFloat(getComputedStyle(rec).getPropertyValue('zoom')) || 1 : 1; if (isScaled) { contentHeight *= zoomValue; contentHeight += contentHeightPadding / zoomValue; if (contentHeight > 1000) contentHeight += contentHeightExtraPadding / zoomValue; } else { contentHeight += contentHeightPadding; if (contentHeight > 1000) contentHeight += contentHeightExtraPadding; } var finishHeight = contentHeight > setByUserHeight ? contentHeight : setByUserHeight; var heightPadding = 0; var selectorsList = ['.t-cover', '.t-cover__filter', '.t-cover__carrier', '.t-cover__wrapper']; // for support CR30N (querySelector need for Edit-mode) if (isCR30N || rec.querySelector('.t734')) selectorsList.push('.t-slds__items-wrapper'); if (isScaled && contentHeight === finishHeight) finishHeight /= zoomValue; const needProcessScale = isScaled && finishHeight === setByUserHeight; selectorsList.forEach(function (selector) { // block CR30N has more than one cover carrier var elementList = Array.prototype.slice.call(rec.querySelectorAll(selector)); elementList.forEach(function (element) { if ( isDynamicParallax && element && element.classList.contains('t-cover__carrier') && finishHeight < document.documentElement.clientHeight ) { heightPadding = document.documentElement.clientHeight * 0.2; const finalHeight = finishHeight + heightPadding + 'px'; element.style.height = needProcessScale ? `calc(${finalHeight} / var(--t-zoom, 1))` : finalHeight; } else if (element) { element.style.height = needProcessScale ? `calc(${finishHeight}px / var(--t-zoom, 1))` : finishHeight + 'px'; } }); }); coverCarrier.setAttribute('data-content-cover-updated-height', finishHeight + heightPadding + 'px'); var event = document.createEvent('Event'); event.initEvent('coverHeightUpdated', true, true); coverCarrier.dispatchEvent(event); } function t_cover__getRecordType(rec) { if (!rec) return ''; return ( rec.getAttribute('data-parenttplid') || rec.getAttribute('data-record-type') || rec.closest('.record')?.getAttribute('data-parenttplid') || rec.closest('.record')?.getAttribute('data-record-type') || '' ); } /** * @param {HTMLElement} rec - element which can be contains element .t-cover__carrier */ function t_cover__updateResizeElem(rec) { var allRec = document.getElementById('allrecords'); var isLazy = allRec ? allRec.getAttribute('data-tilda-lazy') === 'yes' : false; if (!isLazy) return; var cover = rec.querySelector('.t-cover__carrier'); t_onFuncLoad('t_lazyload_updateResize_elem', function () { t_lazyload_updateResize_elem(cover); }); } /** * check is need fixed for background in case if used fixed parallax (only for Safari) * * @param {string} id - of inited record * @returns {boolean} - in case */ function t_cover__checkIsFixForBgNeeded(id) { var rec = document.getElementById('rec' + id); var coverCarrier = rec ? rec.querySelector('.t-cover__carrier') : null; if (!coverCarrier) return false; var isFixedEarly = rec.getAttribute('data-fixed-bg') === 'y'; var videoFormats = ['mp4', 'webm', 'youtube', 'vimeo', 'rutube', 'kinescope', 'vkvideo', 'boomstream']; videoFormats = videoFormats.map(function (videoFormat) { return coverCarrier.getAttribute('data-content-video-url-' + videoFormat); }); var isFixedParallax = coverCarrier.getAttribute('data-content-cover-parallax') === 'fixed'; var isContainsVideo = videoFormats.some(function (url) { return url; }); var isMobile = window.t_cover__isMobile || 'ontouchend' in document; return isFixedParallax && window.isSafari && !isMobile && !isContainsVideo && !isFixedEarly; } /** * mode for fixed background position * * @param {string} id - of inited record */ function t_cover__fixBgFixedNode(id) { var isNeedFixForFixedParallax = t_cover__checkIsFixForBgNeeded(id); var rec = document.getElementById('rec' + id); if (!isNeedFixForFixedParallax || !rec) return; var recordType = rec.getAttribute('data-parenttplid') || rec.getAttribute('data-record-type'); var cover = rec.querySelector('.t-cover'); var coverParent = cover ? cover.parentElement : null; if (!document.getElementById('fixed-bg-cover')) { var style = document.createElement('style'); style.id = 'fixed-bg-cover'; var stylesContent = ''; //@formatter:off stylesContent += '.t-cover__container {'; stylesContent += 'position: relative;'; stylesContent += '}'; stylesContent += '.t-cover__container .t-cover {'; stylesContent += 'clip: rect(0, auto, auto, 0);'; stylesContent += 'position: absolute;'; stylesContent += 'top: 0;'; stylesContent += 'left: 0;'; stylesContent += 'width: 100%;'; stylesContent += 'height: 100% !important;'; stylesContent += '}'; stylesContent += '.t-cover__container .t-cover .t-cover__carrier {'; stylesContent += 'position: fixed;'; stylesContent += 'display: block;'; stylesContent += 'top: 0;'; stylesContent += 'left: 0;'; stylesContent += 'width: 100%;'; stylesContent += 'height: 100% !important;'; stylesContent += 'background-size: cover;'; stylesContent += 'background-position: center center;'; stylesContent += 'transform: translateZ(0);'; stylesContent += 'will-change: transform;'; stylesContent += '}'; //@formatter:on style.textContent = stylesContent; document.head.insertAdjacentElement('beforeend', style); } var newWrapper = document.createElement('div'); newWrapper.classList.add('t-cover__container'); coverParent.insertAdjacentElement('afterbegin', newWrapper); newWrapper.style.height = t_cover__getPureHeight(cover) + 'px'; newWrapper.appendChild(cover); // specific covers fixes - with video popup and avatar section var specificCovers = { 275: '.t256__video-container', 286: '.t266__video-container', 337: '.t-container', 906: '.t906__video-container', }; var classContainer = specificCovers[recordType]; var container = classContainer ? rec.querySelector(classContainer) : null; if (container) newWrapper.appendChild(container); } /** * set mode for fixed bg * * @param {string} id - of inited record * @returns {void} */ function t_cover__fixBgFixedStyles(id) { var rec = document.getElementById('rec' + id); var isNeedFixForBackground = t_cover__checkIsFixForBgNeeded(id); var cover = rec ? rec.querySelector('.t-cover') : null; var coverContainer = rec ? rec.querySelector('.t-cover__container') : null; if (!isNeedFixForBackground || !coverContainer || !cover) return; var coverHeight = cover.style.height; //cached cover height cover.style.height = 0; coverContainer.style.height = coverHeight; rec.setAttribute('data-fixed-bg', 'y'); } /** * get height of element without padding * * @param {HTMLElement} el - current element * @returns {number} - height of el */ function t_cover__getPureHeight(el) { if (!el) return 0; var elPaddingTop = parseInt(el.style.paddingTop) || 0; var elPaddingBottom = parseInt(el.style.paddingBottom) || 0; if (el.clientHeight) { return el.clientHeight - (elPaddingTop + elPaddingBottom); } else { return parseInt(window.getComputedStyle(el).height, 10); } } /** * return number of element height with it margins * * @param {HTMLElement} el - current element * @return {number} - height */ function t_cover__getFullHeight(el) { if (!el) return 0; var elHeight = el.offsetHeight; var elMarginTop = parseInt(el.style.marginTop) || 0; var elMarginBottom = parseInt(el.style.marginBottom) || 0; return elHeight + elMarginTop + elMarginBottom; } /** * smooth scroll * * @param {number} elTopPos - offset top finally position * @returns {void} - if current position equals finally position */ function t_cover__scrollToNextSection(elTopPos) { var documentHeight = Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight ); var bottomViewportPoint = documentHeight - document.documentElement.clientHeight; if (elTopPos > bottomViewportPoint) elTopPos = bottomViewportPoint; if (elTopPos === window.pageYOffset) return false; var currentPosition = window.pageYOffset; var step = (elTopPos - currentPosition) / 30; var difference = window.pageYOffset; var timerID = setInterval(function () { difference += step; window.scrollTo(0, difference); document.body.setAttribute('data-scrollable', 'true'); if ( (elTopPos - currentPosition < 0 && window.pageYOffset <= elTopPos) || (elTopPos - currentPosition > 0 && window.pageYOffset >= elTopPos) ) { clearInterval(timerID); document.body.removeAttribute('data-scrollable'); } }, 10); } // backward compatibility for BF311N function cover_setRecalculatedCoverHeight(a, b) { t_cover__setRecalculatedHeight(a, b); } function t_cover__getHeightWithoutPadding(a) { return t_cover__getPureHeight(a); }