hexo-theme-redefine
Version:
Redefine your writing with Hexo Theme Redefine.
2 lines • 1.06 kB
JavaScript
const o=[],e=[],n=[],t=[];let i=!1,s=!1;const runCallbacks=(o,e)=>{o.forEach((o=>{try{o(e)}catch(o){console.error("Lifecycle callback failed:",o)}}))},fireReady=()=>{i||(i=!0,runCallbacks(o),runCallbacks(e,{initial:!0}))},initSwupHooks=o=>{!s&&o&&o.hooks&&(s=!0,o.hooks.on("page:view",(o=>{runCallbacks(e,o)})),o.hooks.on("visit:start",(o=>{runCallbacks(n,o)})),o.hooks.before("content:replace",(o=>{runCallbacks(t,o)})))},handleSwupReady=o=>{const e=window.swup||o?.detail?.swup;initSwupHooks(e)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",fireReady,{once:!0}):fireReady(),window.swup&&window.swup.hooks?initSwupHooks(window.swup):window.addEventListener("redefine:swup:ready",handleSwupReady,{once:!0});export const onReady=e=>{"function"==typeof e&&(i?e():o.push(e))};export const onPageView=o=>{"function"==typeof o&&(e.push(o),i&&o({initial:!0}))};export const onVisitStart=o=>{"function"==typeof o&&n.push(o)};export const onBeforeContentReplace=o=>{"function"==typeof o&&t.push(o)};
//# sourceMappingURL=lifecycle.js.map