Repository navigation
Expand file tree
/
Copy pathglobal.js
More file actions
1 lines (1 loc) · 6.69 KB
/
Copy pathglobal.js
File metadata and controls
1 lines (1 loc) · 6.69 KB
1
window.volantis={},volantis.dom={},volantis.EventListener={list:[],remove(){this.list.forEach((e=>{e.ele.removeEventListener(e.type,e.f,!1)})),this.list=[]}};class VolantisEventListener{constructor(e,t,o){this.type=e,this.f=t,this.ele=o}}class VolantisDom{constructor(e){return this._ele=e||document.createElement("div"),new Proxy(this,{get:(e,t)=>void 0!==e[t]?e[t]:void 0!==e._ele[t]?"function"==typeof e._ele[t]?e._ele[t].bind(e._ele):e._ele[t]:void 0,set:(e,t,o)=>void 0!==e._ele[t]?(e._ele[t]=o,!0):(e[t]=o,!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
48A7
||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,o=!0){return"function"!=typeof t||(this._ele.addEventListener(e,t,!1),o&&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 void 0===e?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,o=!0){if("function"!=typeof e)return;let n=e;if(o&&(n=()=>{volantis.requestAnimationFrame(e)}),t){const e=this.list.findIndex((e=>e.name===t));if(-1!==e)return void(this.list[e]=new TaskItem(n,t))}this.list.push(new TaskItem(n,t))}remove(e){"string"==typeof e&&(this.list=this.list.filter((t=>t.name!==e)))}}class TaskItem{constructor(e,t){this.name=t||e.name,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. errorImgCover(e){e.src=volantis.GLOBAL_CONFIG.default.cover,e. 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.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(((o,n)=>{var s;if(document.querySelector(`script[src="${s=e,s.replace(/[#".'()[\]]/g,"\\$&")}"]`))return void o();const l=document.createElement("script");l.src=e;if(l. t&&t(),o()},l. Error(`Failed to load script: ${e}`)),t&&"object"==typeof t&&!Array.isArray(t))for(const e in t)t.hasOwnProperty(e)&&("onload"===e?l. Promise(((t,o)=>{var n;if(document.querySelector(`link[href="${n=e,n.replace(/[#".'()[\]]/g,"\\$&")}"]`))return void t();const s=document.createElement("link");Object.assign(s,{rel:"stylesheet",href:e,onload:()=>t(),onerror:()=>o(new Error(`Failed to load CSS: ${e}`))}),document.head.appendChild(s)})),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.layoutHelper=(e,t,o={})=>{const{clean:n=!1,pjax:s=!0}={...o},l=()=>{const o=document.createElement("div");o.innerHTML=t;const s=document.querySelector(`#layoutHelper-${e}`);s&&(n&&(s.innerHTML=""),s.append(o))};l(),s&&volantis.pjax.push(l,`layoutHelper-${e}`)},volantis.scroll={engine:new RunItem,unengine:new RunItem,isScrolling:!1,scrollTimer:null,push:null,ele:null,lastScrollTop:0,del:0,getScrollTop:()=>"BackCompat"!==document.compatMode?document.documentElement.scrollTop:document.body.scrollTop,scrollHeight:()=>Math.max(document.body.scrollHeight,document.documentElement.scrollHeight),offsetHeight:()=>Math.max(document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight),progress:function(){return this.getScrollTop()/(this.scrollHeight()-this.offsetHeight())},handleScrollEvents:function(){this.lastScrollTop=this.getScrollTop();const e=()=>{const t=this.getScrollTop();this.lastScrollTop!==t?(this.del=t-this.lastScrollTop,this.lastScrollTop=t,this.unengine.list.length=0,this.engine.start(),this.handleScrollStop()):this.unengine.start(),window.requestAnimationFrame(e)};window.requestAnimationFrame(e)},handleScrollStop:function(){clearTimeout(this.scrollTimer),this.scrollTimer=setTimeout((()=>{if(this.lastScrollTop===window.pageYOffset){const e=window.lazyLoader;e?.reinitObserver&&this.isScrolling&&(this.isScrolling=!1,e.reinitObserver())}}),200)},debounce:(e,t=200)=>{let o=null;return(...n)=>{clearTimeout(o),o=setTimeout((()=>e.apply(this,n)),t)}},to:(e,t={})=>{if(!e)return;volantis.scroll.ele=e;const{top:o,addTop:n=0,...s}=t,l=e.getBoundingClientRect().top+document.documentElement.scrollTop,i={top:o??l+n,behavior:volantis.GLOBAL_CONFIG.scrollSmooth?"smooth":"instant",observerDic:100,...s},r=document.documentElement.scrollTop||document.body.scrollTop;Math.round(i.top)!==Math.round(r)&&(volantis.scroll.isScrolling=!0,window.scrollTo(i))}},volantis.scroll.push=volantis.scroll.engine.push.bind(volantis.scroll.engine),volantis.scroll.handleScrollEvents(),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.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"))})),top.location!==self.location&&(top.location=self.location);