initBottomNav(){ if (document.getElementById('mx-bottom-nav')) return; var nav = document.createElement('nav'); nav.id = 'mx-bottom-nav'; nav.className = 'mx-bottom-nav'; nav.setAttribute('aria-label','底部主导航'); var path = location.pathname; var items = [ {id:'home', label:'首页', href:'/', icon:''}, {id:'lib', label:'片库', href:'/index.php/vod/type/id/1.html', icon:''}, {id:'hot', label:'排行', href:'/index.php/label/hot.html', icon:''}, {id:'me', label:'我的', href:'/index.php/user/index.html', icon:''}, {id:'install', label:'安装', href:'javascript:void(0)', icon:''} ]; items.forEach(function(it){ var a = document.createElement('a'); a.className = 'mx-bottom-nav-item'; a.href = it.href; a.innerHTML = it.icon + '' + it.label + ''; if (it.id === 'install') { a.href = 'javascript:void(0)'; a.classList.add('mx-nav-install'); a.addEventListener('click', function(ev){ ev.preventDefault(); if (mxDeferredPrompt) { mxDeferredPrompt.prompt(); mxDeferredPrompt.userChoice.then(function(){ mxDeferredPrompt = null; }); } else { mxShowIosTip(); } }); } var active = false; if (it.id === 'home') { active = (path === '/' || path === '/index.php' || path === '/index.html' || path.indexOf('/index/index') !== -1); } else if (it.id === 'lib') { active = (path.indexOf('/index.php/vod/type/id/1') === 0); } else if (it.id === 'hot') { active = (path.indexOf('/index.php/label/hot') === 0); } else if (it.id === 'me') { active = (path.indexOf('/index.php/user/') === 0); } if (active) a.classList.add('active'); nav.appendChild(a); }); document.body.appendChild(nav); } function init(){ // 图片兜底统一由 mx-mobile-v2-js 处理,避免双 setFallback 竞争导致 src 不替换 initBottomNav(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();