MediaWiki:Common.js: Difference between revisions
Undo revision 5755 by Chandrashekars (talk) Tag: Undo |
No edit summary |
||
| Line 91: | Line 91: | ||
'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | 'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | ||
'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | 'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | ||
'ट':'ட','ठ':'ட','ड':'ட','ढ':'ட',' | 'ट':'ட','ठ':'ட','ड':'ட','ढ':'ட','ण':'ண', | ||
'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | 'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | ||
'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | 'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | ||
'य':'ய','र':'ர',' | 'य':'ய','र':'ர','ल':'ல','ळ':'ழ','व':'வ', | ||
'श':'ஶ','ष':'ஷ','स':'ஸ','ह':'ஹ', | 'श':'ஶ','ष':'ஷ','स':'ஸ','ह':'ஹ', | ||
'ा':'ா','ि':'ி','ी':'ீ',' | 'ा':'ா','ि':'ி','ी':'ீ','ु':'ு','ू':'ூ', | ||
'ृ':'ு','ॄ':'ூ', | 'ृ':'ு','ॄ':'ூ', | ||
'े':'ே',' | 'े':'ே','ै':'ை','ो':'ோ','ौ':'ௌ', | ||
'ं':'ம்','ः':':','ँ':'ம்','्':'்','ॐ':'ௐ','ऽ':'ௗ', | 'ं':'ம்','ः':':','ँ':'ம்','्':'்','ॐ':'ௐ','ऽ':'ௗ', | ||
'०':'0','१':'1','२':'2','३':'3','४':'4', | '०':'0','१':'1','२':'2','३':'3','४':'4', | ||
| Line 139: | Line 139: | ||
if ( p.closest( '.gr-controls' ) ) return; | if ( p.closest( '.gr-controls' ) ) return; | ||
if ( p.closest( '.mw-editsection' ) ) return; | if ( p.closest( '.mw-editsection' ) ) return; | ||
} | } | ||
var orig = node.textContent; | var orig = node.textContent; | ||
| Line 194: | Line 193: | ||
var LABEL = 'विषयसूची'; | var LABEL = 'विषयसूची'; | ||
var span = titleEl.querySelector('.gr-toc-title'); | var span = titleEl.querySelector('.gr-toc-title'); | ||
| Line 205: | Line 203: | ||
titleEl.appendChild(span); | titleEl.appendChild(span); | ||
translatableSpans.push(span); | translatableSpans.push(span); | ||
} | } | ||
| Line 218: | Line 216: | ||
var toc = document.querySelector( '.vector-toc' ); | var toc = document.querySelector( '.vector-toc' ); | ||
if ( !toc ) return; | if ( !toc ) return; | ||
var el = toc.querySelector( '#vector-toc-beginning' ); | var el = toc.querySelector( '#vector-toc-beginning' ); | ||
if ( !el ) { | if ( !el ) { | ||
var items = toc.querySelectorAll( '.vector-toc-list-item' ); | var items = toc.querySelectorAll( '.vector-toc-list-item' ); | ||
for ( var i = 0; i < items.length; i++ ) { | for ( var i = 0; i < items.length; i++ ) { | ||
| Line 288: | Line 284: | ||
nav.setAttribute( 'class', 'toc-main-links'); | nav.setAttribute( 'class', 'toc-main-links'); | ||
function makeBtn( href, label ) { | function makeBtn( href, label ) { | ||
var a = document.createElement( 'a' ); | var a = document.createElement( 'a' ); | ||
| Line 448: | Line 442: | ||
// ── TOC: Use Vector's native TOC, add highlight + expand + rename ────── | // ── TOC: Use Vector's native TOC, add highlight + expand + rename ────── | ||
function setupToc() { | function setupToc() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
| Line 469: | Line 455: | ||
// ── IntersectionObserver on actual heading elements ────────────── | // ── IntersectionObserver on actual heading elements ────────────── | ||
var _headingObserver = null; | var _headingObserver = null; | ||
function attachHeadingObserver() { | function attachHeadingObserver() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
if ( _headingObserver ) return; | if ( _headingObserver ) return; | ||
if ( !window.IntersectionObserver ) { | if ( !window.IntersectionObserver ) { | ||
return; /* IntersectionObserver not available — skip active highlight */ | |||
} | } | ||
| Line 484: | Line 467: | ||
var _activeId = null; | var _activeId = null; | ||
var content = document.querySelector( '.mw-parser-output' ); | var content = document.querySelector( '.mw-parser-output' ); | ||
if ( !content ) return; | if ( !content ) return; | ||
| Line 496: | Line 478: | ||
function getTocLink( id ) { | function getTocLink( id ) { | ||
return toc.querySelector( 'a[href="#' + CSS.escape( id ) + '"]' ); | return toc.querySelector( 'a[href="#' + CSS.escape( id ) + '"]' ); | ||
} | } | ||
| Line 506: | Line 487: | ||
function clearActive() { | function clearActive() { | ||
toc.querySelectorAll( '.vector-toc-list-item | /* Clear ALL toc items — prevents multiple items staying highlighted simultaneously */ | ||
toc.querySelectorAll( '.vector-toc-list-item' ).forEach( function ( li ) { | |||
li.classList.remove( 'vector-toc-list-item-active' ); | li.classList.remove( 'vector-toc-list-item-active' ); | ||
var lnk = li.querySelector( '.vector-toc-link' ); | var lnk = li.querySelector( '.vector-toc-link' ); | ||
| Line 530: | Line 512: | ||
li.classList.add( 'vector-toc-list-item-active' ); | li.classList.add( 'vector-toc-list-item-active' ); | ||
var hasActiveChild = !!li.querySelector( | var hasActiveChild = !!li.querySelector( | ||
'.vector-toc-list-item .vector-toc-list-item-active' | '.vector-toc-list-item .vector-toc-list-item-active' | ||
| Line 546: | Line 527: | ||
} | } | ||
// Expand collapsed | // Expand ALL ancestor sections — remove collapsed, force display | ||
var anc = li.parentNode; | var anc = li.parentNode; | ||
while ( anc && anc !== toc ) { | while ( anc && anc !== toc ) { | ||
if ( anc.classList | if ( anc.classList ) { | ||
anc.classList.remove( 'vector-toc-list-item-collapsed' ); | anc.classList.remove( 'vector-toc-list-item-collapsed' ); | ||
} | |||
if ( anc.tagName === 'UL' || anc.tagName === 'LI' ) { | |||
anc.style.removeProperty( 'display' ); | |||
} | } | ||
anc = anc.parentNode; | anc = anc.parentNode; | ||
| Line 567: | Line 551: | ||
} | } | ||
var _visible = new Set(); | var _visible = new Set(); | ||
| Line 579: | Line 562: | ||
} ); | } ); | ||
var topId = null; | var topId = null; | ||
var topY = Infinity; | var topY = Infinity; | ||
| Line 590: | Line 572: | ||
} ); | } ); | ||
if ( !topId ) { | if ( !topId ) { | ||
var bestY = -Infinity; | var bestY = -Infinity; | ||
| Line 601: | Line 582: | ||
setActive( topId || null ); | setActive( topId || null ); | ||
}, { | }, { | ||
rootMargin: '-60px 0px -65% 0px', | rootMargin: '-60px 0px -65% 0px', | ||
threshold: 0 | threshold: 0 | ||
| Line 677: | Line 657: | ||
else { currentScript = 'deva'; } | else { currentScript = 'deva'; } | ||
setTimeout( setupToc, 200 ); | setTimeout( setupToc, 200 ); | ||
} | } | ||
| Line 689: | Line 667: | ||
// ── React to gr-new-content (siteNav panel rendered new items) ── | // ── React to gr-new-content (siteNav panel rendered new items) ── | ||
window.addEventListener( 'gr-new-content', function ( e ) { | window.addEventListener( 'gr-new-content', function ( e ) { | ||
var container = e && e.detail && e.detail.container; | var container = e && e.detail && e.detail.container; | ||
| Line 859: | Line 836: | ||
if ( !needle || needle.length < 4 ) return; | if ( !needle || needle.length < 4 ) return; | ||
function doHighlight() { | function doHighlight() { | ||
var content = document.querySelector( '.mw-parser-output' ); | var content = document.querySelector( '.mw-parser-output' ); | ||
| Line 868: | Line 843: | ||
var found = false; | var found = false; | ||
var spans = content.querySelectorAll( '[data-deva]' ); | var spans = content.querySelectorAll( '[data-deva]' ); | ||
for ( var i = 0; i < spans.length && !found; i++ ) { | for ( var i = 0; i < spans.length && !found; i++ ) { | ||
| Line 875: | Line 849: | ||
if ( orig.indexOf( snippet ) === -1 ) continue; | if ( orig.indexOf( snippet ) === -1 ) continue; | ||
var idx = orig.indexOf( snippet ); | var idx = orig.indexOf( snippet ); | ||
var hlText = orig.slice( idx, Math.min( idx + needle.length, orig.length ) ); | var hlText = orig.slice( idx, Math.min( idx + needle.length, orig.length ) ); | ||
| Line 899: | Line 872: | ||
} | } | ||
if ( !found ) { | if ( !found ) { | ||
var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | ||
| Line 924: | Line 896: | ||
} | } | ||
setTimeout( doHighlight, 600 ); | setTimeout( doHighlight, 600 ); | ||
} | } | ||
| Line 951: | Line 922: | ||
wireUllekhaLinks(); | wireUllekhaLinks(); | ||
} | } | ||
}() );/* ── Search result highlight | }() );/* ── Search result highlight ──────────────────────────────────── */ | ||
( function () { | ( function () { | ||
function storeQueryForLink( url, query ) { | function storeQueryForLink( url, query ) { | ||
try { | try { | ||
var a = document.createElement( 'a' ); | var a = document.createElement( 'a' ); | ||
a.href = url; | a.href = url; | ||
sessionStorage.setItem( 'gr_search_hl', JSON.stringify({ | sessionStorage.setItem( 'gr_search_hl', JSON.stringify({ | ||
query: query, | query: query, | ||
pathname: a.pathname | pathname: a.pathname | ||
}) ); | }) ); | ||
} catch(e) {} | } catch(e) {} | ||
} | } | ||
function applyHighlight() { | function applyHighlight() { | ||
var stored; | var stored; | ||
| Line 980: | Line 943: | ||
if ( !stored || !stored.query ) return; | if ( !stored || !stored.query ) return; | ||
var currentPath = window.location.pathname; | var currentPath = window.location.pathname; | ||
var storedPath = stored.pathname || ''; | var storedPath = stored.pathname || ''; | ||
function normPath(p) { return decodeURIComponent(p).replace(/\/+$/, ''); } | function normPath(p) { return decodeURIComponent(p).replace(/\/+$/, ''); } | ||
if ( storedPath && normPath(storedPath) !== normPath(currentPath) ) { | if ( storedPath && normPath(storedPath) !== normPath(currentPath) ) { | ||
try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | ||
return; | return; | ||
| Line 994: | Line 954: | ||
if ( !query ) return; | if ( !query ) return; | ||
try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | ||
var delays = [400, 900, 1500]; | var delays = [400, 900, 1500]; | ||
delays.forEach( function(ms) { | delays.forEach( function(ms) { | ||
setTimeout( function () { | setTimeout( function () { | ||
if ( !document.querySelector( '.gr-search-hl' ) ) { | if ( !document.querySelector( '.gr-search-hl' ) ) { | ||
highlightText( query ); | highlightText( query ); | ||
| Line 1,009: | Line 966: | ||
} | } | ||
function highlightText( query ) { | function highlightText( query ) { | ||
var content = document.querySelector( '#mw-content-text .mw-parser-output' ); | var content = document.querySelector( '#mw-content-text .mw-parser-output' ); | ||
if ( !content ) return; | if ( !content ) return; | ||
var raw = query.replace( /^"|"$/g, '' ).trim(); | var raw = query.replace( /^"|"$/g, '' ).trim(); | ||
if ( !raw ) return; | if ( !raw ) return; | ||
var patterns = []; | var patterns = []; | ||
patterns.push( escapeRegex( raw ) ); | patterns.push( escapeRegex( raw ) ); | ||
raw.split( /\s+/ ).forEach( function(w) { | raw.split( /\s+/ ).forEach( function(w) { | ||
if ( w.length >= 2 ) patterns.push( escapeRegex( w ) ); | if ( w.length >= 2 ) patterns.push( escapeRegex( w ) ); | ||
| Line 1,040: | Line 991: | ||
if ( !matched ) return; | if ( !matched ) return; | ||
var first = document.querySelector( '.gr-search-hl' ); | var first = document.querySelector( '.gr-search-hl' ); | ||
if ( first ) { | if ( first ) { | ||
first.scrollIntoView({ behavior: 'smooth', block: 'center' }); | first.scrollIntoView({ behavior: 'smooth', block: 'center' }); | ||
first.classList.add( 'gr-search-hl-pulse' ); | first.classList.add( 'gr-search-hl-pulse' ); | ||
setTimeout( function() { | setTimeout( function() { | ||
| Line 1,051: | Line 1,000: | ||
} | } | ||
showDismissBar( query ); | showDismissBar( query ); | ||
} | } | ||
| Line 1,064: | Line 1,012: | ||
root, NodeFilter.SHOW_TEXT, { | root, NodeFilter.SHOW_TEXT, { | ||
acceptNode: function( node ) { | acceptNode: function( node ) { | ||
var p = node.parentElement; | var p = node.parentElement; | ||
if ( !p ) return NodeFilter.FILTER_REJECT; | if ( !p ) return NodeFilter.FILTER_REJECT; | ||
| Line 1,107: | Line 1,054: | ||
} | } | ||
function showDismissBar( query ) { | function showDismissBar( query ) { | ||
var isMob = window.innerWidth < 768; | var isMob = window.innerWidth < 768; | ||
| Line 1,113: | Line 1,059: | ||
bar.id = 'gr-hl-bar'; | bar.id = 'gr-hl-bar'; | ||
if ( isMob ) { | if ( isMob ) { | ||
bar.style.cssText = [ | bar.style.cssText = [ | ||
| Line 1,143: | Line 1,087: | ||
if ( isMob ) { | if ( isMob ) { | ||
bar.innerHTML = | bar.innerHTML = | ||
'<span style="flex-shrink:0">🔍 ' + count + '</span>' + | '<span style="flex-shrink:0">🔍 ' + count + '</span>' + | ||
| Line 1,150: | Line 1,093: | ||
'<button id="gr-hl-dismiss" style="background:rgba(255,255,255,0.15);border:none;color:#fff;min-width:36px;height:36px;border-radius:50%;cursor:pointer;font-size:16px;display:flex;align-items:center;justify-content:center;">✕</button>'; | '<button id="gr-hl-dismiss" style="background:rgba(255,255,255,0.15);border:none;color:#fff;min-width:36px;height:36px;border-radius:50%;cursor:pointer;font-size:16px;display:flex;align-items:center;justify-content:center;">✕</button>'; | ||
} else { | } else { | ||
var nav = document.createElement( 'div' ); | var nav = document.createElement( 'div' ); | ||
nav.style.cssText = 'display:flex;align-items:center;gap:12px;'; | nav.style.cssText = 'display:flex;align-items:center;gap:12px;'; | ||
| Line 1,178: | Line 1,120: | ||
document.body.appendChild( bar ); | document.body.appendChild( bar ); | ||
var hlEls = Array.from( document.querySelectorAll( '.gr-search-hl' ) ); | var hlEls = Array.from( document.querySelectorAll( '.gr-search-hl' ) ); | ||
var currentIdx = 0; | var currentIdx = 0; | ||
| Line 1,207: | Line 1,148: | ||
} | } | ||
function injectHighlightCSS() { | function injectHighlightCSS() { | ||
if ( document.getElementById( 'gr-hl-css' ) ) return; | if ( document.getElementById( 'gr-hl-css' ) ) return; | ||
| Line 1,232: | Line 1,172: | ||
} | } | ||
injectHighlightCSS(); | injectHighlightCSS(); | ||
if ( document.readyState === 'loading' ) { | if ( document.readyState === 'loading' ) { | ||
| Line 1,240: | Line 1,179: | ||
} | } | ||
window.grStoreSearchHL = storeQueryForLink; | window.grStoreSearchHL = storeQueryForLink; | ||
| Line 1,251: | Line 1,189: | ||
if ( !document.body.classList.contains( 'skin-minerva' ) ) return; | if ( !document.body.classList.contains( 'skin-minerva' ) ) return; | ||
/* ── 1. CSS injected into <head> | /* ── 1. CSS injected into <head> ── */ | ||
function injectCSS() { | function injectCSS() { | ||
if ( document.getElementById( 'gr-mob-css' ) ) return; | if ( document.getElementById( 'gr-mob-css' ) ) return; | ||
| Line 1,257: | Line 1,195: | ||
s.id = 'gr-mob-css'; | s.id = 'gr-mob-css'; | ||
s.textContent = | s.textContent = | ||
'body,#mw-mf-viewport,#mw-mf-page-center{padding-top:0!important;margin-top:0!important;}' + | 'body,#mw-mf-viewport,#mw-mf-page-center{padding-top:0!important;margin-top:0!important;}' + | ||
'html,body,#mw-mf-viewport,#mw-mf-page-center{overflow-x:hidden!important;max-width:100vw!important;}' + | 'html,body,#mw-mf-viewport,#mw-mf-page-center{overflow-x:hidden!important;max-width:100vw!important;}' + | ||
'header.header-container{background:#b5451b!important;position:sticky!important;top:0!important;z-index:300!important;}' + | 'header.header-container{background:#b5451b!important;position:sticky!important;top:0!important;z-index:300!important;}' + | ||
'.minerva-header{background:#b5451b!important;min-height:54px!important;}' + | '.minerva-header{background:#b5451b!important;min-height:54px!important;}' + | ||
'.minerva-header .search-toggle,.minerva-header .minerva-user-notifications{display:none!important;}' + | '.minerva-header .search-toggle,.minerva-header .minerva-user-notifications{display:none!important;}' + | ||
'.branding-box a{display:flex!important;align-items:center!important;' + | '.branding-box a{display:flex!important;align-items:center!important;' + | ||
'text-decoration:none!important;max-width:calc(100vw - 80px)!important;}' + | 'text-decoration:none!important;max-width:calc(100vw - 80px)!important;}' + | ||
| Line 1,277: | Line 1,208: | ||
'font-family:system-ui,sans-serif!important;line-height:1.2!important;' + | 'font-family:system-ui,sans-serif!important;line-height:1.2!important;' + | ||
'flex:1 1 auto!important;min-width:0!important;}' + | 'flex:1 1 auto!important;min-width:0!important;}' + | ||
'.minerva-header svg path,.minerva-header svg rect,.minerva-header svg circle{fill:#fff!important;}' + | '.minerva-header svg path,.minerva-header svg rect,.minerva-header svg circle{fill:#fff!important;}' + | ||
'.minerva-header label{color:#fff!important;}' + | '.minerva-header label{color:#fff!important;}' + | ||
'.minerva-tabs,.mw-portlet-associated-pages,.page-actions-menu,' + | '.minerva-tabs,.mw-portlet-associated-pages,.page-actions-menu,' + | ||
'#page-secondary-actions,.last-modified-bar,.minerva-anon-talk-link{display:none!important;}' + | '#page-secondary-actions,.last-modified-bar,.minerva-anon-talk-link{display:none!important;}' + | ||
'#gr-mob-menu-items{display:block!important;}' + | '#gr-mob-menu-items{display:block!important;}' + | ||
'.mw-footer.minerva-footer,.footer-places,.footer-info,' + | '.mw-footer.minerva-footer,.footer-places,.footer-info,' + | ||
'.minerva-footer-logo,#footer-places-about,' + | '.minerva-footer-logo,#footer-places-about,' + | ||
'#footer-places-disclaimers,#footer-places-privacy{display:none!important;}' + | '#footer-places-disclaimers,#footer-places-privacy{display:none!important;}' + | ||
'#gr-static-bar{position:sticky!important;top:54px!important;z-index:200!important;}' + | '#gr-static-bar{position:sticky!important;top:54px!important;z-index:200!important;}' + | ||
'.mf-section-0,.mf-section-1,.mf-section-2,.mf-section-3,.mf-section-4,' + | '.mf-section-0,.mf-section-1,.mf-section-2,.mf-section-3,.mf-section-4,' + | ||
'.mf-section-5,.mf-section-6,.mf-section-7,.mf-section-8,.mf-section-9,' + | '.mf-section-5,.mf-section-6,.mf-section-7,.mf-section-8,.mf-section-9,' + | ||
| Line 1,305: | Line 1,223: | ||
'.section-heading .indicator,.collapsible-heading .indicator{display:none!important;}' + | '.section-heading .indicator,.collapsible-heading .indicator{display:none!important;}' + | ||
'.section-heading,.collapsible-heading{pointer-events:none!important;}' + | '.section-heading,.collapsible-heading{pointer-events:none!important;}' + | ||
'.gr-home-grid{flex-direction:column!important;flex-wrap:nowrap!important;' + | '.gr-home-grid{flex-direction:column!important;flex-wrap:nowrap!important;' + | ||
'gap:12px!important;width:100%!important;}' + | 'gap:12px!important;width:100%!important;}' + | ||
| Line 1,312: | Line 1,228: | ||
'min-width:unset!important;box-sizing:border-box!important;flex:none!important;}' + | 'min-width:unset!important;box-sizing:border-box!important;flex:none!important;}' + | ||
'.gr-home-toggle{flex-wrap:wrap!important;}' + | '.gr-home-toggle{flex-wrap:wrap!important;}' + | ||
'.mw-parser-output{font-size:18px!important;line-height:1.8!important;}' + | '.mw-parser-output{font-size:18px!important;line-height:1.8!important;}' + | ||
'.mw-parser-output h2,.mw-parser-output h3{width:100%!important;}' + | '.mw-parser-output h2,.mw-parser-output h3{width:100%!important;}' + | ||
'.bhashyam-block{margin-left:8px!important;}' + | '.bhashyam-block{margin-left:8px!important;}' + | ||
'#footer,.mw-footer,.catlinks,#catlinks{display:none!important;}' + | '#footer,.mw-footer,.catlinks,#catlinks{display:none!important;}' + | ||
'.gr-mob-toc-panel{position:fixed!important;top:0!important;left:0!important;' + | '.gr-mob-toc-panel{position:fixed!important;top:0!important;left:0!important;' + | ||
'bottom:0!important;width:82vw!important;max-width:340px!important;' + | 'bottom:0!important;width:82vw!important;max-width:340px!important;' + | ||
| Line 1,360: | Line 1,272: | ||
} | } | ||
function watchSections() { | function watchSections() { | ||
var t = null; | var t = null; | ||
| Line 1,383: | Line 1,294: | ||
/* ── 4. Inject custom links into drawer ── */ | /* ── 4. Inject custom links into drawer ── */ | ||
function injectMenuLinks() { | function injectMenuLinks() { | ||
if ( document.getElementById( 'gr-mob-menu-items' ) ) return; | if ( document.getElementById( 'gr-mob-menu-items' ) ) return; | ||
var navDrawer = document.querySelector( '.navigation-drawer' ); | var navDrawer = document.querySelector( '.navigation-drawer' ); | ||
if ( !navDrawer ) return; | if ( !navDrawer ) return; | ||
| Line 1,422: | Line 1,330: | ||
} | } | ||
var pageLeft = document.getElementById( 'mw-mf-page-left' ); | var pageLeft = document.getElementById( 'mw-mf-page-left' ); | ||
if ( pageLeft ) { | if ( pageLeft ) { | ||
while ( pageLeft.firstChild ) pageLeft.removeChild( pageLeft.firstChild ); | while ( pageLeft.firstChild ) pageLeft.removeChild( pageLeft.firstChild ); | ||
pageLeft.style.removeProperty( 'display' ); | pageLeft.style.removeProperty( 'display' ); | ||
pageLeft.appendChild( wrap ); | pageLeft.appendChild( wrap ); | ||
} else { | } else { | ||
navDrawer.appendChild( wrap ); | navDrawer.appendChild( wrap ); | ||
} | } | ||
document.querySelectorAll( | document.querySelectorAll( | ||
'.mw-footer.minerva-footer,.footer-places,.footer-info,' + | '.mw-footer.minerva-footer,.footer-places,.footer-info,' + | ||
| Line 1,490: | Line 1,393: | ||
btn.onclick = open; cls.onclick = close; bd.onclick = close; | btn.onclick = open; cls.onclick = close; bd.onclick = close; | ||
body.querySelectorAll('a').forEach(function(a){ a.onclick = close; }); | body.querySelectorAll('a').forEach(function(a){ a.onclick = close; }); | ||
} | |||
/* ── 6. Moolam / Ullekha links below page title (mobile only) ── */ | |||
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 ); | |||
var ap = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1'; | |||
return ap.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; | |||
var 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' ), 'उल्लेख' ) ); | |||
/* Insert below the page h1 */ | |||
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 ); | |||
} | |||
} | } | ||
| Line 1,500: | Line 1,456: | ||
watchSections(); | watchSections(); | ||
injectMenuLinks(); | injectMenuLinks(); | ||
injectMoolaUllekhaLinks(); | |||
[100, 400, 900, 1800].forEach(function(ms){ setTimeout(expandSections, ms); }); | [100, 400, 900, 1800].forEach(function(ms){ setTimeout(expandSections, ms); }); | ||
setTimeout(initToc, 700); | setTimeout(initToc, 700); | ||
| Line 1,512: | Line 1,469: | ||
if ( window.mw ) { | if ( window.mw ) { | ||
mw.hook( 'wikipage.content' ).add(function() { | mw.hook( 'wikipage.content' ).add(function() { | ||
setTimeout(function(){ expandSections(); injectMenuLinks(); initToc(); }, 300); | setTimeout(function(){ | ||
expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); | |||
}, 300); | |||
}); | }); | ||
} | } | ||
| Line 1,519: | Line 1,478: | ||
/** | /** | ||
* grantha-mobile-fixes.js | * grantha-mobile-fixes.js | ||
*/ | */ | ||
| Line 1,531: | Line 1,483: | ||
'use strict'; | 'use strict'; | ||
mw.hook( 'wikipage.content' ).add( function () { | mw.hook( 'wikipage.content' ).add( function () { | ||
setTimeout( function () { | setTimeout( function () { | ||
var blocks = document.querySelectorAll( '.collapsible-block, .toggle-list' ); | var blocks = document.querySelectorAll( '.collapsible-block, .toggle-list' ); | ||
Array.prototype.forEach.call( blocks, function ( el ) { | Array.prototype.forEach.call( blocks, function ( el ) { | ||
if ( !el.parentNode ) { | if ( !el.parentNode ) { | ||
try { el.remove(); } catch(e) {} | try { el.remove(); } catch(e) {} | ||
| Line 1,553: | Line 1,493: | ||
}, 0 ); | }, 0 ); | ||
} ); | } ); | ||
if ( mw.config.get( 'wgPageName' ) !== 'Main_Page' ) return; | if ( mw.config.get( 'wgPageName' ) !== 'Main_Page' ) return; | ||
| Line 1,563: | Line 1,499: | ||
$( function () { | $( function () { | ||
applyHomeToggleOffset(); | applyHomeToggleOffset(); | ||
window.addEventListener( 'resize', applyHomeToggleOffset, { passive: true } ); | window.addEventListener( 'resize', applyHomeToggleOffset, { passive: true } ); | ||
setTimeout( applyHomeToggleOffset, 300 ); | setTimeout( applyHomeToggleOffset, 300 ); | ||
setTimeout( applyHomeToggleOffset, 800 ); | setTimeout( applyHomeToggleOffset, 800 ); | ||
| Line 1,578: | Line 1,510: | ||
var barRect = bar.getBoundingClientRect(); | var barRect = bar.getBoundingClientRect(); | ||
var barBottom = Math.round( barRect.bottom ); | var barBottom = Math.round( barRect.bottom ); | ||
var homeEl = document.getElementById( 'gr-home' ); | var homeEl = document.getElementById( 'gr-home' ); | ||
var toggleEl = document.getElementById( 'gr-home-toggle' ); | var toggleEl = document.getElementById( 'gr-home-toggle' ); | ||
var firstChild = document.querySelector( | var firstChild = document.querySelector( | ||
'#mw-content-text .mw-parser-output > .gr-home, ' + | '#mw-content-text .mw-parser-output > .gr-home, ' + | ||
| Line 1,594: | Line 1,519: | ||
); | ); | ||
[ homeEl, toggleEl, firstChild ].forEach( function ( el ) { | [ homeEl, toggleEl, firstChild ].forEach( function ( el ) { | ||
if ( el ) el.style.scrollMarginTop = ( barBottom + 4 ) + 'px'; | if ( el ) el.style.scrollMarginTop = ( barBottom + 4 ) + 'px'; | ||
} ); | } ); | ||
var contentText = document.getElementById( 'mw-content-text' ); | var contentText = document.getElementById( 'mw-content-text' ); | ||
if ( contentText ) { | if ( contentText ) { | ||
var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' ); | var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' ); | ||
if ( isMob ) { | if ( isMob ) { | ||
if ( toggleEl ) { | if ( toggleEl ) { | ||
var toggleRect = toggleEl.getBoundingClientRect(); | var toggleRect = toggleEl.getBoundingClientRect(); | ||
if ( toggleRect.top < barBottom ) { | if ( toggleRect.top < barBottom ) { | ||
var currentPT = parseInt( window.getComputedStyle( document.body ).paddingTop, 10 ) || 0; | var currentPT = parseInt( window.getComputedStyle( document.body ).paddingTop, 10 ) || 0; | ||
| Line 1,623: | Line 1,539: | ||
} | } | ||
$( function () { | $( function () { | ||
var $toggle = $( '#gr-home-toggle' ); | var $toggle = $( '#gr-home-toggle' ); | ||
| Line 1,635: | Line 1,547: | ||
if ( !$toggle.length || !$viewG.length || !$viewA.length ) return; | if ( !$toggle.length || !$viewG.length || !$viewA.length ) return; | ||
if ( $toggle.data( 'gr-wired' ) ) return; | if ( $toggle.data( 'gr-wired' ) ) return; | ||
$toggle.data( 'gr-wired', true ); | $toggle.data( 'gr-wired', true ); | ||
| Line 1,661: | Line 1,572: | ||
}); | }); | ||
try { | try { | ||
var saved = localStorage.getItem( 'grantha_home_tab' ); | var saved = localStorage.getItem( 'grantha_home_tab' ); | ||