05-tilda-export-backup/Tilda_ Суджа Шрёдингера_files/tilda-video-processor-1.0.min.js

2 lines
16 KiB
JavaScript
Raw Normal View History

2025-10-29 16:50:39 +00:00
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="hidd