UNPKG

yall-js

Version:
3 lines (2 loc) 1.71 kB
function o(o,e){for(const t in e){const n=e[t];o.addEventListener(t,n.listener||n,n.options||void 0)}}const e="IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype,t=/baidu|(?:google|bing|yandex|duckduck)bot/i.test(navigator.userAgent),n=["src","poster"];function r(o,e){for(const t of n)t in o.dataset&&(o.setAttribute(t,o.dataset[t]),o.classList.contains(e)&&o.classList.remove(e))}function s(o,e,t,n){if("VIDEO"==o.nodeName){const t=Array.from(o.querySelectorAll("source"));for(const o of t)r(o,e);o.load()}r(o,e);const s=o.classList;s.contains(t)&&(s.remove(t),s.add(n))}function i(n){const r=(null==n?void 0:n.lazyClass)||"lazy",i=(null==n?void 0:n.lazyBackgroundClass)||"lazy-bg",c=(null==n?void 0:n.lazyBackgroundLoaded)||"lazy-bg-loaded",l=(null==n?void 0:n.threshold)||200,a=(null==n?void 0:n.events)||{},d=(null==n?void 0:n.observeChanges)||!1,u=(null==n?void 0:n.observeRootSelector)||"body",v=(null==n?void 0:n.mutationObserverOptions)||{childList:!0,subtree:!0},f=`video.${r},.${i}`;let b=Array.from(document.querySelectorAll(f));for(const e of b)o(e,a);if(!0===e&&!1===t){var y=new IntersectionObserver(o=>{for(const e of o)if(e.isIntersecting||e.intersectionRatio){const{target:o}=e;s(o,r,i,c),y.unobserve(o),b=b.filter(e=>e!=o),0===b.length&&!1===d&&y.disconnect()}},{rootMargin:`${l}px 0%`});for(const o of b)y.observe(o);d&&new MutationObserver(()=>{const n=document.querySelectorAll(f);for(const r of n)!1===b.includes(r)&&(b.push(r),o(r,a),!0===e&&!1===t&&y.observe(r))}).observe(document.querySelector(u),v)}else if(t)for(const o of b)s(o,r,i,c)}export{i as yall}; //# sourceMappingURL=yall.modern.js.map