server/assets/production/scripts/organization.js

1 line
4.3 KiB
JavaScript
Raw Permalink Normal View History

2020-08-27 11:15:46 +00:00
document.querySelectorAll(".schedule-category").forEach(e=>{let t=!1,a=e.querySelector(".schedule-category-collapse-icon"),i=e.querySelector(".schedule-category-table");e.querySelector(".schedule-category-header").onclick=()=>{t?(a.style.transform="rotate(180deg)",i.style.maxHeight=null):(a.style.transform="rotate(0deg)",i.style.maxHeight=i.scrollHeight+"px"),t=!t}});let description=document.querySelector(".description-cutted"),descriptionActions=document.querySelector(".description-actions-container"),descriptionOpened=!1,defaultMaxHeight="";if(null!==description){let e=document.querySelector(".description-btn"),t=document.getElementById("description-btn-icon"),a=document.getElementById("description-btn-text");e.onclick=()=>{descriptionOpened?(descriptionActions.className+=" closed",description.style.maxHeight=defaultMaxHeight,a.textContent="Ouvrir la description",t.style.transform="rotate(0deg)"):(descriptionActions.className=descriptionActions.className.replace(" closed",""),defaultMaxHeight=description.style.maxHeight,description.style.maxHeight=description.scrollHeight+"px",a.textContent="Fermer la description",t.style.transform="rotate(180deg)"),descriptionOpened=!descriptionOpened}}let mediaModal=document.querySelector("#media-modal"),mediaModalContent=document.querySelector("#media-modal-content"),navLeft=document.getElementById("media-nav-left"),navRight=document.getElementById("media-nav-right"),currentMedia={},mediaData=[],loadMedias=()=>{document.querySelectorAll(".media-container").forEach(e=>{mediaData.push({isVideo:"true"==e.getAttribute("data-video"),location:e.getAttribute("data-location")})})};loadMedias();let openModal=e=>{"extra"===e&&(e=5),mediaModal.style.visibility="visible",mediaModal.style.opacity=1,currentMedia=mediaData[e],fillModal(currentMedia),document.body.style.overflow="hidden",document.body.style.userSelect="none",document.body.style.touchAction="none",setTimeout(()=>{const e=t=>{!mediaModalContent.contains(t.target)&&isVisible(mediaModalContent)&&null===navLeft.querySelector(":hover")&&null===navRight.querySelector(":hover")&&(closeModal(),document.removeEventListener("click",e))};document.addEventListener("click",e)},100)};const isVisible=e=>!!e&&!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length);let fillModal=()=>{console.log(currentMedia),mediaModalContent.innerHTML="";let e=document.createAttribute("src");e.value=currentMedia.location;let t=null;if(currentMedia.isVideo){t=document.createElement("video"),t.setAttribute("controls",""),t.setAttribute("autoplay",""),t.setAttribute("name","media");let e=document.createElement("source");e.setAttribute("src",currentMedia.location),e.setAttribute("type","video/mp4"),t.appendChild(e)}else t=document.createElement("img"),t.attributes.setNamedItem(e);mediaModalContent.appendChild(t),0===mediaData.indexOf(currentMedia)?navLeft.className+=" disabled":navLeft.className=navLeft.className.replace("disabled",""),mediaData.indexOf(currentMedia)+1===mediaData.length?navRight.className+=" disabled":navRight.className=navRight.className.replace("disabled","")},closeModal=()=>{mediaModal.style.visibility="hidden",mediaModal.style.opacity=0,document.body.style.overflow="initial",document.body.style.height="initial",document.body.style.touchAction="initial",document.body.style.userSelect="initial";let e=document.querySelector("#media-modal video");null!==e&&e.pause()};null!=document.querySelector(".media-mosaic")&&(navLeft.onclick=()=>{0!==mediaData.indexOf(currentMedia)&&(currentMedia=mediaData[mediaData.indexOf(currentMedia)-1],fillModal())},navRight.onclick=()=>{mediaData.indexOf(currentMedia)+1!==mediaData.length&&(currentMedia=mediaData[mediaData.indexOf(currentMedia)+1],fillModal())});let formatPhone=e=>{0===e.indexOf("+33")&&(e="0"+e.substr(3));let t="",a=!1;for(var i=0;i<e.length;i++)t+=e.charAt(i),!0===a&&(t+=" "),a=!a;return["+33"+e.substr(1),t]};document.querySelectorAll(".offuscated").forEach(e=>{let t=e.getAttribute("data-source"),a=e.getAttribute("data-source-type");t=t.replace(/'/gm,'"').replace(/%_/gm,""),t=t.replace(/\$/gm,"A"),