MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 567: Line 567:


/* ── Search result highlight ──────────────────────────────────── */
/* ── Search result highlight ──────────────────────────────────── */
/* Replace the ENTIRE search highlight IIFE in MediaWiki:Common.js
/* EXACT REPLACEMENT for the search highlight IIFE in MediaWiki:Common.js.
  * (from "( function () {" before "function storeQueryForLink"
  * Only changes from the original working version:
*  to its closing "}() );" ) with this block.
  * - Mobile bar: full-width terracotta bottom bar instead of floating pill
*
  * - showDismissBar: guard added (if !count return) to prevent empty bar
* Changes vs previous version:
  * Everything else (storeQueryForLink, applyHighlight, wrapMatches) is
  * - storeQueryForLink: also stores wgPageName as title fallback
  * identical to the version that was working.
  * - 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 602: Line 597:
     var storedPath  = stored.pathname || '';
     var storedPath  = stored.pathname || '';


     function normPath(p) {
     function normPath(p) { return decodeURIComponent(p).replace(/\/+$/, ''); }
      return decodeURIComponent(p).replace(/\/+$/, '').replace(/_/g, ' ');
     if ( storedPath && normPath(storedPath) !== normPath(currentPath) ) {
    }
 
     /* 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 pageTitle  = (window.mw && mw.config && mw.config.get('wgPageName') || '').replace(/_/g,' ');
    var storedPage = normPath(storedPath).replace(/^\//, '');
    var titleMatch = storedPage && pageTitle && pageTitle.toLowerCase() === storedPage.toLowerCase();
 
    if ( storedPath && !pathMatch && !titleMatch ) {
       try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}
       try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}
       return;
       return;
Line 621: Line 606:
     if ( !query ) return;
     if ( !query ) return;


    /* Remove key now — committed to running on this page */
     try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}
     try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}


    /* Retry until .mw-parser-output is present (Minerva lazy-loads sections) */
     var delays = [ 0, 200, 600 ];
    var attempts = 0;
     var delays = [ 0, 200, 500, 1000, 2000 ];
     delays.forEach( function(ms) {
     delays.forEach( function(ms) {
       setTimeout( function() {
       setTimeout( function() {
         if ( document.querySelector( '.gr-search-hl' ) ) return; /* already done */
         if ( document.querySelector( '.gr-search-hl' ) ) return;
         highlightText( query );
         highlightText( query );
       }, ms );
       }, ms );
Line 653: Line 635:
       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 664: Line 645:
       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() { first.classList.remove( 'gr-search-hl-pulse' ); }, 2000 );
        first.classList.remove( 'gr-search-hl-pulse' );
      }, 2000 );
     }
     }


Line 676: Line 655:
   }
   }


  /* Original working wrapMatches — unchanged */
   function wrapMatches( root, re ) {
   function wrapMatches( root, re ) {
     var count = 0;
     var count = 0;
Line 727: Line 705:
     var existing = document.getElementById( 'gr-hl-bar' );
     var existing = document.getElementById( 'gr-hl-bar' );
     if ( existing ) existing.remove();
     if ( existing ) existing.remove();
    var count = document.querySelectorAll( '.gr-search-hl' ).length;
    if ( !count ) return;


     var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' );
     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;


     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',
         'z-index:10200',
         'z-index:10200', 'background:#b5451b', 'color:#fff',
        'background:#b5451b', 'color:#fff',
         'padding:0', 'display:flex', 'align-items:stretch',
         'padding:0',
        'display:flex', 'align-items:stretch',
         'font-family:system-ui,sans-serif',
         'font-family:system-ui,sans-serif',
         'box-shadow:0 -2px 12px rgba(0,0,0,0.25)',
         'box-shadow:0 -2px 12px rgba(0,0,0,0.25)', 'height:56px'
        'height:56px'
       ].join(';');
       ].join(';');


Line 760: Line 736:
         '<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="' + mbs + 'flex:1.6;border-left:1px solid rgba(255,255,255,0.2);border-right:1px solid rgba(255,255,255,0.2);">' +
           '<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></button>' +
           '<span>' + count + ' match' + (count===1?'':'es') + '</span></button>' +
         '<button id="gr-hl-dismiss" style="' + mbs + '">' +
         '<button id="gr-hl-dismiss" 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"><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>' +
Line 832: Line 808:
     s.id = 'gr-hl-css';
     s.id = 'gr-hl-css';
     s.textContent = [
     s.textContent = [
       '.gr-search-hl{',
       '.gr-search-hl{background:#fff176;color:#1a1a1a;border-radius:2px;padding:0 1px;box-shadow:0 0 0 1px rgba(181,69,27,0.25);}',
      '  background:#fff176;color:#1a1a1a;',
       '.gr-search-hl-current{background:#ffb300!important;box-shadow:0 0 0 2px #b5451b!important;}',
      '  border-radius:2px;padding:0 1px;',
       '@keyframes gr-hl-pulse{0%{background:#ffb300;}50%{background:#fff176;}100%{background:#fff176;}}',
      '  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{',
      '  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 874: Line 839:
( 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 916: Line 880:
     document.head.appendChild( s );
     document.head.appendChild( s );
   }
   }
   function expandSections() {
   function expandSections() {
     document.querySelectorAll( '[class*="mf-section-"], .collapsible-block' ).forEach( function ( el ) {
     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' ); } );
      el.removeAttribute( 'hidden' );
     document.querySelectorAll( '.section-heading, .collapsible-heading' ).forEach( function ( el ) { el.setAttribute( 'aria-expanded', 'true' ); el.style.setProperty( 'pointer-events', 'none', 'important' ); } );
      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 ) {
      el.setAttribute( 'aria-expanded', 'true' );
      el.style.setProperty( 'pointer-events', 'none', 'important' );
    } );
   }
   }
   function watchSections() {
   function watchSections() {
     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'; } ) ) { clearTimeout(t); t = setTimeout( expandSections, 30 ); } } );
      if ( ms.some( function(m){ return m.attributeName === 'hidden'; } ) ) { clearTimeout(t); t = setTimeout( expandSections, 30 ); }
     obs.observe( document.querySelector( '#mw-content-text' ) || document.body, { subtree:true, attributes:true, attributeFilter:['hidden','aria-hidden'] } );
    } );
     var root = document.querySelector( '#mw-content-text' ) || document.body;
    obs.observe( root, { subtree:true, attributes:true, attributeFilter:['hidden','aria-hidden'] } );
   }
   }
   function watchBodyPadding() {
   function watchBodyPadding() {
     new MutationObserver( function () {
     new MutationObserver( function () { if ( document.body.style.paddingTop && document.body.style.paddingTop !== '0px' ) document.body.style.paddingTop = ''; } ).observe( document.body, { attributes:true, attributeFilter:['style'] } );
      if ( document.body.style.paddingTop && document.body.style.paddingTop !== '0px' ) {
        document.body.style.paddingTop = '';
      }
    } ).observe( document.body, { attributes:true, attributeFilter:['style'] } );
   }
   }
   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.style.cssText = 'width:100%;background:#fff;margin-top:8px;';
    wrap.id = 'gr-mob-menu-items';
    wrap.style.cssText = 'width:100%;background:#fff;margin-top:8px;';
     var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px;font-size:16px;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;border-bottom:1px solid #f0ebe6;background:#fff;';
     var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px;font-size:16px;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;border-bottom:1px solid #f0ebe6;background:#fff;';
     function makeItem( href, emoji, label ) {
     function makeItem( href, label ) { var a = document.createElement( 'a' ); a.href = href; a.style.cssText = itemStyle; a.innerHTML = '<span>' + label + '</span>'; return a; }
      var a = document.createElement( 'a' ); a.href = href; a.style.cssText = itemStyle;
     wrap.appendChild( makeItem( '/Main_Page', 'Home' ) );
      a.innerHTML = '<span>' + label + '</span>'; return a;
     wrap.appendChild( makeItem( '/My_wiki:Help', 'Help' ) );
    }
     wrap.appendChild( makeItem( '/My_wiki:About', 'About' ) );
     wrap.appendChild( makeItem( '/Main_Page', '', 'Home' ) );
     wrap.appendChild( makeItem( '/My_wiki:Help', '', 'Help' ) );
     wrap.appendChild( makeItem( '/My_wiki:About', '', 'About' ) );
     var userName = window.mw ? mw.config.get( 'wgUserName' ) : null;
     var userName = window.mw ? mw.config.get( 'wgUserName' ) : null;
     if ( userName ) {
     if ( userName ) { var la = document.querySelector( 'a[href*="action=logout"]' ); wrap.appendChild( makeItem( la ? la.href : '/index.php?title=Special:UserLogout', 'Log out' ) ); }
      var la = document.querySelector( 'a[href*="action=logout"]' );
     else wrap.appendChild( makeItem( '/index.php?title=Special:UserLogin', 'Log in' ) );
      wrap.appendChild( makeItem( la ? la.href : '/index.php?title=Special:UserLogout', '', 'Log out' ) );
     } else {
      wrap.appendChild( makeItem( '/index.php?title=Special:UserLogin', '', 'Log in' ) );
    }
     var pageLeft = document.getElementById( 'mw-mf-page-left' );
     var pageLeft = document.getElementById( 'mw-mf-page-left' );
     if ( pageLeft ) { while ( pageLeft.firstChild ) pageLeft.removeChild( pageLeft.firstChild ); pageLeft.style.removeProperty( 'display' ); pageLeft.appendChild( wrap ); }
     if ( pageLeft ) { while ( pageLeft.firstChild ) pageLeft.removeChild( pageLeft.firstChild ); pageLeft.style.removeProperty( 'display' ); pageLeft.appendChild( wrap ); }
     else navDrawer.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'); } );
   }
   }
   var _tocDone = false;
   var _tocDone = false;
   function initToc() {
   function initToc() {
Line 987: Line 921:
     var cls = document.createElement( 'button' ); cls.className = 'gr-mob-toc-close'; cls.textContent = '✕';
     var cls = document.createElement( 'button' ); cls.className = 'gr-mob-toc-close'; cls.textContent = '✕';
     hdr.appendChild( ttl ); hdr.appendChild( cls ); panel.appendChild( hdr );
     hdr.appendChild( ttl ); hdr.appendChild( cls ); panel.appendChild( hdr );
     var body = document.createElement( 'div' ); body.className = 'gr-mob-toc-body';
     var body = document.createElement( 'div' ); body.className = 'gr-mob-toc-body'; body.appendChild( tocList.cloneNode( true ) ); panel.appendChild( body ); document.body.appendChild( panel );
    body.appendChild( tocList.cloneNode( true ) ); panel.appendChild( body ); document.body.appendChild( panel );
     var btn = document.createElement( 'button' ); btn.id = 'gr-mob-toc-btn'; btn.innerHTML = '☰ &nbsp;Contents';
     var btn = document.createElement( 'button' ); btn.id = 'gr-mob-toc-btn';
    btn.innerHTML = '☰ &nbsp;Contents';
     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;';
     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 );
Line 998: Line 930:
     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 ); return ( ( window.mw && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1' ).replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); }
      if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug );
     var teekaPage = document.querySelector( '.gr-teeka-page' );
      var ap = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1';
     var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || pageName.split('/')[0] ) : pageName.split('/')[0];
      return ap.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) );
     var docTitleEl = document.querySelector( '.gr-doc-title' );
    }
     var hasMoolaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-moola' ) === '1';
     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 hasUllekhaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-ullekha' ) === '1';
     var showMoolam = !!teekaPage || hasMoolaPage;
     var showMoolam = !!teekaPage || hasMoolaPage, 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.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;';
     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 ) {
     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; }
      var a = document.createElement( 'a' ); a.href = href; a.textContent = label;
     if ( teekaPage ) nav.appendChild( makeLink( wikiUrl( primarySlug ), 'मूल' ) );
      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;';
     else if ( hasMoolaPage ) nav.appendChild( makeLink( wikiUrl( primarySlug + '/Moola' ), 'मूलम्' ) );
      return a;
     if ( showUllekha ) nav.appendChild( makeLink( wikiUrl( primarySlug + '/Ullekha' ), 'उल्लेख' ) );
    }
     if ( teekaPage )         nav.appendChild( makeLink( wikiUrl( primarySlug ),             'मूल' ) );
     else if ( hasMoolaPage ) nav.appendChild( makeLink( wikiUrl( primarySlug + '/Moola' ),   'मूलम्' ) );
     if ( showUllekha )       nav.appendChild( makeLink( wikiUrl( primarySlug + '/Ullekha' ), 'उल्लेख' ) );
     var h1 = document.getElementById( 'firstHeading' ) || document.querySelector( '.page-heading, h1.firstHeading, .mw-first-heading' );
     var h1 = document.getElementById( 'firstHeading' ) || document.querySelector( '.page-heading, h1.firstHeading, .mw-first-heading' );
     if ( h1 && h1.parentNode ) h1.parentNode.insertBefore( nav, h1.nextSibling );
     if ( h1 && h1.parentNode ) h1.parentNode.insertBefore( nav, h1.nextSibling );
     else { var ct = document.getElementById( 'mw-content-text' ); if ( ct ) ct.insertBefore( nav, ct.firstChild ); }
     else { var ct = document.getElementById( 'mw-content-text' ); if ( ct ) ct.insertBefore( nav, ct.firstChild ); }
   }
   }
 
   injectCSS(); watchBodyPadding();
   injectCSS();
   function boot() { expandSections(); watchSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); [100,400,900,1800].forEach(function(ms){ setTimeout(expandSections,ms); }); setTimeout(initToc,700); }
  watchBodyPadding();
   if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', boot );
 
   else boot();
   function boot() {
   if ( window.mw ) mw.hook( 'wikipage.content' ).add(function(){ setTimeout(function(){ expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); },300); });
    expandSections();
    watchSections();
    injectMenuLinks();
    injectMoolaUllekhaLinks();
    [100, 400, 900, 1800].forEach(function(ms){ setTimeout(expandSections, ms); });
    setTimeout(initToc, 700);
  }
 
   if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', boot ); }
   else { boot(); }
 
   if ( window.mw ) {
    mw.hook( 'wikipage.content' ).add(function() {
      setTimeout(function(){ expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); }, 300);
    });
  }
 
}() );
}() );


Line 1,057: Line 962:
( function () {
( function () {
   '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 ) { try { el.remove(); } catch(e) {} } } );
        if ( !el.parentNode ) { try { el.remove(); } catch(e) {} }
      } );
     }, 0 );
     }, 0 );
   } );
   } );
   if ( mw.config.get( 'wgPageName' ) !== 'Main_Page' ) return;
   if ( mw.config.get( 'wgPageName' ) !== 'Main_Page' ) return;
   mw.loader.using( 'mediawiki.util' ).done( function () {
   mw.loader.using( 'mediawiki.util' ).done( function () {
     $( function () {
     $( function () { applyHomeToggleOffset(); window.addEventListener( 'resize', applyHomeToggleOffset, { passive: true } ); setTimeout( applyHomeToggleOffset, 300 ); setTimeout( applyHomeToggleOffset, 800 ); } );
      applyHomeToggleOffset();
      window.addEventListener( 'resize', applyHomeToggleOffset, { passive: true } );
      setTimeout( applyHomeToggleOffset, 300 );
      setTimeout( applyHomeToggleOffset, 800 );
    } );
   } );
   } );
   function applyHomeToggleOffset() {
   function applyHomeToggleOffset() {
     var bar = document.getElementById( 'gr-static-bar' );
     var bar = document.getElementById( 'gr-static-bar' ); if ( !bar ) return;
    if ( !bar ) return;
     var barBottom = Math.round( bar.getBoundingClientRect().bottom );
     var barRect = bar.getBoundingClientRect();
     [ document.getElementById('gr-home'), document.getElementById('gr-home-toggle'), document.querySelector('#mw-content-text .mw-parser-output > .gr-home, #mw-content-text .mw-parser-output > *:first-child') ].forEach( function(el){ if(el) el.style.scrollMarginTop=(barBottom+4)+'px'; } );
    var barBottom = Math.round( barRect.bottom );
     var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' );
     var homeEl = document.getElementById( 'gr-home' );
     if ( isMob ) { var toggleEl = document.getElementById('gr-home-toggle'); if ( toggleEl ) { var tr = toggleEl.getBoundingClientRect(); if ( tr.top < barBottom ) { var cp = parseInt(window.getComputedStyle(document.body).paddingTop,10)||0; document.body.style.paddingTop=(cp+(barBottom-tr.top)+4)+'px'; } } }
    var toggleEl = document.getElementById( 'gr-home-toggle' );
    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'; } );
     var contentText = document.getElementById( 'mw-content-text' );
     if ( contentText ) {
      var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' );
      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';
        }
      }
    }
   }
   }
   $( function () {
   $( function () {
     var $toggle = $( '#gr-home-toggle' ), $viewG = $( '#gr-view-grantha' ), $viewA = $( '#gr-view-author' );
     var $toggle=$('#gr-home-toggle'),$viewG=$('#gr-view-grantha'),$viewA=$('#gr-view-author'),$btnG=$('#gr-toggle-grantha'),$btnA=$('#gr-toggle-author');
    var $btnG = $( '#gr-toggle-grantha' ), $btnA = $( '#gr-toggle-author' );
     if(!$toggle.length||!$viewG.length||!$viewA.length)return; if($toggle.data('gr-wired'))return; $toggle.data('gr-wired',true);
     if ( !$toggle.length || !$viewG.length || !$viewA.length ) return;
     function showView(which){ 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){} }
    if ( $toggle.data( 'gr-wired' ) ) return;
     $btnG.on('click keydown',function(e){if(e.type==='keydown'&&e.key!=='Enter'&&e.key!==' ')return;showView('grantha');});
    $toggle.data( 'gr-wired', true );
     $btnA.on('click keydown',function(e){if(e.type==='keydown'&&e.key!=='Enter'&&e.key!==' ')return;showView('author');});
     function showView( which ) {
     try{var saved=localStorage.getItem('grantha_home_tab');if(saved==='author')showView('author');else showView('grantha');}catch(e){showView('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){}
    }
     $btnG.on( 'click keydown', function(e){ if ( e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ' ) return; showView( 'grantha' ); });
     $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' ); }
   } );
   } );
}() );
}() );