Files

1 line
11 KiB
JavaScript

'use strict';'require baseclass';'require ui';return baseclass.extend({__init__(){ui.menu.load().then(L.bind(this.render,this))},render(e){let t=e,s='';if(this.renderModeMenu(t),L.env.dispatchpath.length>=3){for(let a=0;a<3&&t;a++)t=t.children[L.env.dispatchpath[a]],s=s+(s?'/':'')+L.env.dispatchpath[a];t&&this.renderTabMenu(t,s)}this.bindSettings(),this.initSidebarState(),this.loadLuxeSettings(),this.initNavbarSlider(),this.setActiveIcon(),this.initIdleTimer(),window.addEventListener('resize',L.bind(this.initSidebarState,this));const a=document.querySelector('.main > .loading');a&&(a.style.opacity='0',a.style.visibility='hidden',a.style.pointerEvents='none'),this.initTypingEffect()},initIdleTimer(){const e=document.getElementById('floating-navbar');if(!e)return;let t;const s=()=>{e.classList.remove('navbar-hidden'),clearTimeout(t),'1'===document.body.getAttribute('data-autohide')&&(t=setTimeout(()=>e.classList.add('navbar-hidden'),3e3))};['touchstart','mousemove','scroll','click','keydown'].forEach(e=>document.addEventListener(e,s,{passive:!0})),s()},bindSettings(){const e=document.querySelector('.showSide'),t=document.querySelector('.darkMask'),s=document.getElementById('settings-toggle'),a=document.getElementById('luxe-settings-menu'),n=document.getElementById('mode-selection-container'),r=['normal','neo','neox','glaze','onyx'];e&&e.addEventListener('click',ui.createHandlerFn(this,'handleSidebarToggle')),t&&t.addEventListener('click',ui.createHandlerFn(this,'handleSidebarToggle')),s&&a&&(s.addEventListener('click',e=>{a.style.display='none'===a.style.display?'block':'none',e.stopPropagation()}),document.querySelectorAll('.style-card').forEach(e=>{e.addEventListener('click',e=>{document.querySelectorAll('.style-card').forEach(e=>e.classList.remove('active')),e.currentTarget.classList.add('active'),n&&(n.style.display=r.includes(e.currentTarget.getAttribute('data-style'))?'block':'none'),this.autoSave(),e.stopPropagation()})}),document.querySelectorAll('.mode-card, .icon-card').forEach(e=>{e.addEventListener('click',e=>{const t=e.currentTarget.classList.contains('mode-card')?'.mode-card':'.icon-card';document.querySelectorAll(t).forEach(e=>e.classList.remove('active')),e.currentTarget.classList.add('active'),this.autoSave(),e.stopPropagation()})}),['set-floating','set-slider-navbar','set-autohide-navbar','set-hostname'].forEach(e=>{const t=document.getElementById(e);t&&t.addEventListener('change',()=>this.autoSave())}),a.addEventListener('click',e=>e.stopPropagation()),document.addEventListener('click',()=>{'block'===a.style.display&&(a.style.display='none')}))},initTypingEffect(){const e=document.querySelector(".brand");if(e&&!e.hasAttribute("data-typed")){e.setAttribute("data-typed","true");const t=e.textContent.trim(),s=`Hello...! ${t}`;e.textContent="",e.classList.add("typing");let a=0;const n=()=>{a<s.length&&(e.textContent+=s.charAt(a),a++,requestAnimationFrame(()=>setTimeout(n,90)))};setTimeout(n,400)}},setActiveIcon(){const e=window.location.pathname,t=document.querySelectorAll('#iconWrapper a');t&&t.forEach(t=>{const s=t.getAttribute('href');s&&e.includes(s)&&t.classList.add('active')})},initNavbarSlider(){const e=document.getElementById('prevArrow'),t=document.getElementById('nextArrow'),s=document.getElementById('iconWrapper');e&&t&&s&&!e.hasAttribute('data-bound')&&(e.setAttribute('data-bound','true'),e.addEventListener('click',()=>s.scrollBy({left:-120,behavior:'smooth'})),t.addEventListener('click',()=>s.scrollBy({left:120,behavior:'smooth'})))},loadLuxeSettings(){const e=document.body,t=document.getElementById('floating-navbar'),s=localStorage.getItem('luxe-theme')||'normal',a=localStorage.getItem('luxe-mode')||'normal',n=localStorage.getItem('luxe-floating')||'0',r=localStorage.getItem('luxe-slider'),i=localStorage.getItem('luxe-icon')||'5',l=localStorage.getItem('luxe-autohide')||'0',hv=localStorage.getItem('luxe-hostname')||'0';document.querySelectorAll('.style-card').forEach(e=>e.classList.remove('active'));const c=document.querySelector(`.style-card[data-style="${s}"]`);c&&c.classList.add('active'),e.setAttribute('data-theme',s);document.querySelectorAll('.mode-card').forEach(e=>e.classList.remove('active'));const o=document.querySelector(`.mode-card[data-mode="${a}"]`);o&&o.classList.add('active'),'normal'!==a?e.setAttribute('data-force-scheme',a):e.removeAttribute('data-force-scheme');document.querySelectorAll('.icon-card').forEach(e=>e.classList.remove('active'));const d=document.querySelector(`.icon-card[data-icon="${i}"]`);d&&d.classList.add('active');const m=document.getElementById('set-floating');'1'===n?(m&&(m.checked=!0),e.setAttribute('data-enable-navbar','1'),e.setAttribute('data-navbar-enabled','1')):(m&&(m.checked=!1),e.setAttribute('data-enable-navbar','0'),e.setAttribute('data-navbar-enabled','0'));if('1'===r){const s=document.getElementById('set-slider-navbar');s&&(s.checked=!0),e.setAttribute('data-slider','true'),t&&t.classList.add('nav-slider-active')}else{const s=document.getElementById('set-slider-navbar');s&&(s.checked=!1),e.removeAttribute('data-slider'),t&&t.classList.remove('nav-slider-active')}const h=document.getElementById('set-autohide-navbar');'1'===l?(h&&(h.checked=!0),e.setAttribute('data-autohide','1')):(h&&(h.checked=!1),e.setAttribute('data-autohide','0'));const hnBtn=document.getElementById('set-hostname');if(hnBtn)hnBtn.checked=(hv==='1');e.setAttribute('data-show-hostname',hv);e.setAttribute('data-icon',i);const u=document.getElementById('mode-selection-container');u&&(u.style.display=['normal','neo','neox','glaze','onyx'].includes(s)?'block':'none')},autoSave(){const e=document.getElementById('set-floating'),t=document.getElementById('set-slider-navbar'),s=document.getElementById('set-autohide-navbar'),hn=document.getElementById('set-hostname'),a=e&&e.checked?'1':'0',n=t&&t.checked?'1':'0',r=s&&s.checked?'1':'0',hv=hn?(hn.checked?'1':'0'):(localStorage.getItem('luxe-hostname')||'0'),i=document.querySelector('.icon-card.active'),l=i?i.getAttribute('data-icon'):'5',c=document.querySelector('.style-card.active'),o=c?c.getAttribute('data-style'):'normal',d=document.querySelector('.mode-card.active'),m=d?d.getAttribute('data-mode'):'normal';document.body.setAttribute('data-theme',o);'normal'!==m?document.body.setAttribute('data-force-scheme',m):document.body.removeAttribute('data-force-scheme');document.body.setAttribute('data-enable-navbar',a);document.body.setAttribute('data-navbar-enabled',a);document.body.setAttribute('data-autohide',r);document.body.setAttribute('data-show-hostname',hv);const h=document.getElementById('floating-navbar');'1'===n?(document.body.setAttribute('data-slider','true'),h&&h.classList.add('nav-slider-active')):(document.body.removeAttribute('data-slider'),h&&h.classList.remove('nav-slider-active'));'0'===r&&h&&h.classList.remove('navbar-hidden');document.body.setAttribute('data-icon',l);localStorage.setItem('luxe-theme',o);localStorage.setItem('luxe-mode',m);localStorage.setItem('luxe-floating',a);localStorage.setItem('luxe-slider',n);localStorage.setItem('luxe-icon',l);localStorage.setItem('luxe-autohide',r);localStorage.setItem('luxe-hostname',hv)},handleMenuExpand(e){const t=e.target,s=t.parentNode,a=t.nextElementSibling,n=s.classList.contains('active');if(document.querySelectorAll('li.slide.active').forEach(e=>{if(e!==s){e.classList.remove('active');e.childNodes[0]&&e.childNodes[0].classList.remove('active');const t=e.querySelector('ul');t&&(t.style.height=t.scrollHeight+'px',requestAnimationFrame(()=>{t.style.transition='height 0.3s cubic-bezier(0.4, 0, 0.2, 1)';t.style.height='0px'}))}}),!a)return;n?(s.classList.remove('active'),t.classList.remove('active'),a.style.height=a.scrollHeight+'px',requestAnimationFrame(()=>{a.style.transition='height 0.3s cubic-bezier(0.4, 0, 0.2, 1)';a.style.height='0px'})):(a.parentNode.offsetLeft+a.offsetWidth<=s.offsetLeft+s.offsetWidth&&a.classList.add('align-left'),s.classList.add('active'),t.classList.add('active'),a.style.display='block',a.style.height='0px',requestAnimationFrame(()=>{a.style.transition='height 0.3s cubic-bezier(0.4, 0, 0.2, 1)';a.style.height=a.scrollHeight+'px';setTimeout(()=>{s.classList.contains('active')&&(a.style.height='auto')},300)}));t.blur();e.preventDefault();e.stopPropagation()},renderMainMenu(e,t,s){const a=(s||0)+1,n=E('ul',{class:s?'slide-menu':'nav'}),r=ui.menu.getChildren(e);if(0===r.length||a>2)return E([]);r.forEach(e=>{const s=this.renderMainMenu(e,t+'/'+e.name,a),r=L.env.dispatchpath[a]===e.name,i=s.children.length;r&&i&&setTimeout(()=>{s.style.height='auto'},50);n.appendChild(E('li',{class:i?'slide'+(r?' active':''):r?' active':''},[E('a',{href:i?'#':L.url(t,e.name),class:i?'menu'+(r?' active':''):'',click:i?ui.createHandlerFn(this,'handleMenuExpand'):'','data-title':i?'':_(e.title)},[_(e.title)]),s]))});if(1===a){const e=document.querySelector('#mainmenu');e&&(e.appendChild(n),e.style.display='')}return n},renderModeMenu(e){const t=document.querySelector('#modemenu');if(!t)return;const s=ui.menu.getChildren(e);s.forEach((e,a)=>{const n=L.env.requestpath.length?e.name===L.env.requestpath[0]:0===a;t.appendChild(E('li',{},[E('a',{href:L.url(e.name),class:n?'active':''},[_(e.title)])]));n&&this.renderMainMenu(e,e.name);a>0&&a<s.length&&t.appendChild(E('li',{class:'divider'},[E('span')]))});s.length>1&&t.parentElement&&(t.parentElement.style.display='')},renderTabMenu(e,t,s){const a=document.querySelector('#tabmenu');if(!a)return E([]);const n=(s||0)+1,r=E('ul',{class:'tabs'}),i=ui.menu.getChildren(e);let l=null;return 0===i.length?E([]):(i.forEach(e=>{const s=L.env.dispatchpath[n+2]===e.name,a=s?' active':'',i=`tabmenu-item-${e.name} ${a}`;r.appendChild(E('li',{class:i},[E('a',{href:L.url(t,e.name)},[_(e.title)])]));s&&(l=e)}),a.appendChild(r),a.style.display='',l&&a.appendChild(this.renderTabMenu(l,t+'/'+l.name,n)),r)},initSidebarState(){const e=window.innerWidth,t=document.querySelector('.main-left'),s=document.querySelector('.darkMask'),a=document.querySelector('.main-right'),n=document.querySelector('.showSide');t&&s&&a&&(e>1152?(t.classList.remove('sidebar-open'),n&&n.classList.remove('active'),t.style.transform='',t.style.opacity='',t.style.visibility='',t.style.transition='',s.style.visibility='hidden',s.style.opacity='0',s.style.transition='',s.style.pointerEvents='none',a.style['overflow-y']='auto'):t.classList.contains('sidebar-open')||(t.style.transform='translateX(-120%)',t.style.opacity='0',t.style.visibility='hidden',s.style.visibility='hidden',s.style.opacity='0',s.style.pointerEvents='none'))},handleSidebarToggle(e){if(window.innerWidth>1152)return;const t=document.querySelector('.darkMask'),s=document.querySelector('.main-right'),a=document.querySelector('.main-left'),n=document.querySelector('.showSide');if(!a||!t||!s)return;const r=!a.classList.contains('sidebar-open');a.style.transition='transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease';t.style.transition='opacity 0.4s ease, visibility 0.4s';r?(a.classList.add('sidebar-open'),n&&n.classList.add('active'),a.style.visibility='visible',a.style.opacity='1',a.style.transform='translateX(0)',t.style.pointerEvents='auto',t.style.visibility='visible',t.style.opacity='1',s.style['overflow-y']='hidden'):(a.classList.remove('sidebar-open'),n&&n.classList.remove('active'),a.style.transform='translateX(-120%)',a.style.opacity='0',t.style.pointerEvents='none',t.style.opacity='0',setTimeout(()=>{a.classList.contains('sidebar-open')||(a.style.visibility='hidden',t.style.visibility='hidden')},400),s.style['overflow-y']='auto')}});