MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 235: | Line 235: | ||
// The commentary list at the top of a moola page has its own heading | // The commentary list at the top of a moola page has its own heading | ||
// (टीकाः). It isn't part of the text, so it doesn't belong in the | // (टीकाः). It isn't part of the text, so it doesn't belong in the | ||
// contents — | // contents. Recognised by what the section holds — the .gr-doc-teekas | ||
// .gr-doc-teekas), | // list, or a section whose only links are to /Vyakhya/ pages — with | ||
// the heading's own wording as a last resort, since the list markup | |||
// differs between pages and the commentary picker rewrites it. | |||
var TEEKA_HEADINGS = /^(टीकाः?|व्याख्याः?|टीकाग्रन्थाः|Teekas?|Commentaries)$/i; | |||
function isTeekaSection(headingEl) { | |||
var wrap = (headingEl.closest && headingEl.closest('.mw-heading')) || headingEl; | |||
var n = wrap.nextElementSibling, links = [], vyakhya = 0, steps = 0; | |||
while (n && steps < 6) { | |||
if (n.classList && n.classList.contains('gr-doc-teekas')) return true; | |||
if (n.querySelector && n.querySelector('.gr-doc-teekas')) return true; | |||
if ((n.tagName && /^H[1-6]$/.test(n.tagName)) || (n.classList && n.classList.contains('mw-heading'))) break; | |||
if (n.querySelectorAll) { | |||
Array.prototype.forEach.call(n.querySelectorAll('a[href]'), function (a) { | |||
var href = a.getAttribute('href') || ''; | |||
if (/^#/.test(href)) return; | |||
links.push(href); | |||
if (/\/Vyakhya\//i.test(decodeURIComponent(href))) vyakhya++; | |||
}); | |||
} | |||
n = n.nextElementSibling; steps++; | |||
} | |||
if (links.length && vyakhya === links.length) return true; | |||
return TEEKA_HEADINGS.test((headingEl.textContent || '').trim()); | |||
} | |||
function removeTocTeekaEntry() { | function removeTocTeekaEntry() { | ||
if (_isNoTocPage()) return; | if (_isNoTocPage()) return; | ||
| Line 245: | Line 268: | ||
try { id = decodeURIComponent(id); } catch (e) { } | try { id = decodeURIComponent(id); } catch (e) { } | ||
var h = id && document.getElementById(id); | var h = id && document.getElementById(id); | ||
if (!h | if (!h || !isTeekaSection(h)) return; | ||
var li = a.closest('.vector-toc-list-item'); | var li = a.closest('.vector-toc-list-item'); | ||
if (li && li.parentNode) li.parentNode.removeChild(li); | if (li && li.parentNode) li.parentNode.removeChild(li); | ||
| Line 1,296: | Line 1,310: | ||
if (!showMoolam && !showUllekha) return; | if (!showMoolam && !showUllekha) return; | ||
var nav = document.createElement('div'); nav.id = 'gr-mob-doc-nav'; | var nav = document.createElement('div'); nav.id = 'gr-mob-doc-nav'; | ||
nav. | nav.className = 'toc-main-links'; // styled in Common.css §24 | ||
function makeLink(href, label) { var a = document.createElement('a'); a.href = href; a.textContent = label; a. | function makeLink(href, label) { var a = document.createElement('a'); a.href = href; a.textContent = label; a.className = 'toc-main-link-item'; return a; } | ||
if (teekaPage) nav.appendChild(makeLink(wikiUrl(primarySlug), 'मूल')); | if (teekaPage) nav.appendChild(makeLink(wikiUrl(primarySlug), 'मूल')); | ||
else if (hasMoolaPage) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Moola'), 'मूलम्')); | else if (hasMoolaPage) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Moola'), 'मूलम्')); | ||
if (showUllekha) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Ullekha'), 'उल्लेख')); | if (showUllekha) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Ullekha'), 'उल्लेख')); | ||
// Right under the document's own title, which is what a reader on a | |||
// phone actually sees as the title; the skin's h1 is the fallback. | |||
var docTitle = document.querySelector('#mw-content-text .gr-doc-title'); | |||
var h1 = document.getElementById('firstHeading') || document.querySelector('.page-heading, h1.firstHeading, .mw-first-heading'); | var h1 = document.getElementById('firstHeading') || document.querySelector('.page-heading, h1.firstHeading, .mw-first-heading'); | ||
if (h1 && h1.parentNode) h1.parentNode.insertBefore(nav, h1.nextSibling); | if (docTitle && docTitle.parentNode) docTitle.parentNode.insertBefore(nav, docTitle.nextSibling); | ||
else 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); } | else { var ct = document.getElementById('mw-content-text'); if (ct) ct.insertBefore(nav, ct.firstChild); } | ||
} | } | ||