05-tilda-export-backup/Tilda_ В лабиринтах судьбы Михаила Михалкова_files/tilda-video-processor-1.0.min.js
2025-10-29 19:50:39 +03:00

2 lines
16 KiB
JavaScript

function processYoutubeVideo(e,t){if(!document.getElementById("youtube-api")){var o=document.createElement("script");o.id="youtube-api",o.src="https://www.youtube.com/iframe_api",document.head.insertAdjacentElement("beforeend",o)}t_videoprocessor__onFuncLoad("YT",(function(){var o={"url-youtube":"",nomute:"",noloop:"",nocover:""};for(var i in o){var r=e.getAttribute("data-content-video-"+i);r&&(o[i]=r)}"yes"!==o.nocover&&(o.nomute=""),o.mute="yes"!==o.nomute,o.loop="yes"!==o.noloop,o.cover="yes"!==o.nocover,t_videoprocessor__setYoutubePlayer(e,o),t_onReady((function(){t_videoprocessor__updateVideoHeight(e,t,"youtube")})),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchend"in document||(window.addEventListener("resize",(function(){o.cover&&t_videoprocessor__updateVideoHeight(e,t,"youtube")})),e.addEventListener("coverHeightUpdated",(function(){t_videoprocessor__updateVideoHeight(e,t,"youtube")}),{once:!0}))}))}function t_videoprocessor__updateVideoHeight(e,t,o){var i=t;if("youtube"===o){var r=t_videoprocessor__getHeightFromAttr(t),n;i=(parseInt(e.getAttribute("data-content-cover-updated-height"),10)||0)>r?e.getAttribute("data-content-cover-updated-height"):t}setWidthAndHeightVideo(e,i,o)}function t_videoprocessor__setYoutubePlayer(e,t){var o=document.createElement("iframe"),i;o.src=t_videoprocessor__generateYoutubeURL(t),o.frameBorder="0",o.allow="fullscreen",o.style.opacity="0",e.appendChild(o);var r=new YT.Player(o,{events:{onReady:function i(r){-1===r.target.getPlayerState()&&"y"!==o.getAttribute("programmly-updated")&&(o.src=t_videoprocessor__generateYoutubeURL(t),o.setAttribute("programmly-updated","y")),o.style.opacity="",t_videoprocessor__pauseAndPlayYouTubeVideo(e,r.target,t.mute),t_videoprocessor__muteYouTubeVideo(r,t),r.target.setLoop(!0)},onStateChange:function e(o){t_videoprocessor__muteYouTubeVideo(o,t),o.data===YT.PlayerState.PLAYING?i=t_videoprocessor__updateLoopedVideo(o.target,t):window.clearInterval(i)}}})}function t_videoprocessor__muteYouTubeVideo(e,t){e.target.setVolume&&t.mute&&e.target.setVolume(0)}function t_videoprocessor__updateLoopedVideo(e,t){return setInterval((function(){var o=e.getCurrentTime(),i=e.getDuration();i&&o+1>i&&(e.seekTo(0),t.noloop&&(e.stopVideo(),e.clearVideo()))}),1e3)}function t_videoprocessor__processHTML5Video(e,t){if(e){var o=window.getComputedStyle(e);"static"!==o.position&&e.style.position||(e.style.position="relative"),t.height=e.offsetHeight;var i=parseInt(o.height.replace("px",""),10),r=parseInt(o.width.replace("px",""),10);(window.t_cover__isMobile||"ontouchend"in document)&&r<i&&e.setAttribute("data-content-video-ratio",i/r);var n=t_videoprocessor__createHTML5Video(t),d;if(e.insertAdjacentElement("beforeend",n),t_onReady((function(){t_videoprocessor__updateVideoHeight(n,window.getComputedStyle(e).height,"html5")})),e.addEventListener("coverHeightUpdated",(function(){t_videoprocessor__updateVideoHeight(n,window.getComputedStyle(e).height,"html5")}),{once:!0}),window.addEventListener("resize",(function(){t_videoprocessor__updateVideoHeight(n,window.getComputedStyle(e).height,"html5")})),"IntersectionObserver"in window)new IntersectionObserver((function(e){e.forEach((function(e){var t,o=e.target.querySelector("video");o&&(e.isIntersecting?o.readyState>=2&&o.play():o.pause())}))})).observe(n);else window.addEventListener("scroll",t_throttle((function(){t_videoprocessor__pauseAndPlayHTMLVideo(n)}),100));return n.querySelector("video")}}function t_videoprocessor__pauseAndPlayHTMLVideo(e){var t=e.querySelector("video");if(t){var o=window.pageYOffset,i=o+document.documentElement.clientHeight,r=e.getBoundingClientRect().top+o,n,d=r+e.offsetHeight,a=500,s;switch(s=i>r&&o<=d?"inside":"near"){case"inside":t.readyState>=2&&t.play();break;case"near":t.pause()}}}function t_videoprocessor__createHTML5Video(e){var t=document.createElement("div");t.style.position=e.position,t.style.zIndex=e.zIndex,t.style.top="0",t.style.left="0",t.style.height=e.height+"px",t.style.width=e.width+"px",t.style.opacity=e.opacity,t.style.overflow="hidden";var o=document.createElement("video");o.style.position="relative",o.style.zIndex=e.zIndex,o.style.poster=e.poster,o.style.top="0",o.style.left="0",o.style.minHeight="100%",o.style.minWidth="100%",o.style.height=e.height+"px",o.style.width=e.width+"px",o.style.objectFit="cover",o.autoplay=e.autoplay,o.loop=e.loop,o.muted=e.muted,o.volume=e.volume,o.setAttribute("playsinline",""),o.addEventListener("canplay",(function(){e.autoplay&&(o.muted=!0,o.play())}));var i=e.mp4?'video/mp4; codecs="avc1.42E01E, mp4a.40.2"':'video/webm; codecs="vp8, vorbis"',r,n;if(document.createElement("video").canPlayType(i))o.src=e.webm||e.mp4,t.insertAdjacentElement("beforeend",o);else if(!t.querySelector(".no-video-loader")){var d=document.createElement("img");d.setAttribute("src",e.poster),d.style.position="absolute",d.style.zIndex=e.zIndex,d.style.top="0",d.style.left="0",d.style.minHeight="100%",d.style.minWidth="100%",d.classList.add("no-video-loader"),t.insertAdjacentElement("beforeend",d)}return t}function setWidthAndHeightVideo(e,t,o){var i=e.querySelector("iframe"),r=e.closest(".t-cover__carrier");if("html5"===o){var n=e;i=(e=e.closest(".t-cover__carrier")).querySelector("video")}var d="yes"!==e.getAttribute("data-content-video-nocover"),a="yes"!==e.getAttribute("data-content-video-noadcut-youtube"),s="youtube"===o||"rutube"===o||"vk"===o,c=e.getAttribute("data-content-video-ratio"),u=a&&s?220:0,l=.5625;if(c&&parseFloat(c)>0&&(l=parseFloat(c)),d){var p=t_videoprocessor__getHeight(t,d,e,l),v=(null==r?void 0:r.clientWidth)||window.innerWidth,_=v*l,m=1;_-u<p&&(m=_<p?p/_:_/p,m+=.02);var h=Math.floor(v*m),g=Math.floor((_+u)*m),y=g-p,f=h-v;i&&(i.style.height=g+"px"),i&&(i.style.width=h+"px"),"html5"===o&&(n.style.height=g+"px",n.style.width=h+"px"),i&&(i.style.marginTop=y>0?-Math.floor(y/2)+"px":"0"),i&&(i.style.marginLeft=f>0?-Math.floor(f/2)+"px":"0")}else{var b=t_videoprocessor__getHeight(t,d,e,l);i&&(i.style.width="100%"),i&&(i.style.height=b+"px")}}function t_videoprocessor__getHeight(e,t,o,i){var r;if(e||(t?e="100vh":r=Math.floor(o.offsetWidth*i)),-1!==e.indexOf("vh")){var n=parseInt(e,10)||0;r=Math.floor(document.documentElement.clientHeight*(n/100))}else e&&(r=parseInt(e,10)||0);return r||0}function t_videoprocessor__getHeightFromAttr(e){return e?-1!==e.indexOf("vh")?parseInt(e,10)*document.documentElement.clientHeight/100:parseInt(e,10):0}function t_videoprocessor__generateYoutubeURL(e){var t=e["url-youtube"],o="https://www.youtube.com/embed",i=e.cover,r=e.mute;-1===t.indexOf(o)&&(-1===t.indexOf("/")&&(t="/"+t),t=o.concat(t)),t+=-1===t.indexOf("?")?"?":"&";var n=location.protocol+"//"+location.host,d=t.replace(o+"/",""),a=d.indexOf("?");return-1!==a&&(d=d.slice(0,a)),i?(t+="autoplay=1",t+="&loop=1",t+="&enablejsapi=1",t+="&playerapiid=featuredytplayer",t+="&controls=0",t+="&modestbranding=1",t+="&rel=0",t+="&showinfo=0",t+="&color=white",t+="&iv_load_policy=3",t+="&theme=light",t+="&wmode=transparent",t+="&origin="+n,t+="&playlist="+d):(t+="autoplay=0",t+="&loop=0",t+="&enablejsapi=1",t+="&playerapiid=featuredytplayer",t+="&controls=1",t+="&modestbranding=1",t+="&rel=0",t+="&showinfo=0",t+="&color=black",t+="&iv_load_policy=3",t+="&theme=dark",t+="&wmode=transparent",t+="&origin="+n),r&&(t+="&mute=1"),t}function t_videoprocessor__pauseAndPlayYouTubeVideo(e,t,o){var i;"IntersectionObserver"in window?new IntersectionObserver((function(o){o.forEach((function(o){var i=o.target,r=t.getPlayerState(),n="y"===e.getAttribute("data-video-invisible");o.isIntersecting?(-1===r||3===r||5===r||2===r&&n)&&(t.playVideo(),i.removeAttribute("data-video-invisible")):t_videoprocessor__pauseVideo(t,r,i)}))})).observe(e):window.addEventListener("scroll",t_throttle((function(){var o=window.pageYOffset,i,r=o+document.documentElement.clientHeight,n=e.getBoundingClientRect().top+o,d,a=n+e.offsetHeight,s="y"===e.getAttribute("data-video-invisible"),c=t.getPlayerState(),u=500,l;switch(l=r>n&&o<=a?"inside":r<n&&r>n-u||o>a&&o<a+u?"near":"far"){case"inside":(-1===c||3===c||5===c||2===c&&s)&&(t.playVideo(),e.removeAttribute("data-video-invisible"));break;case"near":case"far":t_videoprocessor__pauseVideo(t,c,e)}}),100));o||window.addEventListener("scroll",t_throttle((function(){var o=window.pageYOffset,i=e.getBoundingClientRect().top+o,r=e.clientHeight,n=i+r,d=o+document.documentElement.clientHeight;if(!(o>n||d<i)){var a=0;n>d&&d>o?a=Math.floor((n-d)/r*100):o>i&&o<n&&(a=Math.floor((o-i)/r*100)),t.setVolume(100-a)}}),100))}function t_videoprocessor__pauseVideo(e,t,o){o.setAttribute("data-video-invisible","y"),2!==t&&e.pauseVideo()}function t_videoprocessor__processIframeVideo(e,t){e.hasAttribute("data-content-video-url-vimeo")?t_videoprocessor__processVimeoVideo(e,t):e.hasAttribute("data-content-video-url-vkvideo")?t_videoprocessor__processVkVideo(e,t):e.hasAttribute("data-content-video-url-kinescope")?t_videoprocessor__processKinescopeVideo(e,t):e.hasAttribute("data-content-video-url-rutube")&&t_videoprocessor__processRutubeVideo(e,t)}function t_videoprocessor__getIframeVideoUrl(e,t,o,i){var r,n={vimeo:"https://player.vimeo.com/video/",rutube:"https://rutube.ru/play/embed/",kinescope:"https://kinescope.io/embed/"}[e];if(n){var d=t.split("?t="),t=d[0],a=d[1]||0,s=n+t,c="autoplay=true&muted=true&controls=false"+(i?"":"&loop=true")+(a?"&t="+a:"");return"vimeo"===e?s+="/?"+(o?"h="+o+"&":"")+c:"rutube"===e?s+="/?p="+o+"&"+c:"kinescope"===e&&(s+="/?"+c+"&autopause=false"),s}}function t_videoprocessor__getIframeHtml(e,t){var o=document.createElement("iframe");return o.src=e,o.frameBorder="0",o.setAttribute("allow","autoplay; fullscreen; picture-in-picture; encrypted-media; gyroscope; accelerometer; clipboard-write;"),o.style.width="100%",o.style.height=t||"100%",o.setAttribute("webkitAllowFullScreen",""),o.setAttribute("mozallowfullscreen",""),o.setAttribute("allowFullScreen",""),o.innerHTML="<p>Your browser don't support videos.</p>",o}function t_videoprocessor__processVimeoVideo(e,t){var o=e.getAttribute("data-content-video-url-vimeo");if(o){var i=t["video-noloop"],r,n=t_videoprocessor__getIframeVideoUrl("vimeo",o,e.getAttribute("data-content-video-hash-vimeo")||"",i),d=t_videoprocessor__getIframeHtml(n,t["cover-height"]);n?(e.insertAdjacentElement("beforeend",d),t_onReady((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vimeo")})),e.addEventListener("coverHeightUpdated",(function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vimeo")}),{once:!0}),window.addEventListener("resize",t_throttle((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vimeo")}),100))):e.style.backgroundImage=null}else e.style.backgroundImage=null}function t_videoprocessor__processRutubeVideo(e,t){var o=e.getAttribute("data-content-video-url-rutube");if(o){var i=t["video-noloop"],r,n=t_videoprocessor__getIframeVideoUrl("rutube",o,e.getAttribute("data-content-video-hash-rutube")||"",i);if(n){var d=t_videoprocessor__getIframeHtml(n,t["cover-height"]),a=!1,s;if(window.addEventListener("message",(function(e){if(e){var t="";try{t="string"==typeof e.data?JSON.parse(e.data):e.data}catch(o){console.error(o)}t.data&&("player:ready"===t.type&&-1!==d.src.indexOf(t.data.videoId)?(t_videoprocessor__doRutubeCommand(d,"stop"),t_videoprocessor__doRutubeCommand(d,"mute")):"player:changeState"!==t.type||"buffering"!==t.data.state||a?!i&&"player:changeState"===t.type&&["stopped","completed"].includes(t.data.state)&&t_videoprocessor__doRutubeCommand(d,"play"):(a=!0,t_videoprocessor__doRutubeCommand(d,"play")))}})),e.style.backgroundImage=null,e.insertAdjacentElement("beforeend",d),t_onReady((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"rutube")})),e.addEventListener("coverHeightUpdated",(function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"rutube")}),{once:!0}),window.addEventListener("resize",t_throttle((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"rutube")}),100)),"IntersectionObserver"in window)new IntersectionObserver((function(e){e.forEach((function(e){var t;if(e.target===d){var o=e.isIntersecting?"play":"pause";t_videoprocessor__doRutubeCommand(d,o)}}))})).observe(d)}else e.style.backgroundImage=null}else e.style.backgroundImage=null}function t_videoprocessor__doRutubeCommand(e,t){e.contentWindow.postMessage(JSON.stringify({type:"player:"+t,data:{}}),"*")}function t_videoprocessor__processKinescopeVideo(e,t){var o=e.getAttribute("data-content-video-url-kinescope");if(o){var i,r=t_videoprocessor__getIframeVideoUrl("kinescope",o,null,t["video-noloop"]);if(r){var n=document.createElement("div");n.classList.add("t-cover__video__wrapper"),n.style.height=t["cover-height"];var d=t_videoprocessor__getIframeHtml(r);n.insertAdjacentElement("beforeend",d),e.insertAdjacentElement("beforeend",n),t_onReady((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(n,t,"kinescope")})),e.addEventListener("coverHeightUpdated",(function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(n,t,"kinescope")}),{once:!0}),window.addEventListener("resize",t_throttle((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(n,t,"kinescope")}),100)),e.style.backgroundImage=null}else e.style.backgroundImage=null}else e.style.backgroundImage=null}function t_videoprocessor__processVkVideo(e,t){var o=e.getAttribute("data-content-video-url-vkvideo");if(o){var i=(o=o.replace(/https:\/\/(vk\.com|vk\.ru|vkvideo\.ru)\/video/,"")).split("_"),r=e.getAttribute("data-content-video-hash-vkvideo")||"",n=0,d,a=t_videoprocessor__getIframeHtml("https://vk.com/video_ext.php?oid="+i[0]+"&id="+i[1]+"&hd=2"+(r?"&hash="+r:"")+"&js_api=1");e.insertAdjacentElement("beforeend",a);var s=t["video-noloop"];t_onFuncLoad("t_loadJsFile",(function(){t_loadJsFile("https://vk.com/js/api/videoplayer.js",(function(){t_onFuncLoad("VK",(function(){var t=VK.VideoPlayer(a),o;(t.on("inited",(function(){t.mute(),t.play(),n=window.getComputedStyle(e).height||0,t_videoprocessor__updateVideoHeight(e,n,"vk")})),s||t.on("ended",(function(){t.play()})),"IntersectionObserver"in window)&&new IntersectionObserver((function(e){e.forEach((function(e){var o,i;t&&(e.target===a&&(e.isIntersecting?t.play:t.pause)())}))})).observe(a)}))}))})),t_onReady((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vk")})),e.addEventListener("coverHeightUpdated",(function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vk")}),{once:!0}),window.addEventListener("resize",t_throttle((function(){var t=window.getComputedStyle(e).height||0;t_videoprocessor__updateVideoHeight(e,t,"vk")}),100)),e.style.backgroundImage=null}else e.style.backgroundImage=null}function t_videoprocessor__onFuncLoad(e,t){var o;"object"==typeof window[e]&&"function"==typeof window[e].Player?t():o=setInterval((function(){"object"==typeof window[e]&&"function"==typeof window[e].Player&&(t(),clearInterval(o),o=0)}),100),window.addEventListener("load",(function(){setTimeout((function(){if(o){if("object"!=typeof window[e]||"function"!=typeof window[e].Player)throw clearInterval(o),new Error(e+" is undefined");t(),clearInterval(o)}}),5e3)}))}Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.msMatchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.webkitMatchesSelector||Element.prototype.oMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){for(var t=this;t&&1===t.nodeType;){if(Element.prototype.matches.call(t,e))return t;t=t.parentElement||t.parentNode}return null});