1
0

main.min.js 2.2 KB

1
  1. let lastScrollPosition=window.pageYOffset,header=document.getElementById("site-header");const autoHideHeader=()=>{let e=window.pageYOffset;e>lastScrollPosition?(header.classList.remove("slideInUp"),header.classList.add("slideOutDown")):(header.classList.remove("slideOutDown"),header.classList.add("slideInUp")),lastScrollPosition=e};let mobileMenu=document.getElementById("mobile-menu");document.getElementById("menu-btn").addEventListener("click",()=>{"none"==mobileMenu.style.display?mobileMenu.style.display="block":(mobileMenu.classList.remove("bounceInRight"),mobileMenu.classList.add("bounceOutRight"),setTimeout(()=>{mobileMenu.style.display="none",mobileMenu.classList.remove("bounceOutRight"),mobileMenu.classList.add("bounceInRight")},750))});let commentsLoaded=!1,commentsOffsetTop=document.getElementById("comments").offsetTop,commentsLoader=document.getElementById("comments-loader");const avJsUrl="//cdn1.lncld.net/static/js/3.0.4/av-min.js",valineJsUrl="//unpkg.com/valine/dist/Valine.min.js",loadScript=(e,o,t=!0,n=!0)=>new Promise((s,l)=>{function a(e,o){(o||!d.readyState||/loaded|complete/.test(d.readyState))&&(d.onload=null,d.onreadystatechange=null,d=void 0,o?l():s())}let d=document.createElement("script");const i=o||document.getElementsByTagName("script")[0];d.async=t,d.defer=n,d.onload=a,d.onreadystatechange=a,d.src=e,i.parentNode.insertBefore(d,i)}),loadComments=()=>{loadScript(avJsUrl).then(()=>{console.log("av-min.js Loaded"),loadScript(valineJsUrl).then(()=>{console.log("Valine.min.js Loaded"),new Valine({el:"#comments",appId:"QfBLso0johYg7AXtV9ODU6FC-gzGzoHsz",appKey:"J1tpEEsENa48aLVsPdvwMP14"}),console.log("Comments Loaded"),commentsLoader.style.display="none"},()=>{console.log("Fail to Load Valine.min.js")})},()=>{console.log("Fail to Load av-min.js")})};commentsOffsetTop<window.innerHeight&&(console.log("Ready to Load Comments"),commentsLoader.style.display="block",loadComments(),commentsLoaded=!0),window.addEventListener("scroll",()=>{autoHideHeader(),mobileMenu.style.display="none",0==commentsLoaded&&window.pageYOffset+window.innerHeight>commentsOffsetTop&&(console.log("Ready to Load Comments"),commentsLoader.style.display="block",loadComments(),commentsLoaded=!0)});