PageSourceSearch

https://moselle.tv/wp-content/cache/min/1/wp-content/plugins/moselle-live/assets/js/front.js?ver=1790598692

js moselle.tv collected 2026-10-02 07:37:15 UTC 11,425 bytes, 35 lines download raw bytes

1document.addEventListener('DOMContentLoaded',()=>{if(!window.MoselleLiveFront)return;document.querySelectorAll('.moselle-live-wrapper').forEach((wrapper)=>{const postId=wrapper.dataset.postId;const scrollEl=wrapper.querySelector('.moselle-live-scroll');const listEl=wrapper.querySelector('.moselle-live-list');const refreshButton=wrapper.querySelector('.moselle-live-refresh-button');const refreshStatus=wrapper.querySelector('.moselle-live-refresh-status');const scrollHint=wrapper.querySelector('.moselle-live-scroll-hint');const headlineEl=wrapper.querySelector('.moselle-live-headline');const descriptionEl=wrapper.querySelector('.moselle-live-description');if(!postId||!listEl)return;const refreshInterval=parseInt(MoselleLiveFront.refreshInterval||'60000',10)||60000;const requestTimeout=parseInt(MoselleLiveFront.requestTimeout||'25000',10)||25000;const watchdogInterval=parseInt(MoselleLiveFront.watchdogInterval||'30000',10)||30000;const staleAfter=Math.max(refreshInterval*2.5,150000);let lastHtml=listEl.innerHTML;let isRefreshing=!1;let intervalId=null;let stopTimeoutId=null;let watchdogId=null;let viewportRafId=null;let failureCount=0;let lastSuccessAt=Date.now();let lastAttemptAt=0;function getVisibleItemsCount(){const count=parseInt(wrapper.dataset.visibleItems||'5',10);return Number.isFinite(count)&&count>0?count:5}
2function updateScrollAffordance(){if(!scrollEl)return;const isScrollable=scrollEl.classList.contains('is-scrollable')&&(scrollEl.scrollHeight-scrollEl.clientHeight>3);const hasScrolled=isScrollable&&scrollEl.scrollTop>3;const canScrollDown=isScrollable&&(scrollEl.scrollTop+scrollEl.clientHeight<scrollEl.scrollHeight-3);const isAtTop=isScrollable&&scrollEl.scrollTop<=3;scrollEl.classList.toggle('has-scrolled',hasScrolled);scrollEl.classList.toggle('can-scroll-down',canScrollDown);scrollEl.classList.toggle('show-scroll-hint',canScrollDown&&isAtTop&&!!scrollHint);if(!isScrollable){scrollEl.classList.remove('has-scrolled','can-scroll-down','show-scroll-hint')}}
3function scheduleViewportUpdate(){if(viewportRafId)window.cancelAnimationFrame(viewportRafId);viewportRafId=window.requestAnimationFrame(()=>{viewportRafId=null;applyViewportHeight()})}
4function bindMediaLoadReflow(){if(!listEl)return;listEl.querySelectorAll('img').forEach((img)=>{if(!img.complete){img.addEventListener('load',scheduleViewportUpdate,{once:!0});img.addEventListener('error',scheduleViewportUpdate,{once:!0})}});listEl.querySelectorAll('iframe').forEach((iframe)=>{iframe.addEventListener('load',scheduleViewportUpdate,{once:!0})});listEl.querySelectorAll('video').forEach((video)=>{if(video.readyState<1){video.addEventListener('loadedmetadata',scheduleViewportUpdate,{once:!0});video.addEventListener('error',scheduleViewportUpdate,{once:!0})}})}
5function applyViewportHeight(){if(!scrollEl||!listEl)return;const items=Array.from(listEl.querySelectorAll('.moselle-live-item'));const visibleItems=getVisibleItemsCount();if(!items.length||items.length<=visibleItems){scrollEl.style.maxHeight='none';scrollEl.classList.remove('is-scrollable');updateScrollAffordance();return}
6const total=items.slice(0,visibleItems).reduce((sum,item)=>sum+item.offsetHeight,0);if(total>0){scrollEl.style.maxHeight=`${Math.ceil(total)}px`;scrollEl.classList.add('is-scrollable')}
7bindMediaLoadReflow();updateScrollAffordance()}
8function setStatus(message,type=''){if(!refreshStatus)return;refreshStatus.textContent=message||'';refreshStatus.classList.toggle('is-warning',type==='warning');refreshStatus.classList.toggle('is-error',type==='error')}
9function setButtonState(loading){if(!refreshButton)return;refreshButton.disabled=!!loading;refreshButton.textContent=loading?(MoselleLiveFront.refreshingLabel||'Actualisation...'):(MoselleLiveFront.refreshLabel||'Rafraîchir')}
10function stopAutoRefresh(showStatus=!0){if(intervalId){window.clearInterval(intervalId);intervalId=null}
11if(stopTimeoutId){window.clearTimeout(stopTimeoutId);stopTimeoutId=null}
12wrapper.dataset.autoRefreshActive='0';if(showStatus)setStatus(MoselleLiveFront.closedLabel||'Direct clos — actualisation automatique arrêtée')}
13function startAutoRefresh(){wrapper.dataset.autoRefreshActive='1';if(intervalId)return;intervalId=window.setInterval(()=>refreshLive(!1,'interval'),refreshInterval)}
14function syncAutoRefreshState(data={}){const liveStatus=data.live_status||wrapper.dataset.liveStatus||'open';const activeFromServer=parseInt(data.auto_refresh_active??wrapper.dataset.autoRefreshActive??'1',10)===1;const stopAt=parseInt(data.auto_refresh_stop_at??wrapper.dataset.autoRefreshStopAt??'0',10)||0;const serverTime=parseInt(data.server_time??wrapper.dataset.serverTime??`${Math.floor(Date.now() / 1000)}`,10)||Math.floor(Date.now()/1000);wrapper.dataset.liveStatus=liveStatus;wrapper.dataset.autoRefreshStopAt=`${stopAt}`;wrapper.dataset.serverTime=`${serverTime}`;if(liveStatus!=='closed'){startAutoRefresh();return}
15if(!activeFromServer){stopAutoRefresh(!0);return}
16startAutoRefresh();if(stopTimeoutId){window.clearTimeout(stopTimeoutId);stopTimeoutId=null}
17if(stopAt>0){const remainingMs=Math.max(0,(stopAt-serverTime)*1000);if(remainingMs===0){stopAutoRefresh(!0)}else{stopTimeoutId=window.setTimeout(()=>stopAutoRefresh(!0),remainingMs+250)}}}
18function buildEntriesUrl(){const params=new URLSearchParams({moselle_live_nocache:`${Date.now()}`,r:Math.random().toString(36).slice(2,10)});return `${MoselleLiveFront.root}entries/${postId}?${params.toString()}`}
19async function fetchJsonWithTimeout(url){const controller=new AbortController();const timeoutId=window.setTimeout(()=>controller.abort(),requestTimeout);try{const response=await fetch(url,{method:'GET',cache:'no-store',credentials:'same-origin',signal:controller.signal,headers:{'Cache-Control':'no-cache, no-store, must-revalidate',Pragma:'no-cache',Expires:'0',Accept:'application/json'}});const text=await response.text();let data={};try{data=text?JSON.parse(text):{}}catch(error){throw new Error('Réponse du serveur illisible.')}
20if(!response.ok){throw new Error(data.message||'Échec de l’actualisation.')}
21return data}finally{window.clearTimeout(timeoutId)}}
22async function postJsonWithTimeout(url,payload){const controller=new AbortController();const timeoutId=window.setTimeout(()=>controller.abort(),requestTimeout);try{const response=await fetch(url,{method:'POST',cache:'no-store',credentials:'same-origin',signal:controller.signal,headers:{'Content-Type':'application/json',Accept:'application/json','Cache-Control':'no-cache, no-store, must-revalidate',Pragma:'no-cache',Expires:'0'},body:JSON.stringify(payload||{})});const text=await response.text();let data={};try{data=text?JSON.parse(text):{}}catch(error){throw new Error('Réponse du serveur illisible.')}
23if(!response.ok&&!data.html){throw new Error(data.message||'Vote impossible.')}
24return data}finally{window.clearTimeout(timeoutId)}}
25function bindPolls(){if(!listEl||listEl.dataset.pollsBound==='1')return;listEl.dataset.pollsBound='1';listEl.addEventListener('click',async(event)=>{const button=event.target.closest('.moselle-live-poll-vote');if(!button)return;const poll=button.closest('.moselle-live-poll');if(!poll)return;const pollId=poll.dataset.pollId||'';const checked=poll.querySelector('input[type="radio"]:checked');const status=poll.querySelector('.moselle-live-poll-status');if(!checked){if(status)status.textContent='Choisissez une réponse.';return}
26event.preventDefault();button.disabled=!0;if(status)status.textContent='Vote en cours...';try{const data=await postJsonWithTimeout(`${MoselleLiveFront.root}poll-vote/${postId}/${pollId}`,{option_id:checked.value});if(data.html){poll.outerHTML=data.html;try{window.localStorage.setItem(`moselle_live_poll_${pollId}`,'1')}catch(e){}
27scheduleViewportUpdate()}else if(status){status.textContent=data.message||'Vote enregistré.'}}catch(error){button.disabled=!1;if(status)status.textContent=error.message||'Vote impossible.'}})}
28function bindClickToPlayVideos(){if(!listEl||listEl.dataset.clickToPlayBound==='1')return;listEl.dataset.clickToPlayBound='1';listEl.addEventListener('click',(event)=>{const button=event.target.closest('.moselle-live-video-play-button');if(!button)return;const figure=button.closest('.moselle-live-video-clicktoplay');if(!figure)return;const src=figure.dataset.embedSrc||'';if(!src)return;event.preventDefault();button.disabled=!0;const iframe=document.createElement('iframe');
28iframe.src=src;iframe.title='Dailymotion Video Player';iframe.loading='lazy';iframe.allowFullscreen=!0;iframe.setAttribute('frameborder','0');iframe.setAttribute('allow','fullscreen; picture-in-picture; web-share');iframe.referrerPolicy='strict-origin-when-cross-origin';const embed=document.createElement('div');embed.className='moselle-live-video-embed';embed.appendChild(iframe);figure.innerHTML='';figure.appendChild(embed);iframe.addEventListener('load',scheduleViewportUpdate,{once:!0});scheduleViewportUpdate()})}
29function applyPayload(data){if(!data||typeof data!=='object')return;if(typeof data.visible_items!=='undefined')wrapper.dataset.visibleItems=data.visible_items;if(typeof data.headline==='string'&&headlineEl)headlineEl.textContent=data.headline;if(typeof data.description==='string'&&descriptionEl)descriptionEl.textContent=data.description;if(typeof data.html==='string'&&data.html!==lastHtml){listEl.innerHTML=data.html;lastHtml=data.html}
30applyViewportHeight();syncAutoRefreshState(data)}
31async function refreshLive(manual=!1,reason='auto'){if(isRefreshing)return;isRefreshing=!0;lastAttemptAt=Date.now();setButtonState(!0);if(manual){setStatus(MoselleLiveFront.refreshingLabel||'Actualisation...')}
32try{const data=await fetchJsonWithTimeout(buildEntriesUrl());failureCount=0;lastSuccessAt=Date.now();applyPayload(data);if(parseInt(data.auto_refresh_active||0,10)===1&&data.refreshed_at){setStatus(`${MoselleLiveFront.updatedLabel || 'Mis à jour à'} ${data.refreshed_at}`)}else if((data.live_status||wrapper.dataset.liveStatus)!=='closed'&&data.refreshed_at){setStatus(`${MoselleLiveFront.updatedLabel || 'Mis à jour à'} ${data.refreshed_at}`)}}catch(error){failureCount+=1;startAutoRefresh();const wasAbort=error&&error.name==='AbortError';const message=wasAbort?(MoselleLiveFront.slowLabel||'Actualisation lente — nouvel essai automatique en cours'):(error.message||MoselleLiveFront.errorLabel||'Actualisation momentanément impossible.');if(manual||failureCount>=2||reason==='watchdog'){setStatus(message,failureCount>=3?'error':'warning')}}finally{isRefreshing=!1;setButtonState(!1)}}
33function startWatchdog(){if(watchdogId)return;watchdogId=window.setInterval(()=>{const now=Date.now();const autoActive=wrapper.dataset.autoRefreshActive!=='0';if(!autoActive||document.hidden)return;if(!isRefreshing&&now-lastSuccessAt>staleAfter&&now-lastAttemptAt>Math.min(refreshInterval,60000)){setStatus(MoselleLiveFront.slowLabel||'Actualisation lente — nouvel essai automatique en cours','warning');refreshLive(!1,'watchdog')}},watchdogInterval)}
34refreshButton?.addEventListener('click',()=>refreshLive(!0,'manual'));bindClickToPlayVideos();bindPolls();if(scrollEl){scrollEl.addEventListener('scroll',updateScrollAffordance,{passive:!0})}
35document.addEventListener('visibilitychange',()=>{if(!document.hidden&&wrapper.dataset.autoRefreshActive!=='0'){refreshLive(!1,'visible')}});applyViewportHeight();window.addEventListener('resize',scheduleViewportUpdate,{passive:!0});syncAutoRefreshState();startWatchdog()})})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.