MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 969: | Line 969: | ||
window.grStoreSearchHL = storeQueryForLink; | window.grStoreSearchHL = storeQueryForLink; | ||
}()); | |||
/* ═══════════════════════════════════════════════════════════════ | |||
Mobile addon — only runs on Minerva (mobile) skin | |||
═══════════════════════════════════════════════════════════════ */ | |||
(function () { | |||
if (!document.body.classList.contains('skin-minerva')) return; | |||
function injectMenuLinks() { | |||
if (document.getElementById('gr-mob-menu-items')) return; | |||
var navDrawer = document.querySelector('.navigation-drawer'); | |||
if (!navDrawer) return; | |||
var wrap = document.createElement('div'); wrap.id = 'gr-mob-menu-items'; wrap.style.cssText = 'width:100%;background:#fff;margin-top:8px;'; | |||
var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px;font-size:16px;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;border-bottom:1px solid #f0ebe6;background:#fff;'; | |||
function makeItem(href, label) { var a = document.createElement('a'); a.href = href; a.style.cssText = itemStyle; a.innerHTML = '<span>' + label + '</span>'; return a; } | |||
wrap.appendChild(makeItem('/Main_Page', 'Home')); | |||
wrap.appendChild(makeItem('/My_wiki:Help', 'Help')); | |||
wrap.appendChild(makeItem('/My_wiki:About', 'About')); | |||
var userName = window.mw ? mw.config.get('wgUserName') : null; | |||
if (userName) { | |||
wrap.appendChild(makeItem((window.mw && mw.util && mw.util.getUrl) ? mw.util.getUrl('Special:Profile') : '/Special:Profile', 'Profile')); | |||
var la = document.querySelector('a[href*="action=logout"]'); | |||
wrap.appendChild(makeItem(la ? la.href : '/index.php?title=Special:UserLogout', 'Log out')); | |||
} | |||
else wrap.appendChild(makeItem('/index.php?title=Special:UserLogin', 'Log in')); | |||
var pageLeft = document.getElementById('mw-mf-page-left'); | |||
if (pageLeft) { while (pageLeft.firstChild) pageLeft.removeChild(pageLeft.firstChild); pageLeft.style.removeProperty('display'); pageLeft.appendChild(wrap); } | |||
else navDrawer.appendChild(wrap); | |||
} | |||
function injectMoolaUllekhaLinks() { | |||
if (document.getElementById('gr-mob-doc-nav')) return; | |||
var pageName = (window.mw && mw.config && mw.config.get('wgPageName')) || ''; | |||
if (pageName === 'Main_Page' || !pageName) return; | |||
function wikiUrl(slug) { if (window.mw && mw.util && mw.util.getUrl) return mw.util.getUrl(slug); return ((window.mw && mw.config.get('wgArticlePath')) || '/wiki/$1').replace('$1', encodeURIComponent(slug).replace(/%2F/g, '/')); } | |||
var teekaPage = document.querySelector('.gr-teeka-page'); | |||
var primarySlug = teekaPage ? (teekaPage.getAttribute('data-primary') || pageName.split('/')[0]) : pageName.split('/')[0]; | |||
var docTitleEl = document.querySelector('.gr-doc-title'); | |||
var hasMoolaPage = docTitleEl && docTitleEl.getAttribute('data-has-moola') === '1'; | |||
var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute('data-has-ullekha') === '1'; | |||
var showMoolam = !!teekaPage || hasMoolaPage, showUllekha = hasUllekhaPage || !!teekaPage; | |||
if (!showMoolam && !showUllekha) return; | |||
var nav = document.createElement('div'); nav.id = 'gr-mob-doc-nav'; | |||
nav.style.cssText = 'display:flex;gap:10px;padding:10px 16px 8px;background:#fdf8f5;border-bottom:1px solid #f0e0d6;font-family:system-ui,sans-serif;'; | |||
function makeLink(href, label) { var a = document.createElement('a'); a.href = href; a.textContent = label; a.style.cssText = 'display:inline-flex;align-items:center;padding:5px 16px;border-radius:20px;background:#fff;border:1.5px solid #e8cfc4;color:#b5451b;font-size:14px;font-weight:600;text-decoration:none;'; return a; } | |||
if (teekaPage) nav.appendChild(makeLink(wikiUrl(primarySlug), 'मूल')); | |||
else if (hasMoolaPage) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Moola'), 'मूलम्')); | |||
if (showUllekha) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Ullekha'), 'उल्लेख')); | |||
var h1 = document.getElementById('firstHeading') || document.querySelector('.page-heading, h1.firstHeading, .mw-first-heading'); | |||
if (h1 && h1.parentNode) h1.parentNode.insertBefore(nav, h1.nextSibling); | |||
else { var ct = document.getElementById('mw-content-text'); if (ct) ct.insertBefore(nav, ct.firstChild); } | |||
} | |||
function boot() { injectMenuLinks(); injectMoolaUllekhaLinks();} | |||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); | |||
else boot(); | |||
if (window.mw) mw.hook('wikipage.content'); | |||
}()); | }()); | ||