MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 90: | Line 90: | ||
'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | 'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | ||
'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | 'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | ||
' | 'ट':'ட','ठ':'ட','ड':'ட','ढ':'ட','ண':'ண', | ||
'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | 'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | ||
'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | 'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | ||
'य':'ய','र':'ர',' | 'य':'ய','र':'ர','ल':'ல','ळ':'ழ','व':'வ', | ||
'श':'ஶ','ष':'ஷ','स':'ஸ','ह':'ஹ', | 'श':'ஶ','ष':'ஷ','स':'ஸ','ह':'ஹ', | ||
'ा':'ா','ि':'ி','ी':'ீ','ு':'ு','ू':'ூ', | 'ा':'ா','ि':'ி','ी':'ீ','ு':'ு','ू':'ூ', | ||
| Line 138: | Line 138: | ||
if ( p.closest( '.gr-controls' ) ) return; | if ( p.closest( '.gr-controls' ) ) return; | ||
if ( p.closest( '.mw-editsection' ) ) return; | if ( p.closest( '.mw-editsection' ) ) return; | ||
// #gr-toc-doc-nav buttons manage their own data-deva spans in makeBtn | |||
} | } | ||
var orig = node.textContent; | var orig = node.textContent; | ||
| Line 251: | Line 251: | ||
var ullekhaUrl = wikiUrl( primarySlug + '/Ullekha' ); | var ullekhaUrl = wikiUrl( primarySlug + '/Ullekha' ); | ||
var docTitleEl = document.querySelector( '.gr-doc-title' ); | var docTitleEl = document.querySelector( '.gr-doc-title' ); | ||
var hasMoolaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-moola' ) === '1'; | var hasMoolaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-moola' ) === '1'; | ||
var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-ullekha' ) === '1'; | var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-ullekha' ) === '1'; | ||
var moolaPageUrl = wikiUrl( primarySlug + '/Moola' ); | var moolaPageUrl = wikiUrl( primarySlug + '/Moola' ); | ||
var showMoolaPage = !teekaPage && hasMoolaPage; | |||
var showMoolaPage = !teekaPage && hasMoolaPage; | var showMoolaBack = !!teekaPage; | ||
var showMoolaBack = !!teekaPage; | |||
var showUllekha = hasUllekhaPage || !!teekaPage; | var showUllekha = hasUllekhaPage || !!teekaPage; | ||
| Line 285: | Line 267: | ||
nav.setAttribute( 'class', 'toc-main-links'); | nav.setAttribute( 'class', 'toc-main-links'); | ||
// ── CHANGE: makeBtn now wraps label in a data-deva span so | |||
// transliteration (script switching) applies to button text. | |||
function makeBtn( href, label ) { | function makeBtn( href, label ) { | ||
var a = document.createElement( 'a' ); | var a = document.createElement( 'a' ); | ||
a.href = href; | a.href = href; | ||
a.setAttribute( 'class', 'toc-main-link-item'); | a.setAttribute( 'class', 'toc-main-link-item'); | ||
var lspan = document.createElement( 'span' ); | |||
lspan.setAttribute( 'data-deva', label ); | |||
lspan.textContent = ( currentScript && currentScript !== 'deva' ) | |||
? transliterateText( label, currentScript ) | |||
: label; | |||
translatableSpans.push( lspan ); | |||
a.appendChild( lspan ); | |||
a.addEventListener( 'mouseover', function () { this.style.opacity = '0.72'; } ); | a.addEventListener( 'mouseover', function () { this.style.opacity = '0.72'; } ); | ||
a.addEventListener( 'mouseout', function () { this.style.opacity = '1'; } ); | a.addEventListener( 'mouseout', function () { this.style.opacity = '1'; } ); | ||
| Line 302: | Line 285: | ||
} | } | ||
if ( showMoolaPage ) nav.appendChild( makeBtn( moolaPageUrl, 'मूलम्' ) ); | if ( showMoolaPage ) nav.appendChild( makeBtn( moolaPageUrl, 'मूलम्' ) ); | ||
if ( showMoolaBack ) nav.appendChild( makeBtn( moolaUrl, 'मूल' ) ); | if ( showMoolaBack ) nav.appendChild( makeBtn( moolaUrl, 'मूल' ) ); | ||
if ( showUllekha ) nav.appendChild( makeBtn( ullekhaUrl, 'उल्लेख') ); | if ( showUllekha ) nav.appendChild( makeBtn( ullekhaUrl, 'उल्लेख') ); | ||
| Line 315: | Line 295: | ||
// ── TOC active-item highlight ──────────────────────────────────── | // ── TOC active-item highlight ──────────────────────────────────── | ||
function watchTocActive() { | function watchTocActive() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
| Line 333: | Line 312: | ||
var link = li.querySelector( '.vector-toc-link' ) || li.querySelector( 'a' ); | var link = li.querySelector( '.vector-toc-link' ) || li.querySelector( 'a' ); | ||
if ( !link ) return; | if ( !link ) return; | ||
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 379: | Line 354: | ||
if ( active ) { | if ( active ) { | ||
var anc = li.parentNode; | var anc = li.parentNode; | ||
while ( anc && anc !== document.body ) { | while ( anc && anc !== document.body ) { | ||
| Line 390: | Line 364: | ||
} | } | ||
var container = document.querySelector( '.vector-sticky-pinned-container' ); | var container = document.querySelector( '.vector-sticky-pinned-container' ); | ||
if ( container ) { | if ( container ) { | ||
| Line 541: | Line 514: | ||
if ( script ) applyScript( script ); | if ( script ) applyScript( script ); | ||
} ); | } ); | ||
// ── React to script changes from OTHER tabs (BroadcastChannel) ── | |||
try { | |||
var _grBC = new BroadcastChannel( 'gr-script' ); | |||
_grBC.onmessage = function ( e ) { | |||
var script = e && e.data && e.data.script; | |||
if ( script ) { | |||
currentScript = script; | |||
var sel = document.querySelector( '.gr-script-sel' ); | |||
if ( sel ) sel.value = script; | |||
applyScript( script ); | |||
} | |||
}; | |||
} catch ( e ) {} | |||
// ── MediaWiki SPA-style navigation ────────────────────────────── | // ── MediaWiki SPA-style navigation ────────────────────────────── | ||
| Line 575: | Line 562: | ||
// ── Inject "About" link into the header ──────────────────────────── | // ── Inject "About" link into the header ──────────────────────────── | ||
( function () { | ( function () { | ||
function injectAboutLink() { | function injectAboutLink() { | ||
| Line 587: | Line 571: | ||
if ( !headerEnd ) return; | if ( !headerEnd ) return; | ||
var href; | var href; | ||
if ( window.mw && mw.util && mw.util.getUrl ) { | if ( window.mw && mw.util && mw.util.getUrl ) { | ||
| Line 665: | Line 647: | ||
// ── Ullekha reference link handler ───────────────────────────────── | // ── Ullekha reference link handler ───────────────────────────────── | ||
( function () { | ( function () { | ||
function highlightOnArrival() { | function highlightOnArrival() { | ||
var search = window.location.search; | var search = window.location.search; | ||
| Line 686: | Line 661: | ||
if ( !content ) return; | if ( !content ) return; | ||
var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | ||
var found = false; | var found = false; | ||
| Line 693: | Line 666: | ||
var node = walker.currentNode; | var node = walker.currentNode; | ||
var txt = node.textContent || ''; | var txt = node.textContent || ''; | ||
var snippet = needle.slice( 0, 30 ); | var snippet = needle.slice( 0, 30 ); | ||
if ( txt.indexOf( snippet ) !== -1 ) { | if ( txt.indexOf( snippet ) !== -1 ) { | ||
| Line 701: | Line 672: | ||
span.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | span.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | ||
var parent = node.parentNode; | var parent = node.parentNode; | ||
var idx = txt.indexOf( snippet ); | var idx = txt.indexOf( snippet ); | ||
if ( idx >= 0 ) { | if ( idx >= 0 ) { | ||
| Line 712: | Line 682: | ||
parent.insertBefore( after, node ); | parent.insertBefore( after, node ); | ||
parent.removeChild( node ); | parent.removeChild( node ); | ||
setTimeout( function () { | setTimeout( function () { | ||
span.scrollIntoView( { behavior: 'smooth', block: 'center' } ); | span.scrollIntoView( { behavior: 'smooth', block: 'center' } ); | ||
| Line 722: | Line 691: | ||
} | } | ||
function wireUllekhaLinks() { | function wireUllekhaLinks() { | ||
document.querySelectorAll( '.gr-ullekha-ref-link' ).forEach( function ( wrap ) { | document.querySelectorAll( '.gr-ullekha-ref-link' ).forEach( function ( wrap ) { | ||
| Line 730: | Line 698: | ||
if ( !a ) return; | if ( !a ) return; | ||
var base = a.href.split( '#' )[ 0 ]; | var base = a.href.split( '#' )[ 0 ]; | ||
var encoded = encodeURIComponent( hl ); | var encoded = encodeURIComponent( hl ); | ||