syriastreet.com/assets/js/lib/inline-video.js
2023-10-11 18:20:29 +00:00

1 line
No EOL
3.4 KiB
JavaScript

define("makeVideoPlayableInline",[],function(){return function(){"use strict";function t(r,e,i,n){function t(e){Boolean(r[i])===Boolean(n)&&e.stopImmediatePropagation(),delete r[i]}r.addEventListener(e,t,!1)}function d(e,r,i,n){function t(e){i[r]=e}n&&t(e[r]),Object.defineProperty(e,r,{get:function(){return i[r]},set:t})}function p(e,r,i){i.addEventListener(r,function(){return e.dispatchEvent(new Event(r))})}function l(e,r){Promise.resolve().then(function(){e.dispatchEvent(new Event(r))})}function f(e,r,i){(n||0)+200<Date.now()&&(e[g]=!0,n=Date.now()),i||(e.currentTime=r),b[++v%3]=100*r|0}function m(e){return e.driver.currentTime>=e.video.duration}function a(){var e=this,r=e[y];return e.webkitDisplayingFullscreen?void e[h]():("data:"!==r.driver.src&&r.driver.src!==e.src&&(f(e,0,!0),r.driver.src=e.src),void(e.paused&&(r.paused=!1,e.buffered.length||e.load(),r.driver.play(),r.updater.start(),r.hasAudio||(l(e,"play"),r.video.readyState>=r.video.HAVE_ENOUGH_DATA&&l(e,"playing")))))}function o(e){var r=this,i=r[y];i.driver.pause(),i.updater.stop(),r.webkitDisplayingFullscreen&&r[c](),i.paused&&!e||(i.paused=!0,i.hasAudio||l(r,"pause"),r.ended&&(r[g]=!0,l(r,"ended")))}function u(r,e){var i,n,t,d,a,o,u,s,c=r[y]={};function v(e){u=d(v,o),t(e-(s||e)),s=e}c.paused=!0,c.hasAudio=e,c.video=r,c.updater=(n=function(e){var r=this;r.video.readyState>=r.video.HAVE_FUTURE_DATA?(r.hasAudio||(r.driver.currentTime=r.video.currentTime+e*r.video.playbackRate/1e3,r.video.loop&&m(r)&&(r.driver.currentTime=0)),f(r.video,r.driver.currentTime)):r.video.networkState!==r.video.NETWORK_IDLE||r.video.buffered.length||r.video.load(),r.video.ended&&(delete r.video[g],r.video.pause(!0))}.bind(c),t=n,d=requestAnimationFrame,a=cancelAnimationFrame,{start:function(){u||v(0)},stop:function(){a(u),u=null,s=0}}),e?c.driver=(n=r,i=new Audio,p(n,"play",i),p(n,"playing",i),p(n,"pause",i),i.crossOrigin=n.crossOrigin,i.src=n.src||n.currentSrc||"data:",i):(r.addEventListener("canplay",function(){r.paused||l(r,"playing")}),c.driver={src:r.src||r.currentSrc||"data:",muted:!0,paused:!0,pause:function(){c.driver.paused=!0},play:function(){c.driver.paused=!1,m(c)&&f(r,0)},get ended(){return m(c)}}),r.addEventListener("emptied",function(){var e=!c.driver.src||"data:"===c.driver.src;c.driver.src&&c.driver.src!==r.src&&(f(r,0,!0),c.driver.src=r.src,e?c.driver.play():c.updater.stop())},!1),r.addEventListener("webkitbeginfullscreen",function(){r.paused?e&&!c.driver.buffered.length&&c.driver.load():(r.pause(),r[h]())}),e&&(r.addEventListener("webkitendfullscreen",function(){c.driver.currentTime=r.currentTime}),r.addEventListener("seeking",function(){b.indexOf(100*r.currentTime|0)<0&&(c.driver.currentTime=r.currentTime)}))}function e(e,r,i){var n;void 0===r&&(r=!0),(i=void 0===i?!0:i)&&!s||e[y]||(u(e,r),n=(i=e)[y],i[h]=i.play,i[c]=i.pause,i.play=a,i.pause=o,d(i,"paused",n.driver),d(i,"muted",n.driver,!0),d(i,"playbackRate",n.driver,!0),d(i,"ended",n.driver),d(i,"loop",n.driver,!0),t(i,"seeking"),t(i,"seeked"),t(i,"timeupdate",g,!1),t(i,"ended",g,!1),e.classList.add("IIV"),!r&&e.autoplay&&e.play(),/iPhone|iPod|iPad/.test(navigator.platform))||console.warn("iphone-inline-video is not guaranteed to work in emulated environments")}var n,r="undefined"==typeof Symbol?function(e){return"@"+(e||"@")+Math.random()}:Symbol,s=/iPhone|iPod/i.test(navigator.userAgent)&&!matchMedia("(-webkit-video-playable-inline)").matches,y=r(),g=r(),h=r("nativeplay"),c=r("nativepause"),b=[],v=0;return e.isWhitelisted=s,e}()});