601var viewportTopPos = window.pageYOffset;602var videoTopPos = el.getBoundingClientRect().top + viewportTopPos;603var videoHeight = el.clientHeight;604var videoBottomPos = videoTopPos + videoHeight;605var viewportBottomPos = viewportTopPos + document.documentElement.clientHeight;606if (viewportTopPos > videoBottomPos || viewportBottomPos < videoTopPos) {607return;608}609var volumeValue = 0;610if (videoBottomPos > viewportBottomPos && viewportBottomPos > viewportTopPos) {611volumeValue = Math.floor(100 * ((videoBottomPos - viewportBottomPos) / videoHeight));
} else if (viewportTopPos > videoTopPos && viewportTopPos < videoBottomPos) { volumeValue = Math.floor(100 * ((viewportTopPos - videoTopPos) / videoHeight)); } player.setVolume(100 - volumeValue); }, 100) );}/** * @param {Object} player * @param {number} playerState * @param {HTMLElement} el */function t_videoprocessor__pauseVideo(player, playerState, el) { el.setAttribute('data-video-invisible', 'y'); if (playerState !== 2) { player.pauseVideo(); }}/** * Processing video added with iframe * @param {HTMLElement} el - current el * @param {Object} params - cover params */function t_videoprocessor__processIframeVideo(el, params) { if (el.hasAttribute('data-content-video-url-vimeo')) { t_videoprocessor__processVimeoVideo(el, params); } else if (el.hasAttribute('data-content-video-url-vkvideo')) { t_videoprocessor__processVkVideo(el, params); } else if (el.hasAttribute('data-content-video-url-kinescope')) { t_videoprocessor__processKinescopeVideo(el, params); } else if (el.hasAttribute('data-content-video-url-rutube')) { t_videoprocessor__processRutubeVideo(el, params); }}/** * Generates URL for iframe video * @param {('rutube'|'kinescope')} videoType - type of video * @param {string} id - id for video * @param {string} hash - hash for video * @param {boolean} noloop - if video should not be looped * @return {string} - url for iframe */function t_videoprocessor__getIframeVideoUrl(videoType, id, hash, noloop) { var startUrlByType = { vimeo: 'https://player.vimeo.com/video/', rutube: 'https://rutube.ru/play/embed/', kinescope: 'https://kinescope.io/embed/', }; var startUrl = startUrlByType[videoType]; if (!startUrl) return; var idParts = id.split('?t='); var id = idParts[0]; var start = idParts[1] || 0; var url = startUrl + id; var params = 'autoplay=true&muted=true&controls=false' + (noloop ? '' : '&loop=true') + (start ? '&t=' + start : ''); if (videoType === 'vimeo') { url += '/?' + (hash ? 'h=' + hash + '&' : '') + params; } else if (videoType === 'rutube') { url += '/?p=' + hash + '&' + params; } else if (videoType === 'kinescope') { url += '/?' + params + '&autopause=false'; } return url;}/** * Generates HTML for iframe * @param {string} url - url of video * @param {string} height - height of cover * @return {HTMLElement} - iframe */function t_videoprocessor__getIframeHtml(url, height) { var iframe = document.createElement('iframe'); iframe.src = url; iframe.frameBorder = '0'; iframe.setAttribute( 'allow', 'autoplay; fullscreen; picture-in-picture; encrypted-media; gyroscope; accelerometer; clipboard-write;' ); iframe.style.width = '100%'; iframe.style.height = height || '100%';