@mhg/blog
Version:
3 lines (2 loc) • 10.1 kB
JavaScript
!function(){const e=new WeakMap,t=new Proxy({},{get(n,o){const l=e.get(t);return l?.[o]},set(n,o,l){e.has(t)||e.set(t,Object.create(null));return e.get(t)[o]=l,!0},deleteProperty(n,o){const l=e.get(t);return!(!l||!Object.prototype.hasOwnProperty.call(l,o))&&(delete l[o],0===Object.keys(l).length&&e["delete"](t),!0)},ownKeys(n){const o=e.get(t);return o?Object.keys(o):[]},getOwnPropertyDescriptor(n,o){const l=e.get(t);return l&&Object.prototype.hasOwnProperty.call(l,o)?{value:l[o],writable:!0,enumerable:!0,configurable:!0}:undefined}});Object.defineProperty(window,"volantis",{value:t,writable:!0,configurable:!0,enumerable:!0})}(),volantis.dom={},volantis.simpleTextHash=e=>{let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n),t&=t;return t.toString(16).padStart(8,"0")},volantis.getFunctionHash=e=>{const t=e.toString();return volantis.simpleTextHash(t)},volantis.EventListener={list:[],remove(){this.list.forEach(e=>{e.ele.removeEventListener(e.type,e.f,!1)}),this.list=[]}};class VolantisEventListener{constructor(e,t,n){this.type=e,this.f=t,this.ele=n}}class VolantisDom{constructor(e){return this._ele=e||document.createElement("div"),new Proxy(this,{get:(e,t)=>e[t]!==undefined?e[t]:e._ele[t]!==undefined?"function"==typeof e._ele[t]?e._ele[t].bind(e._ele):e._ele[t]:undefined,set:(e,t,n)=>e._ele[t]!==undefined?(e._ele[t]=n,!0):(e[t]=n,!0)})}find(e){const t=this._ele.querySelector(e);return t?new VolantisDom(t):null}hasClass(e){return this._ele.classList.contains(e)}addClass(e){return"string"!=typeof e||e.split(" ").forEach(e=>{e&&this._ele.classList.add(e)}),this}removeClass(e){return"string"!=typeof e||e.split(" ").forEach(e=>{e&&this._ele.classList.remove(e)}),this}toggleClass(e){return"string"!=typeof e||e.split(" ").forEach(e=>{e&&this._ele.classList.toggle(e)}),this}on(e,t,n=!0){return"function"!=typeof t||(this._ele.addEventListener(e,t,!1),n&&volantis.EventListener.list.push(new VolantisEventListener(e,t,this._ele))),this}click(e,t){return this.on("click",e,t)}scroll(e,t){return this.on("scroll",e,t)}html(e){return e===undefined?this._ele.innerHTML:(this._ele.innerHTML=e,this)}hide(){return this._ele.classList.remove("show"),this._ele.style.removeProperty("display"),this}show(){return this._ele.classList.add("show"),this._ele.style.removeProperty("display"),this}}volantis.dom.$=e=>e?e instanceof VolantisDom?e:e instanceof NodeList||e instanceof HTMLCollection?Array.from(e).map(e=>new VolantisDom(e)):e instanceof Node?new VolantisDom(e):null:null;class RunItem{constructor(){this.list=[]}start(){this.list.forEach(e=>e.run())}push(e,t,n=!0){if("function"!=typeof e)return;let o=e;n&&(o=()=>{volantis.requestAnimationFrame(e)}),t=t||volantis.getFunctionHash(e);const l=this.list.findIndex(e=>e.name===t);-1===l?this.list.push(new TaskItem(o,t)):this.list[l]=new TaskItem(o,t)}remove(e){"string"==typeof e&&(this.list=this.list.filter(t=>t.name!==e))}}class TaskItem{constructor(e,t){this.name=t||volantis.getFunctionHash(e),this.fn=e}run(){try{this.fn()}catch(e){console.error(`Error executing task ${this.name}:`,e)}}}function errorImgAvatar(e){e.src=volantis.GLOBAL_CONFIG["default"].avatar,e.onerror=null}function errorImgCover(e){e.src=volantis.GLOBAL_CONFIG["default"].cover,e.onerror=null}volantis.pjax={},volantis.pjax.method={complete:new RunItem,error:new RunItem,send:new RunItem},volantis.pjax=Object.assign(volantis.pjax,{push:volantis.pjax.method.complete.push.bind(volantis.pjax.method.complete),error:volantis.pjax.method.error.push.bind(volantis.pjax.method.error),send:volantis.pjax.method.send.push.bind(volantis.pjax.method.send)}),volantis.rightmenu={},volantis.rightmenu.method={handle:new RunItem},volantis.rightmenu=Object.assign(volantis.rightmenu,{handle:volantis.rightmenu.method.handle.push.bind(volantis.rightmenu.method.handle)}),volantis.dark={},volantis.dark.method={toggle:new RunItem},volantis.dark=Object.assign(volantis.dark,{push:volantis.dark.method.toggle.push.bind(volantis.dark.method.toggle)}),volantis.js=(e,t)=>new Promise((n,o)=>{setTimeout(function(){var l;if(document.querySelector(`script[src="${l=e,l.replace(/[#".'()[\]]/g,"\\$&")}"]`))return void n();const i=document.createElement("script");i.src=e;if(i.onload=()=>{"function"==typeof t&&t(),n()},i.onerror=()=>o(new Error(`Failed to load script: ${e}`)),t&&"object"==typeof t&&!Array.isArray(t))for(const e in t)t.hasOwnProperty(e)&&("onload"===e?i.onload=()=>{t[e](),n()}:"pjax"===e?(i.setAttribute("pjax",""),i.setAttribute("data-pjax","")):!0===t[e]?i.setAttribute(e,""):i.setAttribute(e,t[e]));(document.head||document.documentElement).appendChild(i)})}),volantis.css=e=>new Promise((t,n)=>{setTimeout(function(){var o;if(document.querySelector(`link[href="${o=e,o.replace(/[#".'()[\]]/g,"\\$&")}"]`))return void t();const l=document.createElement("link");Object.assign(l,{rel:"stylesheet",href:e,onload:()=>t(),onerror:()=>n(new Error(`Failed to load CSS: ${e}`))}),document.head.appendChild(l)})}),volantis["import"]={jQuery:()=>"undefined"==typeof jQuery?volantis.js(volantis.GLOBAL_CONFIG.cdn.jquery):new Promise(e=>{e()})},volantis.throttle=(e,t=200)=>{let n=0;return function(...o){const l=Date.now();l-n>=t&&(e.apply(this,o),n=l)}},volantis.debounce=(e,t=200)=>{let n=null;return function(){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,arguments),n=null},t)}},volantis.requestAnimationFrame=e=>(window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)}),window.requestAnimationFrame(e)),volantis.rafThrottle=e=>{let t=null;return(...n)=>{t||(t=volantis.requestAnimationFrame(()=>{e(...n),t=null}))}},volantis.layoutHelper=(e,t,n={})=>{const{clean:o=!1,pjax:l=!0}={...n},i=()=>{const n=document.createElement("div");n.innerHTML=t;const l=document.querySelector(`#layoutHelper-${e}`);l&&(o&&(l.innerHTML=""),l.append(n))};i(),l&&volantis.pjax.push(i,`layoutHelper-${e}`)},volantis.scroll={engine:new RunItem,unengine:new RunItem},volantis.scroll=Object.assign(volantis.scroll,{push:volantis.scroll.engine.push.bind(volantis.scroll.engine)}),volantis.scroll.getScrollTop=()=>{let e;return window.pageYOffset?e=window.pageYOffset:document.compatMode&&"BackCompat"!=document.compatMode?e=document.documentElement.scrollTop:document.body&&(e=document.body.scrollTop),e},volantis.scroll.scrollHeight=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)},volantis.scroll.offsetHeight=function(){return Math.min(document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},volantis.scroll.progress=function(){return volantis.scroll.getScrollTop()/(volantis.scroll.scrollHeight()-volantis.scroll.offsetHeight())},volantis.scroll.handleScrollEvents=()=>{volantis.scroll.lastScrollTop=volantis.scroll.getScrollTop(),volantis.requestAnimationFrame(function e(){const t=volantis.scroll.getScrollTop();volantis.scroll.lastScrollTop!==t?(volantis.scroll.del=t-volantis.scroll.lastScrollTop,volantis.scroll.lastScrollTop=t,volantis.scroll.unengine.list=[],volantis.scroll.engine.start()):volantis.scroll.unengine.start(),volantis.requestAnimationFrame(e)})},volantis.scroll.handleScrollEvents(),volantis.scroll.ele=null,volantis.scroll.to=(e,t={})=>{e&&(volantis.scroll.ele=e,opt={top:e.getBoundingClientRect().top+document.documentElement.scrollTop,behavior:volantis.GLOBAL_CONFIG.scroll_behavior},"top"in t&&(opt.top=t.top),"behavior"in t&&(opt.behavior=t.behavior),"addTop"in t&&(opt.top+=t.addTop),"observerDic"in t||(t.observerDic=100),window.scrollTo(opt),t.observer&&setTimeout(()=>{volantis.scroll.ele==e&&volantis.scroll.unengine.push(()=>{let n=e.getBoundingClientRect().top;n>=-t.observerDic&&n<=t.observerDic||volantis.scroll.to(e,t),volantis.scroll.unengine.remove("unengineObserver")},"unengineObserver")},1e3))},volantis.cleanContentVisibility=()=>{document.querySelector(".post-story")&&(console.log("cleanContentVisibility"),document.querySelectorAll(".post-story").forEach(e=>{e.classList.remove("post-story")}))};const nativeSetTimeout=window.setTimeout,nativeSetInterval=window.setInterval,nativeClearTimeout=window.clearTimeout,nativeClearInterval=window.clearInterval;volantis.activeTimeout=[],volantis.activeInterval=[],window.setTimeout=function(e,t,...n){const o=nativeSetTimeout(function(...t){try{return e.apply(this,t)}finally{const e=volantis.activeTimeout.indexOf(o);-1!==e&&volantis.activeTimeout.splice(e,1)}},t,...n);return volantis.activeTimeout.push(o),o},window.setInterval=function(e,t,...n){const o=nativeSetInterval(e,t,...n);return volantis.activeInterval.push(o),o},window.clearTimeout=function(e){nativeClearTimeout(e);const t=volantis.activeTimeout.indexOf(e);-1!==t&&volantis.activeTimeout.splice(t,1)},window.clearInterval=function(e){nativeClearInterval(e);const t=volantis.activeInterval.indexOf(e);-1!==t&&volantis.activeInterval.splice(t,1)},volantis.getActiveInterval=function(){return[...volantis.activeInterval]},volantis.getActiveTimeout=function(){return[...volantis.activeTimeout]},volantis.clearAllTimers=function(){volantis.getActiveInterval().forEach(function(e){clearInterval(e)}),volantis.getActiveTimeout().forEach(function(e){clearTimeout(e)})},volantis.pjax.send(volantis.clearAllTimers,"clearAllTimers"),document.addEventListener("DOMContentLoaded",function(){volantis.dom.bodyAnchor=volantis.dom.$(document.getElementById("safearea")),volantis.dom.topBtn=volantis.dom.$(document.getElementById("s-top")),volantis.dom.wrapper=volantis.dom.$(document.getElementById("wrapper")),volantis.dom.coverAnchor=volantis.dom.$(document.querySelector("#l_cover .cover-wrapper")),volantis.dom.switcher=volantis.dom.$(document.querySelector("#l_header .switcher .s-search")),volantis.dom.header=volantis.dom.$(document.getElementById("l_header")),volantis.dom.search=volantis.dom.$(document.querySelector("#l_header .m_search")),volantis.dom.mPhoneList=volantis.dom.$(document.querySelectorAll("#l_header .m-phone .list-v"))});
//# sourceMappingURL=../maps/js/global.js.map