File size: 3,695 Bytes
779c5fe |
1 2 |
const btf={debounce:function(t,e,n){let o;return function(){const i=this,a=arguments,s=function(){o=null,n||t.apply(i,a)},c=n&&!o;clearTimeout(o),o=setTimeout(s,e),c&&t.apply(i,a)}},throttle:function(t,e,n){let o,i,a,s=0;n||(n={});const c=function(){s=n.leading===!1?0:new Date().getTime(),o=null,t.apply(i,a),o||(i=a=null)};return function(){const r=new Date().getTime();!s&&n.leading===!1&&(s=r);const l=e-(r-s);i=this,a=arguments,l<=0||l>e?(o&&(clearTimeout(o),o=null),s=r,t.apply(i,a),o||(i=a=null)):!o&&n.trailing!==!1&&(o=setTimeout(c,l))}},sidebarPaddingR:()=>{const t=window.innerWidth,e=document.body.clientWidth,n=t-e;t!==e&&(document.body.style.paddingRight=n+"px")},snackbarShow:(t,e=!1,n=2e3)=>{const{position:o,bgLight:i,bgDark:a}=GLOBAL_CONFIG.Snackbar,s=document.documentElement.getAttribute("data-theme")==="light"?i:a;Snackbar.show({text:t,backgroundColor:s,showAction:e,duration:n,pos:o,customClass:"snackbar-css"})},diffDate:(t,e=!1)=>{const n=new Date,o=new Date(t),i=n.getTime()-o.getTime(),a=1e3*60,s=a*60,c=s*24,f=c*30;let r;if(e){const l=i/f,d=i/c,u=i/s,m=i/a;l>12?r=o.toLocaleDateString().replace(/\//g,"-"):l>=1?r=parseInt(l)+" "+GLOBAL_CONFIG.date_suffix.month:d>=1?r=parseInt(d)+" "+GLOBAL_CONFIG.date_suffix.day:u>=1?r=parseInt(u)+" "+GLOBAL_CONFIG.date_suffix.hour:m>=1?r=parseInt(m)+" "+GLOBAL_CONFIG.date_suffix.min:r=GLOBAL_CONFIG.date_suffix.just}else r=parseInt(i/c);return r},loadComment:(t,e)=>{if("IntersectionObserver"in window){const n=new IntersectionObserver(o=>{o[0].isIntersecting&&(e(),n.disconnect())},{threshold:[0]});n.observe(t)}else e()},scrollToDest:(t,e=500)=>{const n=window.pageYOffset;if(n>t&&(t=t-70),"scrollBehavior"in document.documentElement.style){window.scrollTo({top:t,behavior:"smooth"});return}let o=null;t=+t,window.requestAnimationFrame(function i(a){o=o||a;const s=a-o;n<t?window.scrollTo(0,(t-n)*s/e+n):window.scrollTo(0,n-(n-t)*s/e),s<e?window.requestAnimationFrame(i):window.scrollTo(0,t)})},animateIn:(t,e)=>{t.style.display="block",t.style.animation=e},animateOut:(t,e)=>{t.addEventListener("animationend",function n(){t.style.display="",t.style.animation="",t.removeEventListener("animationend",n)}),t.style.animation=e},getParents:(t,e)=>{for(;t&&t!==document;t=t.parentNode)if(t.matches(e))return t;return null},siblings:(t,e)=>[...t.parentNode.children].filter(n=>e?n!==t&&n.matches(e):n!==t),wrap:(t,e,n)=>{const o=document.createElement(e);for(const[i,a]of Object.entries(n))o.setAttribute(i,a);t.parentNode.insertBefore(o,t),o.appendChild(t)},unwrap:t=>{const e=t.parentNode;e!==document.body&&(e.parentNode.insertBefore(t,e),e.parentNode.removeChild(e))},isHidden:t=>t.offsetHeight===0&&t.offsetWidth===0,getEleTop:t=>{let e=t.offsetTop,n=t.offsetParent;for(;n!==null;)e+=n.offsetTop,n=n.offsetParent;return e},loadLightbox:t=>{const e=GLOBAL_CONFIG.lightbox;if(e==="mediumZoom"){const n=mediumZoom(t);n.on("open",o=>{const i=document.documentElement.getAttribute("data-theme")==="dark"?"#121212":"#fff";n.update({background:i})})}e==="fancybox"&&(t.forEach(n=>{if(n.parentNode.tagName!=="A"){const o=n.dataset.lazySrc||n.src,i=n.title||n.alt||"";btf.wrap(n,"a",{href:o,"data-fancybox":"gallery","data-caption":i,"data-thumb":o})}}),window.fancyboxRun||(Fancybox.bind("[data-fancybox]",{Hash:!1,Thumbs:{autoStart:!1}}),window.fancyboxRun=!0))},initJustifiedGallery:function(t){t.forEach(function(e){btf.isHidden(e)||fjGallery(e,{itemSelector:".fj-gallery-item",rowHeight:220,gutter:4,onJustify:function(){this.$container.style.opacity="1"}})})},updateAnchor:t=>{if(t!==window.location.hash){t||(t=location.pathname);const e=GLOBAL_CONFIG_SITE.title;window.history.replaceState({url:location.href,title:e},e,t)}}};
|