MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* MediaWiki:Common.js — grantha.io (v7) | /* MediaWiki:Common.js — grantha.io (v7) */ | ||
( function () { | ( function () { | ||
| Line 22: | Line 6: | ||
var currentScript = 'deva'; | var currentScript = 'deva'; | ||
function devanagariToIAST( text ) { | function devanagariToIAST( text ) { | ||
var CONSONANTS = { | var CONSONANTS = { | ||
| Line 67: | Line 50: | ||
} | } | ||
var SCRIPT_MAP = { | var SCRIPT_MAP = { | ||
kn: { | kn: { | ||
| Line 91: | Line 73: | ||
'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | 'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங', | ||
'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | 'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ', | ||
' | 'ட':'ட','ठ':'ட','ड':'ட','ढ':'ட','ண':'ண', | ||
'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | 'त':'த','थ':'த','द':'த','ध':'த','न':'ந', | ||
'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | 'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம', | ||
| Line 98: | Line 80: | ||
'ा':'ா','ि':'ி','ी':'ீ','ु':'ு','ू':'ூ', | 'ा':'ா','ि':'ி','ी':'ீ','ु':'ு','ू':'ூ', | ||
'ृ':'ு','ॄ':'ூ', | 'ृ':'ு','ॄ':'ூ', | ||
'े':'ே',' | 'े':'ே','ை':'ை','ो':'ோ','ौ':'ௌ', | ||
'ं':'ம்','ः':':','ँ':'ம்','्':'்','ॐ':'ௐ','ऽ':'ௗ', | 'ं':'ம்','ः':':','ँ':'ம்','्':'்','ॐ':'ௐ','ऽ':'ௗ', | ||
'०':'0','१':'1','२':'2','३':'3','४':'4', | '०':'0','१':'1','२':'2','३':'3','४':'4', | ||
| Line 122: | Line 104: | ||
} | } | ||
var translatableSpans = []; | var translatableSpans = []; | ||
| Line 131: | Line 112: | ||
var nodes = []; | var nodes = []; | ||
while ( walker.nextNode() ) nodes.push( walker.currentNode ); | while ( walker.nextNode() ) nodes.push( walker.currentNode ); | ||
nodes.forEach( function ( node ) { | nodes.forEach( function ( node ) { | ||
var p = node.parentNode; | var p = node.parentNode; | ||
| Line 149: | Line 129: | ||
} ); | } ); | ||
} | } | ||
document.querySelectorAll( '.vector-toc .vector-toc-text' ).forEach( function ( span ) { | document.querySelectorAll( '.vector-toc .vector-toc-text' ).forEach( function ( span ) { | ||
if ( span.hasAttribute( 'data-deva' ) ) return; | if ( span.hasAttribute( 'data-deva' ) ) return; | ||
| Line 159: | Line 138: | ||
} | } | ||
function applyScript( script ) { | function applyScript( script ) { | ||
currentScript = script; | currentScript = script; | ||
| Line 172: | Line 150: | ||
} | } | ||
function _isNoTocPage() { | function _isNoTocPage() { | ||
var pn = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | var pn = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | ||
| Line 178: | Line 155: | ||
} | } | ||
function renameTocTitle() { | |||
function renameTocTitle() { | if ( _isNoTocPage() ) return; | ||
var toc = document.querySelector('.vector-toc'); | |||
if ( !toc ) return; | |||
var titleEl = toc.querySelector('.vector-toc-title') || toc.querySelector('.vector-pinnable-header-label'); | |||
if ( !titleEl ) return; | |||
var LABEL = 'विषयसूची'; | |||
var span = titleEl.querySelector('.gr-toc-title'); | |||
if ( !span ) { | |||
titleEl.innerHTML = ''; | |||
span = document.createElement('span'); | |||
span.className = 'gr-toc-title'; | |||
span.setAttribute('data-deva', LABEL); | |||
titleEl.appendChild(span); | |||
translatableSpans.push(span); | |||
} | |||
span.textContent = currentScript === 'deva' ? LABEL : transliterateText(LABEL, currentScript); | |||
} | } | ||
function removeTocBeginning() { | function removeTocBeginning() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
| Line 230: | Line 192: | ||
} | } | ||
function expandTocSections() { | function expandTocSections() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
| Line 240: | Line 201: | ||
} | } | ||
function injectTocDocNav() { | function injectTocDocNav() { | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
| Line 246: | Line 206: | ||
if ( !toc ) return; | if ( !toc ) return; | ||
if ( document.getElementById( 'gr-toc-doc-nav' ) ) return; | if ( document.getElementById( 'gr-toc-doc-nav' ) ) return; | ||
var artPath = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1'; | var artPath = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1'; | ||
var pageTitle = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | var pageTitle = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | ||
var teekaPage = document.querySelector( '.gr-teeka-page' ); | var teekaPage = document.querySelector( '.gr-teeka-page' ); | ||
var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || '' ) : ''; | var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || '' ) : ''; | ||
if ( !primarySlug ) { primarySlug = pageTitle.split( '/' )[ 0 ]; } | |||
if ( !primarySlug ) { | |||
if ( !primarySlug ) return; | if ( !primarySlug ) return; | ||
function wikiUrl( slug ) { | function wikiUrl( slug ) { | ||
if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug ); | if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug ); | ||
return artPath.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); | return artPath.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); | ||
} | } | ||
var docTitleEl = document.querySelector( '.gr-doc-title' ); | |||
var | |||
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 showMoolaPage = !teekaPage && hasMoolaPage; | var showMoolaPage = !teekaPage && hasMoolaPage; | ||
var showMoolaBack = !!teekaPage; | var showMoolaBack = !!teekaPage; | ||
var showUllekha = hasUllekhaPage || !!teekaPage; | var showUllekha = hasUllekhaPage || !!teekaPage; | ||
if ( !showMoolaPage && !showMoolaBack && !showUllekha ) return; | if ( !showMoolaPage && !showMoolaBack && !showUllekha ) return; | ||
var nav = document.createElement( 'div' ); | var nav = document.createElement( 'div' ); | ||
nav.id = 'gr-toc-doc-nav'; | nav.id = 'gr-toc-doc-nav'; | ||
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' ); | ||
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' ); | var lspan = document.createElement( 'span' ); | ||
lspan.setAttribute( 'data-deva', label ); | lspan.setAttribute( 'data-deva', label ); | ||
lspan.textContent = ( currentScript && currentScript !== 'deva' ) | lspan.textContent = ( currentScript && currentScript !== 'deva' ) ? transliterateText( label, currentScript ) : label; | ||
translatableSpans.push( lspan ); | translatableSpans.push( lspan ); | ||
a.appendChild( lspan ); | a.appendChild( lspan ); | ||
| Line 299: | Line 239: | ||
return a; | return a; | ||
} | } | ||
if ( showMoolaPage ) nav.appendChild( makeBtn( wikiUrl( primarySlug + '/Moola' ), 'मूलम्' ) ); | |||
if ( showMoolaPage ) nav.appendChild( makeBtn( | if ( showMoolaBack ) nav.appendChild( makeBtn( wikiUrl( primarySlug ), 'मूल' ) ); | ||
if ( showMoolaBack ) nav.appendChild( makeBtn( | if ( showUllekha ) nav.appendChild( makeBtn( wikiUrl( primarySlug + '/Ullekha'), 'उल्लेख') ); | ||
if ( showUllekha ) nav.appendChild( makeBtn( | |||
var tocContents = toc.querySelector( '.vector-toc-contents' ); | var tocContents = toc.querySelector( '.vector-toc-contents' ); | ||
if ( tocContents ) toc.insertBefore( nav, tocContents ); | if ( tocContents ) toc.insertBefore( nav, tocContents ); | ||
| Line 309: | Line 247: | ||
} | } | ||
var _headingObserver = null; | var _headingObserver = null; | ||
| Line 460: | Line 252: | ||
if ( _isNoTocPage() ) return; | if ( _isNoTocPage() ) return; | ||
if ( _headingObserver ) return; | if ( _headingObserver ) return; | ||
if ( !window.IntersectionObserver ) | if ( !window.IntersectionObserver ) return; | ||
var ACTIVE_COLOR = '#f57c00'; | var ACTIVE_COLOR = '#f57c00'; | ||
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; | ||
var headings = Array.from( | var headings = Array.from( content.querySelectorAll( 'h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]' ) ); | ||
if ( !headings.length ) return; | if ( !headings.length ) return; | ||
var toc = document.querySelector( '.vector-toc' ); | var toc = document.querySelector( '.vector-toc' ); | ||
if ( !toc ) return; | if ( !toc ) return; | ||
function getTocLink( id ) { return toc.querySelector( 'a[href="#' + CSS.escape( id ) + '"]' ); } | |||
function getTocLink( id ) { | function getTocLi( id ) { var a = getTocLink( id ); return a ? a.closest( '.vector-toc-list-item' ) : null; } | ||
function getTocLi( id ) { | |||
function clearActive() { | function clearActive() { | ||
toc.querySelectorAll( '.vector-toc-list-item' ).forEach( function ( li ) { | 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' ); | ||
| Line 494: | Line 270: | ||
lnk.style.removeProperty( 'color' ); | lnk.style.removeProperty( 'color' ); | ||
lnk.style.setProperty( 'font-weight', '400', 'important' ); | lnk.style.setProperty( 'font-weight', '400', 'important' ); | ||
lnk.querySelectorAll( '*' ).forEach( function ( el ) { | lnk.querySelectorAll( '*' ).forEach( function ( el ) { el.style.removeProperty( 'color' ); el.style.setProperty( 'font-weight', '400', 'important' ); } ); | ||
} ); | } ); | ||
} | } | ||
function setActive( id ) { | function setActive( id ) { | ||
if ( _activeId === id ) return; | if ( _activeId === id ) return; | ||
| Line 506: | Line 278: | ||
clearActive(); | clearActive(); | ||
if ( !id ) return; | if ( !id ) return; | ||
var li = getTocLi( id ); | var li = getTocLi( id ); | ||
if ( !li ) return; | if ( !li ) return; | ||
li.classList.add( 'vector-toc-list-item-active' ); | li.classList.add( 'vector-toc-list-item-active' ); | ||
var hasActiveChild = !!li.querySelector( '.vector-toc-list-item .vector-toc-list-item-active' ); | |||
var hasActiveChild = !!li.querySelector( | |||
if ( !hasActiveChild ) { | if ( !hasActiveChild ) { | ||
var lnk = li.querySelector( '.vector-toc-link' ); | var lnk = li.querySelector( '.vector-toc-link' ); | ||
if ( lnk ) { | if ( lnk ) { | ||
lnk.style.setProperty( 'color', | lnk.style.setProperty( 'color', ACTIVE_COLOR, 'important' ); | ||
lnk.style.setProperty( 'font-weight', '700', | lnk.style.setProperty( 'font-weight', '700', 'important' ); | ||
lnk.querySelectorAll( '*' ).forEach( function ( el ) { | lnk.querySelectorAll( '*' ).forEach( function ( el ) { el.style.setProperty( 'color', ACTIVE_COLOR, 'important' ); el.style.setProperty( 'font-weight', '700', 'important' ); } ); | ||
} | } | ||
} | } | ||
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' ); | ||
if ( anc.tagName === 'UL' || anc.tagName === 'LI' ) anc.style.removeProperty( 'display' ); | |||
if ( anc.tagName === 'UL' || anc.tagName === 'LI' ) | |||
anc = anc.parentNode; | anc = anc.parentNode; | ||
} | } | ||
var sticky = document.querySelector( '.vector-sticky-pinned-container' ); | var sticky = document.querySelector( '.vector-sticky-pinned-container' ); | ||
var scrollEl = sticky || toc; | var scrollEl = sticky || toc; | ||
| Line 550: | Line 306: | ||
} | } | ||
} | } | ||
var _visible = new Set(); | var _visible = new Set(); | ||
_headingObserver = new IntersectionObserver( function ( entries ) { | _headingObserver = new IntersectionObserver( function ( entries ) { | ||
entries.forEach( function ( entry ) { | entries.forEach( function ( entry ) { | ||
if ( entry.isIntersecting ) | if ( entry.isIntersecting ) _visible.add( entry.target.id ); | ||
else _visible.delete( entry.target.id ); | |||
} ); | } ); | ||
var topId = null, topY = Infinity; | |||
var topId = null | |||
_visible.forEach( function ( id ) { | _visible.forEach( function ( id ) { | ||
var el = document.getElementById( id ); | var el = document.getElementById( id ); | ||
if ( el ) { | if ( el ) { var y = el.getBoundingClientRect().top; if ( y >= 0 && y < topY ) { topY = y; topId = id; } } | ||
} ); | } ); | ||
if ( !topId ) { | if ( !topId ) { | ||
var bestY = -Infinity; | var bestY = -Infinity; | ||
headings.forEach( function ( h ) { | headings.forEach( function ( h ) { var y = h.getBoundingClientRect().top; if ( y < 0 && y > bestY ) { bestY = y; topId = h.id; } } ); | ||
} | } | ||
setActive( topId || null ); | setActive( topId || null ); | ||
}, { | }, { rootMargin: '-60px 0px -65% 0px', threshold: 0 } ); | ||
headings.forEach( function ( h ) { _headingObserver.observe( h ); } ); | |||
} | |||
} ); | |||
function setupToc() { | |||
if ( _isNoTocPage() ) return; | |||
var toc = document.querySelector( '.vector-toc' ); | |||
if ( !toc ) return; | |||
removeTocBeginning(); | |||
renameTocTitle(); | |||
expandTocSections(); | |||
injectTocDocNav(); | |||
attachHeadingObserver(); | |||
} | } | ||
function init() { | function init() { | ||
var HIDE_IDS = [ | var HIDE_IDS = [ 'vector-appearance', 'vector-appearance-pinned-container', 'vector-appearance-unpinned-container' ]; | ||
function removeHiddenEls() { | function removeHiddenEls() { | ||
HIDE_IDS.forEach( function ( id ) { | HIDE_IDS.forEach( function ( id ) { var el = document.getElementById( id ); if ( el && el.parentNode ) el.parentNode.removeChild( el ); } ); | ||
var pt = document.getElementById( 'vector-page-tools' ) || document.querySelector( '.vector-page-tools-pinned-container' ); | |||
if ( pt ) pt.querySelectorAll( '[aria-controls="vector-appearance"]' ).forEach( function ( el ) { if ( el.parentNode ) el.parentNode.removeChild( el ); } ); | |||
var pt = document.getElementById( 'vector-page-tools' ) || | |||
if ( pt ) | |||
} | } | ||
removeHiddenEls(); | removeHiddenEls(); | ||
( function detectTeekaMode() { | ( function detectTeekaMode() { | ||
var tp = document.querySelector( '.gr-teeka-page' ); | var tp = document.querySelector( '.gr-teeka-page' ); | ||
| Line 617: | Line 352: | ||
var mainUrl = artPath.replace( '$1', primary ); | var mainUrl = artPath.replace( '$1', primary ); | ||
var refParam = window.location.search.match( /[?&]ref=([01])/ ); | var refParam = window.location.search.match( /[?&]ref=([01])/ ); | ||
if ( refParam ) { | if ( refParam ) { document.body.classList.add( refParam[1] === '1' ? 'gr-ref-mode' : 'gr-standalone' ); return; } | ||
var ref = document.referrer || ''; | var ref = document.referrer || ''; | ||
document.body.classList.add( | document.body.classList.add( ( ref && primary && ref.indexOf( mainUrl ) !== -1 ) ? 'gr-ref-mode' : 'gr-standalone' ); | ||
}() ); | }() ); | ||
if ( window.MutationObserver ) { | if ( window.MutationObserver ) { | ||
var hideObs = new MutationObserver( function ( mutations ) { | var hideObs = new MutationObserver( function ( mutations ) { | ||
| Line 636: | Line 365: | ||
setTimeout( function () { hideObs.disconnect(); }, 6000 ); | setTimeout( function () { hideObs.disconnect(); }, 6000 ); | ||
} | } | ||
var content = document.querySelector( '.mw-parser-output' ); | |||
var content | |||
var alreadyTagged = content && content.querySelector( '[data-deva]' ); | var alreadyTagged = content && content.querySelector( '[data-deva]' ); | ||
if ( !alreadyTagged ) { | if ( !alreadyTagged ) { translatableSpans = []; tagTextNodes(); } | ||
else { | |||
document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) { | document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) { | ||
var orig = span.textContent; | var orig = span.textContent; if ( !orig.trim() ) return; | ||
span.setAttribute( 'data-deva', orig ); translatableSpans.push( span ); | |||
span.setAttribute( 'data-deva', orig ); | |||
} ); | } ); | ||
} | } | ||
var saved = ( function () { try { return localStorage.getItem( LS_SCRIPT_KEY ); } catch ( e ) { return null; } }() ); | |||
var saved = ( function () { | if ( saved && saved !== 'deva' ) { applyScript( saved ); } else { currentScript = 'deva'; } | ||
if ( saved && saved !== 'deva' ) { applyScript( saved ); } | |||
setTimeout( setupToc, 200 ); | setTimeout( setupToc, 200 ); | ||
} | } | ||
window.addEventListener( 'gr-script-change', function ( e ) { | window.addEventListener( 'gr-script-change', function ( e ) { | ||
var script = e && e.detail && e.detail.script; | var script = e && e.detail && e.detail.script; | ||
| Line 666: | Line 384: | ||
} ); | } ); | ||
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 686: | Line 403: | ||
} ); | } ); | ||
try { | try { | ||
var _grBC = new BroadcastChannel( 'gr-script' ); | var _grBC = new BroadcastChannel( 'gr-script' ); | ||
_grBC.onmessage = function ( e ) { | _grBC.onmessage = function ( e ) { | ||
var script = e && e.data && e.data.script; | var script = e && e.data && e.data.script; | ||
if ( script ) { | if ( script ) { currentScript = script; var sel = document.querySelector( '.gr-script-sel' ); if ( sel ) sel.value = script; applyScript( script ); } | ||
}; | }; | ||
} catch ( e ) {} | } catch ( e ) {} | ||
if ( window.mw ) { | if ( window.mw ) { | ||
mw.hook( 'wikipage.content' ).add( function () { | mw.hook( 'wikipage.content' ).add( function () { | ||
setTimeout( function () { | setTimeout( function () { | ||
var content | var content = document.querySelector( '.mw-parser-output' ); | ||
var alreadyTagged = content && content.querySelector( '[data-deva]' ); | var alreadyTagged = content && content.querySelector( '[data-deva]' ); | ||
if ( !alreadyTagged ) { | if ( !alreadyTagged ) { translatableSpans = []; tagTextNodes(); } | ||
else { | |||
document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) { | document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) { | ||
var orig = span.textContent; | var orig = span.textContent; if ( !orig.trim() ) return; | ||
span.setAttribute( 'data-deva', orig ); translatableSpans.push( span ); | |||
span.setAttribute( 'data-deva', orig ); | |||
} ); | } ); | ||
} | } | ||
| Line 723: | Line 429: | ||
} | } | ||
if ( document.readyState === 'loading' ) { | if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', init ); } | ||
else { init(); } | |||
}() ); /* ← end of main IIFE */ | }() ); /* ← end of main IIFE */ | ||
| Line 739: | Line 442: | ||
return ap.replace( '$1', title ); | return ap.replace( '$1', title ); | ||
} | } | ||
var linkStyle = [ 'color:rgba(255,255,255,0.88)','font-size:0.88em','font-family:system-ui,sans-serif','font-weight:500','text-decoration:none','padding:4px 10px','border-radius:4px','margin-right:4px','transition:color 0.15s,background 0.15s','white-space:nowrap' ].join( ';' ); | |||
var linkStyle = [ | |||
function makeHeaderLink( id, href, label ) { | function makeHeaderLink( id, href, label ) { | ||
var a = document.createElement( 'a' ); | var a = document.createElement( 'a' ); | ||
a.id = id; a.href = href; a.textContent = label; | a.id = id; a.href = href; a.textContent = label; a.style.cssText = linkStyle; | ||
a.addEventListener( 'mouseover', function () { this.style.color = '#fff'; this.style.background = 'rgba(255,255,255,0.12)'; } ); | |||
a.addEventListener( 'mouseover', function () { | a.addEventListener( 'mouseout', function () { this.style.color = 'rgba(255,255,255,0.88)'; this.style.background = 'transparent'; } ); | ||
a.addEventListener( 'mouseout', function () { | |||
return a; | return a; | ||
} | } | ||
function injectHeaderLinks() { | function injectHeaderLinks() { | ||
if ( document.getElementById( 'gr-about-link' ) ) return; | if ( document.getElementById( 'gr-about-link' ) ) return; | ||
var headerEnd = document.querySelector( '.vector-header-end' ) || document.querySelector( '#vector-user-links' ) || document.querySelector( '.mw-header' ); | |||
var headerEnd = document.querySelector( '.vector-header-end' ) || | |||
if ( !headerEnd ) return; | if ( !headerEnd ) return; | ||
var helpLink = makeHeaderLink( 'gr-help-link', wikiHref( 'My_wiki:Help' ), 'Help' ); | var helpLink = makeHeaderLink( 'gr-help-link', wikiHref( 'My_wiki:Help' ), 'Help' ); | ||
var aboutLink = makeHeaderLink( 'gr-about-link', wikiHref( 'My_wiki:About' ), 'About' ); | var aboutLink = makeHeaderLink( 'gr-about-link', wikiHref( 'My_wiki:About' ), 'About' ); | ||
var ul = document.querySelector( '.vector-user-links' ) || document.querySelector( '#pt-userpage' ); | |||
var ul = document.querySelector( '.vector-user-links' ) || | if ( ul && ul.parentNode === headerEnd ) { headerEnd.insertBefore( aboutLink, ul ); headerEnd.insertBefore( helpLink, aboutLink ); } | ||
else { headerEnd.appendChild( helpLink ); headerEnd.appendChild( aboutLink ); } | |||
if ( ul && ul.parentNode === headerEnd ) { | |||
} | } | ||
if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', injectHeaderLinks ); | if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', injectHeaderLinks ); | ||
else injectHeaderLinks(); | else injectHeaderLinks(); | ||
| Line 802: | Line 479: | ||
try { localStorage.setItem( 'gr_home_view', v ); } catch ( e ) {} | try { localStorage.setItem( 'gr_home_view', v ); } catch ( e ) {} | ||
} | } | ||
function initHomeToggle() { | function initHomeToggle() { | ||
var gBtn = document.getElementById( 'gr-toggle-grantha' ); | var gBtn = document.getElementById( 'gr-toggle-grantha' ); | ||
| Line 809: | Line 485: | ||
gBtn.addEventListener( 'click', function () { grHomeView( 'grantha' ); } ); | gBtn.addEventListener( 'click', function () { grHomeView( 'grantha' ); } ); | ||
aBtn.addEventListener( 'click', function () { grHomeView( 'author' ); } ); | aBtn.addEventListener( 'click', function () { grHomeView( 'author' ); } ); | ||
[ gBtn, aBtn ].forEach( function ( btn ) { | [ gBtn, aBtn ].forEach( function ( btn ) { btn.addEventListener( 'keydown', function ( e ) { if ( e.key === 'Enter' || e.key === ' ' ) btn.click(); } ); } ); | ||
var saved; try { saved = localStorage.getItem( 'gr_home_view' ); } catch ( e ) {} | |||
var saved; | |||
if ( saved === 'author' ) grHomeView( 'author' ); | if ( saved === 'author' ) grHomeView( 'author' ); | ||
} | } | ||
if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', initHomeToggle ); | if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', initHomeToggle ); | ||
else initHomeToggle(); | else initHomeToggle(); | ||
| Line 826: | Line 496: | ||
// ── 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 835: | Line 504: | ||
try { needle = decodeURIComponent( m[ 1 ] ); } catch ( e ) { return; } | try { needle = decodeURIComponent( m[ 1 ] ); } catch ( e ) { return; } | ||
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' ); | ||
if ( !content ) return; | if ( !content ) return; | ||
var snippet = needle.slice( 0, 40 ); | var snippet = needle.slice( 0, 40 ); | ||
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 848: | Line 514: | ||
var orig = spanEl.getAttribute( 'data-deva' ) || ''; | var orig = spanEl.getAttribute( 'data-deva' ) || ''; | ||
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 ) ); | ||
var mark = document.createElement( 'mark' ); | var mark = document.createElement( 'mark' ); | ||
mark.className | mark.className = 'gr-ullekha-highlight'; | ||
mark.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | mark.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | ||
mark.textContent | mark.textContent = hlText; | ||
var parent = spanEl.parentNode; | var parent = spanEl.parentNode; | ||
if ( !parent ) continue; | if ( !parent ) continue; | ||
var before = document.createTextNode( orig.slice( 0, idx ) ); | var before = document.createTextNode( orig.slice( 0, idx ) ); | ||
var after = document.createTextNode( orig.slice( idx + hlText.length ) ); | var after = document.createTextNode( orig.slice( idx + hlText.length ) ); | ||
parent.insertBefore( before, spanEl ); | parent.insertBefore( before, spanEl ); parent.insertBefore( mark, spanEl ); parent.insertBefore( after, spanEl ); parent.removeChild( spanEl ); | ||
setTimeout( function () { mark.scrollIntoView( { behavior: 'smooth', block: 'center' } ); }, 100 ); | |||
setTimeout( function () { | |||
found = true; | found = true; | ||
} | } | ||
if ( !found ) { | if ( !found ) { | ||
var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT ); | ||
| Line 878: | Line 534: | ||
var txt = node.textContent || ''; | var txt = node.textContent || ''; | ||
if ( txt.indexOf( snippet ) === -1 ) continue; | if ( txt.indexOf( snippet ) === -1 ) continue; | ||
var idx2 | var idx2 = txt.indexOf( snippet ); | ||
var mark2 | var mark2 = document.createElement( 'mark' ); | ||
mark2.className | mark2.className = 'gr-ullekha-highlight'; | ||
mark2.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | mark2.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;'; | ||
mark2.textContent | mark2.textContent = txt.slice( idx2, Math.min( idx2 + needle.length, txt.length ) ); | ||
var p = node.parentNode; | var p = node.parentNode; | ||
p.insertBefore( document.createTextNode( txt.slice( 0, idx2 ) ), node ); | p.insertBefore( document.createTextNode( txt.slice( 0, idx2 ) ), node ); | ||
| Line 888: | Line 544: | ||
p.insertBefore( document.createTextNode( txt.slice( idx2 + mark2.textContent.length ) ), node ); | p.insertBefore( document.createTextNode( txt.slice( idx2 + mark2.textContent.length ) ), node ); | ||
p.removeChild( node ); | p.removeChild( node ); | ||
setTimeout( function () { | setTimeout( function () { mark2.scrollIntoView( { behavior: 'smooth', block: 'center' } ); }, 100 ); | ||
found = true; | found = true; | ||
} | } | ||
} | } | ||
} | } | ||
doHighlight(); | doHighlight(); | ||
} | } | ||
function wireUllekhaLinks() { | function wireUllekhaLinks() { | ||
document.querySelectorAll( '.gr-ullekha-ref-link' ).forEach( function ( wrap ) { | document.querySelectorAll( '.gr-ullekha-ref-link' ).forEach( function ( wrap ) { | ||
| Line 905: | Line 557: | ||
var a = wrap.querySelector( 'a' ); | var a = wrap.querySelector( 'a' ); | ||
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 ); | ||
a.href = base + ( hl ? '?hlUllekha=' + encoded : '' ) | a.href = base + ( hl ? '?hlUllekha=' + encoded : '' ) + ( anchor ? '#' + anchor : '' ); | ||
} ); | } ); | ||
} | } | ||
if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', function () { highlightOnArrival(); wireUllekhaLinks(); } ); } | |||
else { highlightOnArrival(); wireUllekhaLinks(); } | |||
}() ); | |||
/* ── Search result highlight ──────────────────────────────────── */ | /* ── Search result highlight ──────────────────────────────────── */ | ||
/* Replace the ENTIRE search highlight IIFE in MediaWiki:Common.js | /* Replace the ENTIRE search highlight IIFE in MediaWiki:Common.js | ||
* (from | * (from "( function () {" before "function storeQueryForLink" | ||
* to its closing "}() );" ) | * to its closing "}() );" ) with this block. | ||
* | * | ||
* | * Changes vs previous version: | ||
* | * - storeQueryForLink: also stores wgPageName as title fallback | ||
* | * - applyHighlight: path check uses both pathname AND title fallback | ||
* | * - sessionStorage key cleared AFTER highlight runs, not before | ||
* | * - wrapMatches: unchanged from original working version | ||
* | * - showDismissBar mobile: full-width terracotta bar (not pill) | ||
*/ | */ | ||
( function () { | ( function () { | ||
/* Called by readerToolbar.js before navigating to a result page */ | |||
function storeQueryForLink( url, query ) { | function storeQueryForLink( url, query ) { | ||
try { | try { | ||
| Line 945: | Line 587: | ||
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) {} | ||
| Line 959: | Line 599: | ||
if ( !stored || !stored.query ) return; | if ( !stored || !stored.query ) return; | ||
var currentPath = window.location.pathname; | |||
var storedPath = stored.pathname || ''; | |||
var currentPath | |||
var storedPath | |||
function normPath(p) { | function normPath(p) { | ||
return decodeURIComponent(p).replace(/\/+$/, '').replace(/_/g, ' ' | return decodeURIComponent(p).replace(/\/+$/, '').replace(/_/g, ' '); | ||
} | } | ||
/* Primary: pathname match. Fallback: stored path's last segment matches | |||
* wgPageName (handles /index.php?title= vs short-URL discrepancy) */ | |||
var pathMatch = storedPath && normPath(storedPath) === normPath(currentPath); | var pathMatch = storedPath && normPath(storedPath) === normPath(currentPath); | ||
var pageTitle = (window.mw && mw.config && mw.config.get('wgPageName') || '').replace(/_/g,' '); | |||
var storedPage = normPath(storedPath).replace(/^\//, ''); | |||
var | var titleMatch = storedPage && pageTitle && pageTitle.toLowerCase() === storedPage.toLowerCase(); | ||
var | |||
var titleMatch | |||
if ( storedPath && !pathMatch && !titleMatch ) { | if ( storedPath && !pathMatch && !titleMatch ) { | ||
try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | ||
return; | return; | ||
| Line 989: | Line 621: | ||
if ( !query ) return; | if ( !query ) return; | ||
/* | /* Remove key now — committed to running on this page */ | ||
try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {} | |||
/* Retry until .mw-parser-output is present (Minerva lazy-loads sections) */ | |||
var attempts = 0; | var attempts = 0; | ||
var | var delays = [ 0, 200, 500, 1000, 2000 ]; | ||
delays.forEach( function(ms) { | |||
function | setTimeout( function() { | ||
if ( document.querySelector( '.gr-search-hl' ) ) return; /* already done */ | |||
highlightText( query ); | |||
}, ms ); | |||
} ); | |||
} | |||
} | } | ||
| Line 1,023: | Line 642: | ||
if ( !raw ) return; | if ( !raw ) return; | ||
var patterns = []; | |||
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,034: | Line 653: | ||
try { re = new RegExp( '(' + patterns[pi] + ')', 'gi' ); } | try { re = new RegExp( '(' + patterns[pi] + ')', 'gi' ); } | ||
catch(e) { continue; } | catch(e) { continue; } | ||
var count = wrapMatches( content, re ); | var count = wrapMatches( content, re ); | ||
if ( count > 0 ) { matched = true; break; } | if ( count > 0 ) { matched = true; break; } | ||
| Line 1,042: | Line 662: | ||
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.classList.add( 'gr-search-hl-pulse' ); | |||
setTimeout( function() { | setTimeout( function() { | ||
first.classList.remove( 'gr-search-hl-pulse' ); | |||
}, 2000 ); | |||
} | } | ||
| Line 1,059: | Line 676: | ||
} | } | ||
/* Original working wrapMatches — unchanged */ | |||
function wrapMatches( root, re ) { | function wrapMatches( root, re ) { | ||
var count = 0; | var count = 0; | ||
| Line 1,069: | Line 687: | ||
if ( tag === 'SCRIPT' || tag === 'STYLE' || tag === 'NOSCRIPT' ) return NodeFilter.FILTER_REJECT; | if ( tag === 'SCRIPT' || tag === 'STYLE' || tag === 'NOSCRIPT' ) return NodeFilter.FILTER_REJECT; | ||
if ( p.classList.contains( 'gr-search-hl' ) ) return NodeFilter.FILTER_REJECT; | if ( p.classList.contains( 'gr-search-hl' ) ) return NodeFilter.FILTER_REJECT; | ||
return NodeFilter.FILTER_ACCEPT; | return NodeFilter.FILTER_ACCEPT; | ||
} | } | ||
| Line 1,102: | Line 718: | ||
frag.appendChild( document.createTextNode( val.slice( last ) ) ); | frag.appendChild( document.createTextNode( val.slice( last ) ) ); | ||
} | } | ||
textNode.parentNode.replaceChild( frag, textNode ); | |||
} ); | } ); | ||
| Line 1,111: | Line 725: | ||
function showDismissBar( query ) { | function showDismissBar( query ) { | ||
var existing = document.getElementById( 'gr-hl-bar' ); | var existing = document.getElementById( 'gr-hl-bar' ); | ||
if ( existing ) existing.remove(); | if ( existing ) existing.remove(); | ||
var isMob = window.innerWidth < 768 || | var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' ); | ||
var bar = document.createElement( 'div' ); | var bar = document.createElement( 'div' ); | ||
bar.id = 'gr-hl-bar'; | bar.id = 'gr-hl-bar'; | ||
var count = document.querySelectorAll( '.gr-search-hl' ).length; | var count = document.querySelectorAll( '.gr-search-hl' ).length; | ||
if ( isMob ) { | if ( isMob ) { | ||
bar.style.cssText = [ | bar.style.cssText = [ | ||
'position:fixed', 'bottom:0', 'left:0', 'right:0', | 'position:fixed', 'bottom:0', 'left:0', 'right:0', | ||
| Line 1,137: | Line 746: | ||
].join(';'); | ].join(';'); | ||
var | var mbs = 'flex:1;display:flex;flex-direction:column;align-items:center;' + | ||
'justify-content:center;background:none;border:none;color:#fff;cursor:pointer;' + | 'justify-content:center;background:none;border:none;color:#fff;cursor:pointer;' + | ||
'padding:6px 4px;font-family:system-ui,sans-serif;font-size:11px;font-weight:500;' + | 'padding:6px 4px;font-family:system-ui,sans-serif;font-size:11px;font-weight:500;' + | ||
| Line 1,143: | Line 752: | ||
bar.innerHTML = | bar.innerHTML = | ||
'<button id="gr-hl-prev" style="' + | '<button id="gr-hl-prev" style="' + mbs + '">' + | ||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>' + | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>' + | ||
'<span>Prev</span> | '<span>Prev</span></button>' + | ||
'<button id="gr-hl-next" style="' + mbs + '">' + | |||
'<button id="gr-hl-next" style="' + | |||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>' + | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>' + | ||
'<span>Next</span> | '<span>Next</span></button>' + | ||
'<button id="gr-hl-results" style="' + mbs + 'flex:1.6;border-left:1px solid rgba(255,255,255,0.2);border-right:1px solid rgba(255,255,255,0.2);">' + | |||
'<button id="gr-hl-results" style="' + | |||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="22" y2="22"/></svg>' + | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="22" y2="22"/></svg>' + | ||
'<span>' + count + ' match' + ( count === 1 ? '' : 'es' ) + '</span> | '<span>' + count + ' match' + ( count === 1 ? '' : 'es' ) + '</span></button>' + | ||
'<button id="gr-hl-dismiss" style="' + mbs + '">' + | |||
'<button id="gr-hl-dismiss" style="' + | |||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>' + | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>' + | ||
'<span>Close</span> | '<span>Close</span></button>'; | ||
} else { | } else { | ||
bar.style.cssText = [ | bar.style.cssText = [ | ||
'position:fixed', 'bottom:0', 'left:0', 'right:0', 'z-index:10200', | 'position:fixed', 'bottom:0', 'left:0', 'right:0', 'z-index:10200', | ||
| Line 1,179: | Line 782: | ||
bar.appendChild( nav ); | bar.appendChild( nav ); | ||
var | var db = document.createElement( 'button' ); | ||
db.id = 'gr-hl-dismiss'; db.textContent = '✕ Close'; | |||
db.style.cssText = 'background:rgba(255,255,255,0.15);border:none;color:#fff;padding:4px 12px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;'; | |||
bar.appendChild( db ); | |||
bar.appendChild( | |||
} | } | ||
document.body.appendChild( bar ); | document.body.appendChild( bar ); | ||
var hlEls = Array.from( document.querySelectorAll( '.gr-search-hl' ) ); | |||
var hlEls | |||
var current = 0; | var current = 0; | ||
| Line 1,195: | Line 796: | ||
hlEls.forEach( function(el) { el.classList.remove( 'gr-search-hl-current' ); } ); | hlEls.forEach( function(el) { el.classList.remove( 'gr-search-hl-current' ); } ); | ||
current = ( ( idx % hlEls.length ) + hlEls.length ) % hlEls.length; | current = ( ( idx % hlEls.length ) + hlEls.length ) % hlEls.length; | ||
hlEls[ current ].classList.add( 'gr-search-hl-current' ); | |||
hlEls[ current ].scrollIntoView({ behavior: 'smooth', block: 'center' }); | |||
} | } | ||
function dismiss() { clearHighlights(); bar.remove(); } | |||
if ( | var nb = document.getElementById( 'gr-hl-next' ); | ||
if ( | var pb = document.getElementById( 'gr-hl-prev' ); | ||
if ( | var rb = document.getElementById( 'gr-hl-results' ); | ||
if ( | var db2 = document.getElementById( 'gr-hl-dismiss' ); | ||
bar.remove(); | if ( nb ) nb.onclick = function() { goTo( current + 1 ); }; | ||
if ( pb ) pb.onclick = function() { goTo( current - 1 ); }; | |||
if ( db2 ) db2.onclick = dismiss; | |||
if ( rb ) rb.onclick = function() { | |||
bar.remove(); clearHighlights(); | |||
if ( window.showSearchDialog ) window.showSearchDialog( query ); | if ( window.showSearchDialog ) window.showSearchDialog( query ); | ||
}; | }; | ||
| Line 1,222: | Line 817: | ||
function clearHighlights() { | function clearHighlights() { | ||
document.querySelectorAll( '.gr-search-hl' ).forEach( function( span ) { | document.querySelectorAll( '.gr-search-hl' ).forEach( function( span ) { | ||
var | var p = span.parentNode; if ( !p ) return; | ||
while ( span.firstChild ) p.insertBefore( span.firstChild, span ); | |||
while ( span.firstChild ) | p.removeChild( span ); | ||
} ); | } ); | ||
} | } | ||
| Line 1,238: | Line 832: | ||
s.id = 'gr-hl-css'; | s.id = 'gr-hl-css'; | ||
s.textContent = [ | s.textContent = [ | ||
'.gr-search-hl{background:#fff176;color:#1a1a1a;border-radius:2px;', | '.gr-search-hl{', | ||
' | ' background:#fff176;color:#1a1a1a;', | ||
'.gr-search-hl-current{background:#ffb300!important;', | ' border-radius:2px;padding:0 1px;', | ||
'box-shadow:0 0 0 2px #b5451b!important;}', | ' box-shadow:0 0 0 1px rgba(181,69,27,0.25);', | ||
'}', | |||
'.gr-search-hl-current{', | |||
' background:#ffb300!important;', | |||
' box-shadow:0 0 0 2px #b5451b!important;', | |||
'}', | |||
'@keyframes gr-hl-pulse{', | '@keyframes gr-hl-pulse{', | ||
'0%{background:#ffb300;}50%{background:#fff176;}100%{background:#fff176;}}', | ' 0%{background:#ffb300;}', | ||
' 50%{background:#fff176;}', | |||
' 100%{background:#fff176;}', | |||
'}', | |||
'.gr-search-hl-pulse{animation:gr-hl-pulse 1.2s ease 2;}', | '.gr-search-hl-pulse{animation:gr-hl-pulse 1.2s ease 2;}', | ||
].join(''); | ].join(''); | ||
| Line 1,250: | Line 852: | ||
injectHighlightCSS(); | injectHighlightCSS(); | ||
if ( document.readyState === 'loading' ) { | if ( document.readyState === 'loading' ) { | ||
document.addEventListener( 'DOMContentLoaded', | document.addEventListener( 'DOMContentLoaded', applyHighlight ); | ||
} else { | } else { | ||
applyHighlight(); | |||
} | } | ||
if ( window.mw ) { | if ( window.mw ) { | ||
mw.hook( 'wikipage.content' ).add( function() { | mw.hook( 'wikipage.content' ).add( function() { | ||
| Line 1,273: | Line 868: | ||
}() ); | }() ); | ||
/* ═══════════════════════════════════════════════════════════════ | /* ═══════════════════════════════════════════════════════════════ | ||
Mobile addon — | Mobile addon — only runs on Minerva (mobile) skin | ||
═══════════════════════════════════════════════════════════════ */ | ═══════════════════════════════════════════════════════════════ */ | ||
( function () { | ( function () { | ||
if ( !document.body.classList.contains( 'skin-minerva' ) ) return; | if ( !document.body.classList.contains( 'skin-minerva' ) ) return; | ||
function injectCSS() { | function injectCSS() { | ||
if ( document.getElementById( 'gr-mob-css' ) ) return; | if ( document.getElementById( 'gr-mob-css' ) ) return; | ||
| Line 1,291: | Line 885: | ||
'.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;}' + | ||
'.branding-box a::before{content:"";display:block;width:30px;height:30px;flex-shrink:0;background:url("/favicon.png") center/contain no-repeat;margin-right:8px;}' + | |||
'.branding-box a::before{content:"";display:block;width:30px;height:30px;flex-shrink:0; | '.branding-box a span{color:#fff!important;font-size:16px!important;font-weight:700!important;font-family:system-ui,sans-serif!important;line-height:1.2!important;flex:1 1 auto!important;min-width:0!important;}' + | ||
'.branding-box a span{color:#fff!important;font-size:16px!important;font-weight:700!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;}' + | ||
'#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,#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-10{display:block!important;visibility:visible!important;}' + | ||
'.collapsible-block{display:block!important;}' + | '.collapsible-block{display:block!important;}' + | ||
'.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;}' + | ||
'.gr-home-card{width:100%!important;max-width:100%!important;min-width:unset!important;box-sizing:border-box!important;flex:none!important;}' + | |||
'.gr-home-card{width:100%!important;max-width:100%!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;}' + | ||
| Line 1,323: | Line 905: | ||
'.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;background:#fff!important;z-index:10400!important;box-shadow:4px 0 28px rgba(0,0,0,0.22)!important;overflow-y:auto!important;padding:0 0 40px!important;transform:translateX(-110%)!important;transition:transform 0.26s cubic-bezier(0.4,0,0.2,1)!important;display:block!important;}' + | ||
'.gr-mob-toc-panel.open{transform:translateX(0)!important;}' + | '.gr-mob-toc-panel.open{transform:translateX(0)!important;}' + | ||
'.gr-mob-toc-backdrop{display:none!important;position:fixed!important;inset:0!important; | '.gr-mob-toc-backdrop{display:none!important;position:fixed!important;inset:0!important;background:rgba(0,0,0,0.4)!important;z-index:10399!important;}' + | ||
'.gr-mob-toc-backdrop.open{display:block!important;}' + | '.gr-mob-toc-backdrop.open{display:block!important;}' + | ||
'.gr-mob-toc-header{position:sticky!important;top:0!important;background:#fff!important; | '.gr-mob-toc-header{position:sticky!important;top:0!important;background:#fff!important;display:flex!important;align-items:center!important;justify-content:space-between!important;padding:16px 16px 12px!important;border-bottom:1px solid #f0ebe6!important;z-index:1!important;}' + | ||
'.gr-mob-toc-title{font-size:13px!important;font-weight:700!important;text-transform:uppercase!important;letter-spacing:0.08em!important;color:#b5451b!important;font-family:system-ui,sans-serif!important;}' + | |||
'.gr-mob-toc-close{background:none!important;border:none!important;font-size:22px!important;color:#999!important;cursor:pointer!important;padding:4px 8px!important;}' + | |||
'.gr-mob-toc-title{font-size:13px!important;font-weight:700!important;text-transform:uppercase!important; | |||
'.gr-mob-toc-close{background:none!important;border:none!important; | |||
'.gr-mob-toc-body{padding:12px 16px!important;}' + | '.gr-mob-toc-body{padding:12px 16px!important;}' + | ||
'.gr-mob-toc-body a{display:block!important;font-size:16px!important;line-height:1.6!important; | '.gr-mob-toc-body a{display:block!important;font-size:16px!important;line-height:1.6!important;color:#2c1810!important;text-decoration:none!important;padding:8px 0!important;border-bottom:1px solid #f5f0ed!important;}'; | ||
document.head.appendChild( s ); | document.head.appendChild( s ); | ||
} | } | ||
function expandSections() { | function expandSections() { | ||
document.querySelectorAll( '[class*="mf-section-"], .collapsible-block' ) | document.querySelectorAll( '[class*="mf-section-"], .collapsible-block' ).forEach( function ( el ) { | ||
el.removeAttribute( 'hidden' ); | |||
el.style.setProperty( 'display', 'block', 'important' ); | |||
el.style.setProperty( 'visibility', 'visible', 'important' ); | |||
el.removeAttribute( 'aria-hidden' ); | |||
} ); | |||
document.querySelectorAll( '.section-heading, .collapsible-heading' ).forEach( function ( el ) { | |||
document.querySelectorAll( '.section-heading, .collapsible-heading' ) | el.setAttribute( 'aria-expanded', 'true' ); | ||
el.style.setProperty( 'pointer-events', 'none', 'important' ); | |||
} ); | |||
} | } | ||
| Line 1,366: | Line 933: | ||
var t = null; | var t = null; | ||
var obs = new MutationObserver( function ( ms ) { | var obs = new MutationObserver( function ( ms ) { | ||
if ( ms.some( function(m){ return m.attributeName === 'hidden'; } ) ) { | if ( ms.some( function(m){ return m.attributeName === 'hidden'; } ) ) { clearTimeout(t); t = setTimeout( expandSections, 30 ); } | ||
} ); | } ); | ||
var root = document.querySelector( '#mw-content-text' ) || document.body; | var root = document.querySelector( '#mw-content-text' ) || document.body; | ||
| Line 1,374: | Line 939: | ||
} | } | ||
function watchBodyPadding() { | function watchBodyPadding() { | ||
new MutationObserver( function () { | new MutationObserver( function () { | ||
| Line 1,383: | Line 947: | ||
} | } | ||
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; | ||
var wrap = document.createElement( 'div' ); | var wrap = document.createElement( 'div' ); | ||
wrap.id = 'gr-mob-menu-items'; | wrap.id = 'gr-mob-menu-items'; | ||
wrap.style.cssText = 'width:100%;background:#fff;margin-top:8px;'; | 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;'; | |||
var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px; | |||
function makeItem( href, emoji, label ) { | function makeItem( href, emoji, label ) { | ||
var a = document.createElement( 'a' ); | var a = document.createElement( 'a' ); a.href = href; a.style.cssText = itemStyle; | ||
a.innerHTML = '<span>' + label + '</span>'; return a; | |||
a.innerHTML = | |||
} | } | ||
wrap.appendChild( makeItem( '/Main_Page', '', 'Home' ) ); | wrap.appendChild( makeItem( '/Main_Page', '', 'Home' ) ); | ||
wrap.appendChild( makeItem( '/My_wiki:Help', '', 'Help' ) ); | wrap.appendChild( makeItem( '/My_wiki:Help', '', 'Help' ) ); | ||
wrap.appendChild( makeItem( '/My_wiki:About', '', 'About' ) ); | wrap.appendChild( makeItem( '/My_wiki:About', '', 'About' ) ); | ||
var userName = window.mw ? mw.config.get( 'wgUserName' ) : null; | var userName = window.mw ? mw.config.get( 'wgUserName' ) : null; | ||
if ( userName ) { | if ( userName ) { | ||
var la = document.querySelector( 'a[href*="action=logout"]' ); | var la = document.querySelector( 'a[href*="action=logout"]' ); | ||
wrap.appendChild( makeItem( | wrap.appendChild( makeItem( la ? la.href : '/index.php?title=Special:UserLogout', '', 'Log out' ) ); | ||
} else { | } else { | ||
wrap.appendChild( makeItem( '/index.php?title=Special:UserLogin', '', 'Log in' ) ); | wrap.appendChild( makeItem( '/index.php?title=Special:UserLogin', '', 'Log in' ) ); | ||
} | } | ||
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 ); pageLeft.style.removeProperty( 'display' ); pageLeft.appendChild( wrap ); } | ||
else navDrawer.appendChild( wrap ); | |||
document.querySelectorAll( '.mw-footer.minerva-footer,.footer-places,.footer-info,.minerva-footer-logo,#footer-places-about,#footer-places-disclaimers,#footer-places-privacy' ).forEach( function(el) { el.style.setProperty('display','none','important'); } ); | |||
document.querySelectorAll( | |||
} | } | ||
var _tocDone = false; | var _tocDone = false; | ||
function initToc() { | function initToc() { | ||
if ( _tocDone ) return; | if ( _tocDone ) return; | ||
var tocList = document.querySelector( '.vector-toc-contents, .vector-toc .vector-toc-list' ); | var tocList = document.querySelector( '.vector-toc-contents, .vector-toc .vector-toc-list' ); | ||
if ( !tocList | if ( !tocList || !tocList.querySelector( 'li' ) ) return; | ||
_tocDone = true; | _tocDone = true; | ||
var bd = document.createElement( 'div' ); bd.className = 'gr-mob-toc-backdrop'; document.body.appendChild( bd ); | |||
var bd = document.createElement( 'div' ); | var panel = document.createElement( 'div' ); panel.className = 'gr-mob-toc-panel'; | ||
var hdr = document.createElement( 'div' ); hdr.className = 'gr-mob-toc-header'; | |||
var ttl = document.createElement( 'div' ); ttl.className = 'gr-mob-toc-title'; ttl.textContent = 'विषयसूची'; | |||
var cls = document.createElement( 'button' ); cls.className = 'gr-mob-toc-close'; cls.textContent = '✕'; | |||
var panel = document.createElement( 'div' ); | hdr.appendChild( ttl ); hdr.appendChild( cls ); panel.appendChild( hdr ); | ||
var body = document.createElement( 'div' ); body.className = 'gr-mob-toc-body'; | |||
body.appendChild( tocList.cloneNode( true ) ); panel.appendChild( body ); document.body.appendChild( panel ); | |||
var hdr = document.createElement( 'div' ); | var btn = document.createElement( 'button' ); btn.id = 'gr-mob-toc-btn'; | ||
var ttl = document.createElement( 'div' ); | |||
var cls = document.createElement( 'button' ); | |||
hdr.appendChild( ttl ); hdr.appendChild( cls ); | |||
var body = document.createElement( 'div' ); | |||
body.appendChild( tocList.cloneNode( true ) ); | |||
var btn = document.createElement( 'button' ); | |||
btn.innerHTML = '☰ Contents'; | btn.innerHTML = '☰ Contents'; | ||
btn.style.cssText = 'position:fixed;bottom:148px;left:16px;z-index:9100; | btn.style.cssText = 'position:fixed;bottom:148px;left:16px;z-index:9100;background:#fff;border:1.5px solid #b5451b;border-radius:24px;padding:10px 16px;font-size:15px;font-family:system-ui,sans-serif;color:#b5451b;font-weight:600;box-shadow:0 3px 14px rgba(0,0,0,0.15);cursor:pointer;'; | ||
document.body.appendChild( btn ); | document.body.appendChild( btn ); | ||
function open() { panel.classList.add('open'); bd.classList.add('open'); document.body.style.overflow='hidden'; } | function open() { panel.classList.add('open'); bd.classList.add('open'); document.body.style.overflow='hidden'; } | ||
function close() { panel.classList.remove('open'); bd.classList.remove('open'); document.body.style.overflow=''; } | function close() { panel.classList.remove('open'); bd.classList.remove('open'); document.body.style.overflow=''; } | ||
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; }); | ||
} | } | ||
function injectMoolaUllekhaLinks() { | function injectMoolaUllekhaLinks() { | ||
if ( document.getElementById( 'gr-mob-doc-nav' ) ) return; | if ( document.getElementById( 'gr-mob-doc-nav' ) ) return; | ||
var pageName = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | var pageName = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || ''; | ||
if ( pageName === 'Main_Page' || !pageName ) return; | if ( pageName === 'Main_Page' || !pageName ) return; | ||
function wikiUrl( slug ) { | function wikiUrl( slug ) { | ||
if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug ); | if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug ); | ||
| Line 1,497: | Line 1,008: | ||
return ap.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); | return ap.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); | ||
} | } | ||
var teekaPage = document.querySelector( '.gr-teeka-page' ); | |||
var teekaPage | var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || pageName.split('/')[0] ) : pageName.split('/')[0]; | ||
var primarySlug | var docTitleEl = document.querySelector( '.gr-doc-title' ); | ||
var docTitleEl | |||
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 showMoolam = !!teekaPage || hasMoolaPage; | var showMoolam = !!teekaPage || hasMoolaPage; | ||
var showUllekha = hasUllekhaPage || !!teekaPage; | var showUllekha = hasUllekhaPage || !!teekaPage; | ||
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.style.cssText = 'display:flex;gap:10px;padding:10px 16px 8px;background:#fdf8f5;border-bottom:1px solid #f0e0d6;font-family:system-ui,sans-serif;'; | ||
nav.style.cssText = 'display:flex;gap:10px;padding:10px 16px 8px; | |||
function makeLink( href, label ) { | function makeLink( href, label ) { | ||
var a = document.createElement( 'a' ); | 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;'; | |||
a.style.cssText = 'display:inline-flex;align-items:center;padding:5px 16px; | |||
return a; | 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' ), 'उल्लेख' ) ); | ||
var h1 = document.getElementById( 'firstHeading' ) || document.querySelector( '.page-heading, h1.firstHeading, .mw-first-heading' ); | |||
if ( h1 && h1.parentNode ) h1.parentNode.insertBefore( nav, h1.nextSibling ); | |||
var h1 = document.getElementById( 'firstHeading' ) || | else { var ct = document.getElementById( 'mw-content-text' ); if ( ct ) ct.insertBefore( nav, ct.firstChild ); } | ||
if ( h1 && h1.parentNode ) | |||
} | } | ||
injectCSS(); | injectCSS(); | ||
watchBodyPadding(); | watchBodyPadding(); | ||
| Line 1,552: | Line 1,043: | ||
} | } | ||
if ( document.readyState === 'loading' ) { | if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', boot ); } | ||
else { boot(); } | |||
if ( window.mw ) { | if ( window.mw ) { | ||
mw.hook( 'wikipage.content' ).add(function() { | mw.hook( 'wikipage.content' ).add(function() { | ||
setTimeout(function(){ | setTimeout(function(){ expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); }, 300); | ||
}); | }); | ||
} | } | ||
}() ); | }() ); | ||
( function () { | ( function () { | ||
| Line 1,578: | Line 1,062: | ||
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) {} } | ||
} ); | } ); | ||
}, 0 ); | }, 0 ); | ||
| Line 1,599: | Line 1,081: | ||
var bar = document.getElementById( 'gr-static-bar' ); | var bar = document.getElementById( 'gr-static-bar' ); | ||
if ( !bar ) return; | if ( !bar ) return; | ||
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 > *:first-child' ); | ||
[ homeEl, toggleEl, firstChild ].forEach( function ( el ) { if ( el ) el.style.scrollMarginTop = ( barBottom + 4 ) + 'px'; } ); | |||
[ homeEl, toggleEl, firstChild ].forEach( function ( el ) { | |||
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 && toggleEl ) { | ||
var toggleRect = toggleEl.getBoundingClientRect(); | |||
if ( toggleRect.top < barBottom ) { | |||
var currentPT = parseInt( window.getComputedStyle( document.body ).paddingTop, 10 ) || 0; | |||
document.body.style.paddingTop = ( currentPT + ( barBottom - toggleRect.top ) + 4 ) + 'px'; | |||
} | } | ||
} | } | ||
| Line 1,631: | Line 1,101: | ||
$( function () { | $( function () { | ||
var $toggle | var $toggle = $( '#gr-home-toggle' ), $viewG = $( '#gr-view-grantha' ), $viewA = $( '#gr-view-author' ); | ||
var $btnG = $( '#gr-toggle-grantha' ), $btnA = $( '#gr-toggle-author' ); | |||
var $btnG | |||
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 ); | ||
function showView( which ) { | function showView( which ) { | ||
if ( which === 'grantha' ) { | if ( which === 'grantha' ) { $viewG.show(); $viewA.hide(); $btnG.addClass( 'gr-toggle-active' ); $btnA.removeClass( 'gr-toggle-active' ); } | ||
else { $viewA.show(); $viewG.hide(); $btnA.addClass( 'gr-toggle-active' ); $btnG.removeClass( 'gr-toggle-active' ); } | |||
try { localStorage.setItem( 'grantha_home_tab', which ); } catch(e){} | try { localStorage.setItem( 'grantha_home_tab', which ); } catch(e){} | ||
} | } | ||
$btnG.on( 'click keydown', function(e){ if ( e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ' ) return; showView( 'grantha' ); }); | |||
$btnG.on( 'click keydown', function(e){ | $btnA.on( 'click keydown', function(e){ if ( e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ' ) return; showView( 'author' ); }); | ||
try { var saved = localStorage.getItem( 'grantha_home_tab' ); if ( saved === 'author' ) showView( 'author' ); else showView( 'grantha' ); } catch(e) { showView( 'grantha' ); } | |||
$btnA.on( 'click keydown', function(e){ | |||
try { | |||
} ); | } ); | ||
}() ); | }() ); | ||