Jump to content

       

Go to Vaniquotes | Go to Vanipedia | Go to Vanimedia

Vanisource - the complete essence of Vedic knowledge

MediaWiki:Common.js: Difference between revisions

From Vanisource
No edit summary
Tag: Manual revert
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* INSTALL ONLY IN MediaWiki:Common.js — Vanisource V15 */
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
Line 570: Line 571:
});
});


if (!document.querySelector('header.vector-header, header.mw-header')) {
/* Sticky burger menu - Pure Floating Dropdown (Forces Unpinned & Full Title) */
/* Sticky burger menu - Pure Floating Dropdown (Forces Unpinned & Full Title) */
(function () {
(function () {
Line 729: Line 729:




}
/* Floating "Back to Top" Button Controller */
/* Floating "Back to Top" Button Controller */
(function () {
(function () {
Line 774: Line 773:
});
});


/* Vanisource V6: responsive shared shell. No orientation forcing or timers. */
 
mw.loader.using(["mediawiki.util"]).then(function () {
(function() {
var titleText = "VANISOURCE - BOOKS · LETTERS · LECTURES · CONVERSATIONS";
var targetUrl = "/wiki/Main_Page";
function removeGlobalSiteNotice() {
$('#siteNotice, #localNotice, .vector-sitenotice-container, #mainbanner, .sitenotice, .mw-sitenotice, .anonnotice, .dismissable-notice, #centralNotice').remove();
}
function createHomeLink() {
var homeSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>';
return $('<a>', {
id: 'vanipedia-topbar-home-link',
href: 'https://dev.vanipedia.org/',
title: 'Vanipedia Home / Entry Portal',
'aria-label': 'Home',
class: 'vanipedia-topbar-home'
}).html('<span class="vanipedia-home-icon">' + homeSvg + '</span><span class="vanipedia-home-text">Home</span>');
}
function createCenterBlock() {
var blockStyle = 'position:absolute !important; left:50% !important; top:54% !important; transform:translate(-50%, -50%) !important; display:flex !important; flex-direction:column !important; align-items:center !important; justify-content:center !important; text-align:center !important; white-space:nowrap !important; z-index:10 !important; pointer-events:auto !important;';
var titleStyle = 'position:static !important; transform:none !important; display:block !important; font-family:"Cinzel", Georgia, serif !important; font-size:18px !important; font-weight:700 !important; letter-spacing:2px !important; color:#f5d77f !important; text-decoration:none !important; text-shadow:0 2px 4px rgba(0,0,0,0.9), 0 0 10px rgba(245,215,127,0.3) !important; line-height:1.25 !important; margin:0 0 4px 0 !important; padding:0 !important; user-select:text !important;';
var vanisevaWrapStyle = 'position:static !important; transform:none !important; display:block !important; margin:0 0 4px 0 !important; line-height:1.2 !important;';
var vanisevaLinkStyle = 'color:#fff2c4 !important; font-family:"Noto Serif", Georgia, serif !important; font-size:12.5px !important; font-style:normal !important; font-weight:500 !important; letter-spacing:0.35px !important; text-decoration:none !important; border:1px solid rgba(223,173,62,0.35) !important; background:rgba(245,215,127,0.08) !important; outline:none !important; padding:2px 14px !important; border-radius:12px !important; cursor:pointer !important; display:inline-block !important; transition:all 0.18s ease !important;';
var sisterWrapStyle = 'position:static !important; transform:none !important; display:flex !important; align-items:center !important; justify-content:center !important; gap:14px !important; margin:0 !important; line-height:1.2 !important;';
var sisterLinkStyle = 'color:#f5d77f !important; font-family:"Noto Serif", Georgia, serif !important; font-size:13px !important; font-weight:600 !important; letter-spacing:0.4px !important; text-decoration:none !important; border:none !important; border-bottom:none !important; outline:none !important; padding:2px 8px !important; border-radius:3px !important; display:inline-flex !important; align-items:center !important; cursor:pointer !important; transition:all 0.18s ease !important;';
var sepStyle = 'color:rgba(245,215,127,0.4) !important; font-size:11px !important; line-height:1 !important; user-select:none !important;';
var $block = $('<div>', {
id: 'vanipedia-topbar-center-block',
class: 'vanipedia-topbar-center-block',
style: blockStyle
});
var $title = $('<div>', {
id: 'vanipedia-topbar-title',
class: 'vanipedia-topbar-main-title',
style: titleStyle,
text: titleText
});
var $vaniseva = $('<div>', {
class: 'vanipedia-topbar-vaniseva-title',
style: vanisevaWrapStyle
}).html('<a href="https://vaniseva.org" target="_blank" rel="noopener noreferrer" title="Vaniseva" style="' + vanisevaLinkStyle + '">Collaborate with us to invoke and fully manifest Śrīla Prabhupāda&#39;s Vani-presence</a>');
var $sisterLinks = $('<div>', {
class: 'vanipedia-topbar-sister-links',
style: sisterWrapStyle
}).html(
'<a href="https://vanipedia.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vanipedia" style="' + sisterLinkStyle + '">vanipedia.org</a>' +
'<span class="vanipedia-topbar-sister-sep" aria-hidden="true" style="' + sepStyle + '">•</span>' +
'<a href="https://vaniquotes.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vaniquotes" style="' + sisterLinkStyle + '">vaniquotes.org</a>' +
'<span class="vanipedia-topbar-sister-sep" aria-hidden="true" style="' + sepStyle + '">•</span>' +
'<a href="https://vanimedia.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vanimedia" style="' + sisterLinkStyle + '">vanimedia.org</a>'
);
$block.append($title, $vaniseva, $sisterLinks);
return $block;
}
function updateTopBar() {
removeGlobalSiteNotice();
$('#vanipedia-topbar-center-block, #vanipedia-topbar-center-block-mobile, #vanipedia-topbar-title, #vanipedia-topbar-title-mobile, #vanipedia-topbar-title-link, #vanipedia-topbar-center-title, #vanipedia-topbar-home-link, #vanipedia-topbar-sister-links, #vanipedia-topbar-sister-links-mobile, .vanipedia-topbar-sister-links, .vanipedia-topbar-center-block').remove();
$('.vector-header-container').css({
'background': 'transparent',
'background-color': 'transparent',
'border': 'none',
'box-shadow': 'none',
'padding': '0',
'margin': '0',
'min-height': '0',
'height': 'auto',
'width': '100%',
'max-width': '100%'
});
var isMobile = (window.innerWidth <= 999) || $('body').hasClass('skin-minerva') || $('body').hasClass('skin-vector-mobile') || $('.minerva-header').length > 0;
var $header = $('header.mw-header, header.vector-header').not('.minerva-header').first();
if (!$header.length && !$('body').hasClass('skin-minerva') && !$('.minerva-header').length) {
$header = $('#mw-head, header').not('.minerva-header').filter(':visible').first();
}
if ($header.length) {
$header.css({
'min-height': isMobile ? '52px' : '86px',
'height': isMobile ? '52px' : 'auto',
'max-height': isMobile ? '52px' : 'none',
'padding': isMobile ? '0 10px' : '10px 24px',
'background-color': '#345B63',
'border-bottom': '2px solid #b1873d',
'box-shadow': '0 4px 18px rgba(0,0,0,0.35)',
'position': 'relative',
'display': 'flex',
'flex-wrap': 'nowrap',
'align-items': 'center',
'justify-content': 'space-between',
'box-sizing': 'border-box',
'width': '100%',
'max-width': '100%'
});
if (!isMobile) {
$header.append(createCenterBlock());
}
var $search = $header.find('.vector-header-start #p-search, #p-search');
if ($search.length) {
$search.after(createHomeLink());
} else if ($header.find('.vector-header-start').length) {
$header.find('.vector-header-start').append(createHomeLink());
}
}
var $minervaHeader = $('.minerva-header');
if ($minervaHeader.length) {
// 1. Ensure "Vanipedia" Title Link exists with text in the branding box
var $branding = $minervaHeader.find('.branding-box');
if ($branding.length) {
var $brandLink = $branding.find('a');
if ($brandLink.length) {
if (!$brandLink.text().trim()) {
$brandLink.html('<span>Vanipedia</span>');
}
} else {
$branding.html('<a href="/wiki/Main_Page"><span>Vanipedia</span></a>');
}
} else {
var brandHtml = '<div class="branding-box"><a href="/wiki/Main_Page"><span>Vanipedia</span></a></div>';
var $burger = $minervaHeader.find('#mw-mf-main-menu-button, .navigation-drawer.toggle-list').first();
if ($burger.length) {
$burger.after(brandHtml);
} else {
$minervaHeader.prepend(brandHtml);
}
}
// 2. Ensure Home Link is inserted cleanly
var $minervaForm = $minervaHeader.find('.minerva-search-form, #searchform').first();
if ($minervaForm.length && !$minervaHeader.find('#vanipedia-topbar-home-link').length) {
$minervaForm.before(createHomeLink());
} else if (!$minervaHeader.find('#vanipedia-topbar-home-link').length) {
var $minervaUser = $minervaHeader.find('.minerva-user-navigation, #ca-mytalks').first();
if ($minervaUser.length) {
$minervaUser.before(createHomeLink());
} else {
$minervaHeader.append(createHomeLink());
}
}
$minervaHeader.css({
'flex-wrap': 'nowrap',
'height': '52px',
'min-height': '52px',
'max-height': '52px',
'padding': '0 10px',
'display': 'flex',
'align-items': 'center',
'justify-content': 'space-between',
'box-sizing': 'border-box'
});
}
var $stageHeader = $('#vani-stage-header-slot');
if ($stageHeader.length && !$stageHeader.find('.vanipedia-topbar-center-block').length) {
var $stageSearch = $stageHeader.find('#p-search, .search-box, .minerva-search-form').first();
if ($stageSearch.length && !$stageHeader.find('#vanipedia-topbar-home-link').length) {
$stageSearch.after(createHomeLink());
}
if (!isMobile) {
$stageHeader.append(createCenterBlock());
}
}
var $stickyTitle = $('#vector-sticky-header .vector-sticky-header-title, #vector-sticky-header .vector-sticky-header-context-bar .mw-headline');
if ($stickyTitle.length) {
$stickyTitle.html('<a href="' + targetUrl + '" style="color: inherit; text-decoration: none;">' + titleText + '</a>');
}
}
$(function() {
removeGlobalSiteNotice();
});
var topbarResizeTimer;
$(window).on('resize orientationchange', function() {
clearTimeout(topbarResizeTimer);
topbarResizeTimer = setTimeout(updateTopBar, 150);
});
$(document).ready(updateTopBar);
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(updateTopBar);
}
})();
 
(function initPermanentBottomBar() {
function isEntryPage() {
return (
document.body.classList.contains('ext-vp3d-fullscreen') ||
!!document.querySelector('.vp-entry3d-container') ||
!!document.querySelector('.vp-entry3d-wrapper') ||
window.location.pathname === '/' ||
(window.location.pathname === '/index.php' && !window.location.search) ||
(window.mw && mw.config && (mw.config.get('wgPageName') === 'Entry_Page' || mw.config.get('wgTitle') === 'Entry Page'))
);
}
function setupBottomBar() {
// Never inject on the 3D entry page; remove if already present
if (isEntryPage()) {
var existing = document.getElementById('vh-bottom-bar');
if (existing) existing.remove();
return;
}
if (document.getElementById('vh-bottom-bar')) return;
var bar = document.createElement('nav');
bar.id = 'vh-bottom-bar';
bar.className = 'vh-bottom-bar';
bar.setAttribute('aria-label', 'Vanisource Global Navigation');
bar.innerHTML =
'<div class="vh-bottom-bar-inner" style="display:flex !important; align-items:center !important; width:100% !important; max-width:100% !important; height:100% !important; padding:0 24px !important; box-sizing:border-box !important;">' +
'<div class="vh-bottom-bar-left-space" style="flex:1 1 0 !important; min-width:0 !important;"></div>' +
'<div class="vh-bottom-nav-links" style="flex:0 0 auto !important; display:flex !important; align-items:center !important; justify-content:center !important; gap:12px !important; white-space:nowrap !important;">' +
'<a href="https://dev.vanipedia.org/" class="vh-bottom-link vh-bottom-entry">Home</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="/wiki/Main_Page" class="vh-bottom-link vh-bottom-home">Main Page</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vanipedia_Vision" class="vh-bottom-link">Core Principles</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vaniseva" class="vh-bottom-link">Volunteer</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vanipedia_Community" class="vh-bottom-link">Community</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/contact.php" target="_blank" rel="noopener noreferrer" class="vh-bottom-link">Contact</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Special:IframePage" class="vh-bottom-link vh-bottom-donate">Donate</a>' +
'</div>' +
'<div class="vh-bottom-bar-right-space" style="flex:1 1 0 !important; min-width:0 !important; display:flex !important; align-items:center !important; justify-content:center !important;">' +
'<div class="vh-bottom-social-links" style="position:static !important; transform:none !important; display:inline-flex !important; align-items:center !important; gap:24px !important;">' +
'<a href="https://www.youtube.com/@VanimediaPrabhupada" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="YouTube" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/YouTube_Logo_B.png" alt="YouTube" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.facebook.com/vanipedia.org" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Facebook Page" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Facebook_Group_Logo.png" alt="Facebook" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.facebook.com/groups/VanipediaGroup" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Facebook Group" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Facebook_Logo_2023.png" alt="Facebook Group" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.instagram.com/vanipediaprabhupada/" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Instagram" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Insta_Logo.png" alt="Instagram" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'</div>' +
'</div>' +
'</div>';
var stageSlot = document.getElementById('vani-stage-footer-slot');
if (stageSlot) {
stageSlot.appendChild(bar);
} else {
document.body.appendChild(bar);
}
}
// Remove bar if 3D entry page activates asynchronously
if (window.MutationObserver && document.body) {
var observer = new MutationObserver(function() {
if (isEntryPage()) {
var existing = document.getElementById('vh-bottom-bar');
if (existing) existing.remove();
}
});
observer.observe(document.body, { attributes: true, attributeFilter: ['class'], childList: true });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setupBottomBar);
} else {
setupBottomBar();
}
})();
 
/* V7: wiki-native shell controls and one selection per page load. */
(function () {
(function () {
    'use strict';
     var selected = null;
     var petals = [['Vanipedia', 'https://vanipedia.org'], ['Vaniquotes', 'https://vaniquotes.org'], ['Vanimedia', 'https://vanimedia.org']];
     var passages = [
     var siteLinks = [
         { text: 'The self-realized soul is not bewildered by such a change.', title: 'Bhagavad-gītā 2.13 · 1972 edition', href: 'https://vanisource.org/wiki/BG_2.13_(1972)' },
         ['Home', 'https://dev.vanipedia.org/'], ['Main Page', '/wiki/Main_Page'],
         { text: 'Just try to learn the truth by approaching a spiritual master. Inquire from him submissively and render service unto him.', title: 'Bhagavad-gītā 4.34 · 1972 edition', href: 'https://vanisource.org/wiki/BG_4.34_(1972)' }
        ['Core Principles', 'https://vanipedia.org/wiki/Vanipedia_Vision'],
        ['Volunteer', 'https://vaniseva.org'], ['Community', 'https://vanipedia.org/wiki/Vanipedia_Community'],
         ['Contact', 'https://vanipedia.org/contact.php'], ['Donate', 'https://vanipedia.org/wiki/Special:IframePage']
     ];
     ];
     function element(tag, className, text) {
     function init() {
         var el = document.createElement(tag);
        var home = document.getElementById('vs-home');
         if (className) el.className = className;
        var action = mw.config.get('wgAction') || 'view';
         if (text) el.textContent = text;
        var main = !!home && (action === 'view' || action === 'purge');
         return el;
        if (main) {
            document.body.classList.add('vs-main-view');
            var slot = document.getElementById('vs-search-slot');
            if (slot && !slot.querySelector('form')) {
                var form = document.createElement('form');
                form.className = 'vs-search'; form.method = 'get'; form.action = mw.config.get('wgScript') || '/w/index.php'; form.setAttribute('role','search');
                var hidden = document.createElement('input'); hidden.type='hidden'; hidden.name='title'; hidden.value='Special:Search';
                var label=document.createElement('label');label.htmlFor='vs-main-search';label.textContent='Search Vanisource';
                var input=document.createElement('input');input.type='search';input.name='search';input.id='vs-main-search';input.placeholder='Search Śrīla Prabhupāda’s teachings';
                var button=document.createElement('button');button.type='submit';button.textContent='Search';
                label.appendChild(input);form.append(hidden,label,button);slot.replaceChildren(form);
            }
            if (!selected) selected={passage:passages[Math.floor(Math.random()*passages.length)],photo:Math.floor(Math.random()*12)+1};
            if (!home.dataset.vsSelectionApplied) {
                home.dataset.vsSelectionApplied='true';
                var quote=home.querySelector('.vs-source-quote');var reference=home.querySelector('.vs-source-meta a');
                if (quote && reference) {quote.textContent='“'+selected.passage.text+'”';reference.textContent=selected.passage.title;reference.href=selected.passage.href;}
                var portrait=home.querySelector('#vs-portrait-frame img');
                if (portrait) {
                    var preload=new Image();
                    preload.onload=function(){if(portrait.isConnected){portrait.removeAttribute('srcset');portrait.removeAttribute('sizes');portrait.src=preload.src;}};
                    preload.src='/wiki/Special:Redirect/file/Srila-Prabhupada-Hero-'+String(selected.photo).padStart(2,'0')+'.jpg';
                }
            }
            // Keep the native menu reachable when the reading-area sidebars are hidden.
            var menu=document.getElementById('vector-main-menu');
            var unpinned=document.getElementById('vector-main-menu-unpinned-container') || document.querySelector('#vector-main-menu-dropdown .vector-dropdown-content');
            if(menu && unpinned && !unpinned.contains(menu)) unpinned.appendChild(menu);
        }
        var header=document.querySelector('header.vector-header, header.mw-header');
        var start=header && header.querySelector('.vector-header-start');
         var search=document.getElementById('p-search');
         if(start && search && !start.contains(search)) start.appendChild(search);
        var portal=document.getElementById('vanipedia-topbar-home-link');
        if(start && portal) start.appendChild(portal);
         document.querySelectorAll('#searchInput, input[name="search"]').forEach(function(input){
            if(input.id!=='vs-main-search') {input.placeholder='Search Vanisource';input.setAttribute('aria-label','Search Vanisource');}
        });
        // Label the real native menu toggle; its skin handlers remain in charge.
        var menuLabel=document.querySelector('#vector-main-menu-dropdown .vector-dropdown-label');
         if(menuLabel) menuLabel.setAttribute('aria-label','Main menu');
     }
     }
     function link(label, href) {
     $(init);mw.hook('wikipage.content').add(init);
        var a = element('a', '', label);
    var pending;
        a.href = href;
    $(window).on('resize orientationchange',function(){clearTimeout(pending);pending=setTimeout(init,200);});
         return a;
})();
 
});
 
/* V12: place the live header outside the reading grid so sticky positioning
  lasts for the entire page, and reserve an anchor-scroll offset. */
(function () {
function initStickyHeader() {
  var header=document.querySelector('header.vector-header, header.mw-header');
  if(!header)return;
  var container=header.closest('.vector-header-container') || header;
  if(container.parentElement!==document.body)document.body.insertBefore(container,document.body.firstChild);
  function updateOffset(){
  document.documentElement.style.setProperty('--vs-header-height',container.getBoundingClientRect().height+'px');
  }
  updateOffset();
  if(!container.dataset.vsStickyReady){
  container.dataset.vsStickyReady='true';
  if(window.ResizeObserver){var observer=new ResizeObserver(updateOffset);observer.observe(container);}
  else window.addEventListener('resize',updateOffset);
  }
}
$(initStickyHeader);
mw.hook('wikipage.content').add(initStickyHeader);
})();
 
/* V13: the edition page works as a complete ordinary wiki page without JS.
  With JS, a book hash shows only that title. Native links/history remain. */
(function () {
    function showSelection(moveFocus) {
        var root = document.getElementById('vs-editions');
         if (!root) return;
        var action = mw.config.get('wgAction') || 'view';
        if (action !== 'view' && action !== 'purge') return;
        var fragment;
        try { fragment = decodeURIComponent(window.location.hash.slice(1)); }
        catch (e) { fragment = ':invalid-fragment:'; }
        var target = fragment ? document.getElementById(fragment) : null;
        var selected = target && root.contains(target) ? target.closest('.vs-edition-book') : null;
        var index = root.querySelector('.vs-edition-index');
        var books = root.querySelectorAll('.vs-edition-book');
        if (selected) {
            if (index) index.hidden = true;
            books.forEach(function (book) { book.hidden = book !== selected; });
        } else {
            // The title index stays compact with JS. Unknown hashes expose
            // all text so older chapter/book anchors never produce a blank page.
            if (index) index.hidden = false;
            var indexOnly = !!index && (!fragment || fragment === 'all-books');
            books.forEach(function (book) { book.hidden = indexOnly; });
        }
        if (moveFocus && selected) {
            selected.setAttribute('tabindex', '-1');
            selected.focus({ preventScroll: true });
            selected.scrollIntoView({ block: 'start', behavior: 'auto' });
        }
     }
     }
     function navigation(items, className, label) {
     $(function () { showSelection(false); });
         var nav = element('nav', className);
    mw.hook('wikipage.content').add(function () { showSelection(false); });
        nav.setAttribute('aria-label', label);
    window.addEventListener('hashchange', function () { showSelection(true); });
        items.forEach(function (item) { nav.appendChild(link(item[0], item[1])); });
})();
         return nav;
 
/* V14: reuse native shared File references. If a dev thumbnail is missing,
  use the existing audited Vanimedia image; never duplicate/upload the file. */
(function () {
    function initSharedCovers() {
         document.querySelectorAll('#vs-home [data-vs-cover-source], #vs-editions [data-vs-cover-source]').forEach(function (frame) {
            var source = frame.dataset.vsCoverSource;
            var parsed;
            try { parsed = new URL(source); } catch (e) { return; }
            if (parsed.protocol !== 'https:' || parsed.hostname !== 'vanimedia.org' || !parsed.pathname.startsWith('/w/images/')) return;
            var image = frame.querySelector('img');
            if (!image) {
                // A transient repository lookup failure may yield a red File
                // link instead of an image. Keep the book navigation usable.
                image = document.createElement('img');
                image.alt = frame.dataset.vsCoverAlt || 'Representative book cover';
                var destination = frame.dataset.vsCoverLink;
                if (destination && (destination.startsWith('/wiki/Books_and_Editions#') || /^https:\/\/(?:www\.)?vanisource\.org\/wiki\//.test(destination))) {
                    var link = document.createElement('a');
                    link.href = destination;
                    link.appendChild(image);
                    frame.replaceChildren(link);
                } else {
                    frame.replaceChildren(image);
                }
                image.dataset.vsCoverFallback = 'true';
                image.src = source;
                return;
            }
            if (image.dataset.vsCoverReady) return;
            image.dataset.vsCoverReady = 'true';
            function fallback() {
                if (!image.isConnected || image.dataset.vsCoverFallback) return;
                image.dataset.vsCoverFallback = 'true';
                image.removeAttribute('srcset');
                image.removeAttribute('sizes');
                var picture = image.closest('picture');
                if (picture) picture.querySelectorAll('source').forEach(function (item) { item.remove(); });
                image.src = source;
            }
            image.addEventListener('error', fallback, { once: true });
            if (image.complete && image.naturalWidth === 0) fallback();
         });
     }
     }
     function isMainView() {
     $(initSharedCovers);
        var action = mw.config.get('wgAction') || 'view';
    mw.hook('wikipage.content').add(initSharedCovers);
        return !!document.getElementById('vs-home') && (action === 'view' || action === 'purge');
})();
 
/* V15: edition choices stay over the bookshelf; wiki links remain the fallback. */
(function () {
    var books = [{"id":"book-00","title":"Bhagavad-gītā As It Is","editions":[{"label":"1968 · Abridged","title":"Bhagavad Gita As It Is (1968)","url":"https://vanisource.org/wiki/Bhagavad_Gita_As_It_Is_(1968)_Collier-Macmillan_Abridged_Edition","pdf_links":[]},{"label":"1972","title":"Bhagavad-gītā As It Is (1972)","url":"https://vanisource.org/wiki/Bhagavad-gita_As_It_Is_(1972)","pdf_links":["http://vanimedia.org/w/images/7/7a/1972-73_Bhagavad_gita-As_It_Is.pdf"]},{"label":"1983+","title":"Bhagavad-gītā As It Is (1983+)","url":"https://vanisource.org/wiki/Bhagavad-gita_As_It_Is_(1983%2B)","pdf_links":[]}],"related":[{"title":"Introduction to Bhagavad-gita","note":"A publication format of the introduction, not another full Bhagavad-gītā work. Related Vanisource text is explicitly the 1972 edition; do not label it as the standalone booklet.","source":"https://www.bbt.org/book/introduction-bhagavad-gita"},{"title":"Srimad Bhagavad-Gita Verse Book","note":"BBT describes roman transliterations of the Sanskrit verses. Keep under formats; no matching Vanisource standalone verse-book edition verified.","source":"https://www.bbt.org/book/srimad-bhagavad-gita-verse-book"}]},{"id":"book-01","title":"Śrīmad-Bhāgavatam","editions":[{"label":"1962-65","title":"Srimad Bhagwatam (1962-65)","url":"https://vanisource.org/wiki/Srimad_Bhagwatam_(1962-65)","pdf_links":["http://vanimedia.org/w/images/c/c5/1962-SB-Vol-1.pdf","http://vanimedia.org/w/images/7/77/1964-SB-Vol-2.pdf","http://vanimedia.org/w/images/1/1c/1965-SB-Vol-3.pdf"]},{"label":"Text and sources","title":"Śrīmad-Bhāgavatam","url":"https://vanisource.org/wiki/Srimad-Bhagavatam","pdf_links":[]},{"label":"1972–1977 · PDFs","title":"Śrīmad-Bhāgavatam (1972-77)","url":"https://vanisource.org/wiki/Srimad-Bhagavatam_(1972-77)","pdf_links":["http://vanimedia.org/w/images/9/94/SB1.1-1972.pdf","http://vanimedia.org/w/images/9/96/SB1.2-1972.pdf","http://vanimedia.org/w/images/c/c9/SB1.3-1972.pdf","http://vanimedia.org/w/images/6/68/SB2.1-1972.pdf","http://vanimedia.org/w/images/8/8b/SB2.2-1972.pdf","http://vanimedia.org/w/images/d/d2/SB3.1-1972.pdf","http://vanimedia.org/w/images/f/fc/SB3.2-1974.pdf","http://vanimedia.org/w/images/2/2b/SB3.3-1974.pdf","http://vanimedia.org/w/images/3/31/SB3.4-1974.pdf","http://vanimedia.org/w/images/9/9c/SB4.1-1972.pdf","http://vanimedia.org/w/images/4/4c/SB4.2-1974.pdf","http://vanimedia.org/w/images/5/51/SB4.3-1974.pdf","http://vanimedia.org/w/images/8/88/SB4.4-1974.pdf","http://vanimedia.org/w/images/a/a8/SB5.1-1975.pdf","http://vanimedia.org/w/images/f/f6/SB5.2-1975.pdf","http://vanimedia.org/w/images/7/7a/SB6.1-1975.pdf","http://vanimedia.org/w/images/6/6e/SB6.2-1975.pdf","http://vanimedia.org/w/images/5/54/SB6.3-1976.pdf","http://vanimedia.org/w/images/1/1b/SB7.1-1976.pdf","http://vanimedia.org/w/images/a/a0/SB7.2-1976.pdf","http://vanimedia.org/w/images/a/a6/SB7.3-1976.pdf","http://vanimedia.org/w/images/c/c8/SB8.1-1976.pdf","http://vanimedia.org/w/images/8/8c/SB8.2-1976.pdf","http://vanimedia.org/w/images/0/00/SB8.3-1976.pdf","http://vanimedia.org/w/images/b/b8/SB9.1-1977.pdf","http://vanimedia.org/w/images/e/e6/SB9.2-1977.pdf","http://vanimedia.org/w/images/1/11/SB9.3-1977.pdf","http://vanimedia.org/w/images/6/63/SB10.1-1977.pdf","http://vanimedia.org/w/images/1/10/SB10.2-1977.pdf","http://vanimedia.org/w/images/5/56/SB10.3-1980.pdf"]}],"note":"Volume attribution matters: BBTmedia credits later continuation cantos 11 and 12 to Hridayānanda Goswami and Gopīparāṇadhana Dāsa."},{"id":"book-02","title":"Śrī Caitanya-caritāmṛta","editions":[{"label":"1975","title":"Śrī Caitanya-caritāmṛta (1975)","url":"https://vanisource.org/wiki/Sri_Caitanya-caritamrta_(1975)","pdf_links":[]},{"label":"1996","title":"Śrī Caitanya-caritāmṛta (1996)","url":"https://vanisource.org/wiki/Sri_Caitanya-caritamrta","pdf_links":[]}]},{"id":"book-03","title":"Nectar of Instruction","editions":[{"label":"1975","title":"Nectar of Instruction (1975)","url":"https://vanisource.org/wiki/The_Nectar_of_Instruction_(1975)","pdf_links":["http://vanimedia.org/w/images/f/f6/1975-The_Nectar_of_Instruction.pdf"]}]},{"id":"book-04","title":"Śrī Īśopaniṣad","editions":[{"label":"1974","title":"Śrī Īśopaniṣad (1974)","url":"https://vanisource.org/wiki/Sri_Isopanisad_(1974)","pdf_links":["http://vanimedia.org/w/images/f/fe/1969-edition-Sri-Isopanisad.pdf"]},{"label":"2001","title":"Śrī Īśopaniṣad (2001)","url":"https://vanisource.org/wiki/Sri_Isopanisad_(2001)","pdf_links":[]}]},{"id":"book-05","title":"Kṛṣṇa, the Supreme Personality of Godhead","editions":[{"label":"1970","title":"Kṛṣṇa, The Supreme Personality of Godhead (1970)","url":"https://vanisource.org/wiki/Krsna_The_Supreme_Personality_of_Godhead_(1970)","pdf_links":["http://vanimedia.org/w/images/0/06/1970-KRSNA_Book_Vol.1.pdf","http://vanimedia.org/w/images/e/ef/1970-KRSNA_Book_Vol.2.pdf"]},{"label":"1996+","title":"Kṛṣṇa, The Supreme Personality of Godhead (1996+)","url":"https://vanisource.org/wiki/Krsna_The_Supreme_Personality_of_Godhead_(1996%2B)","pdf_links":[]}]},{"id":"book-06","title":"Teachings of Lord Caitanya","editions":[{"label":"1975","title":"Teachings of Lord Caitanya (1975)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Caitanya_(1975)","pdf_links":[]},{"label":"2011","title":"Teachings of Lord Caitanya (2011)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Caitanya_(2011)","pdf_links":[]},{"label":"1968","title":"Teachings of Lord Chaitanya (1968)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Chaitanya_(1968)","pdf_links":["http://vanimedia.org/w/images/2/21/1968-Teachings_of_Lord_Chaitanya.pdf"]}]},{"id":"book-07","title":"Nectar of Devotion","editions":[{"label":"1970","title":"Nectar of Devotion (1970)","url":"https://vanisource.org/wiki/Nectar_of_Devotion_(1970)","pdf_links":["http://vanimedia.org/w/images/a/a5/1970-The_Nectar_of_Devotion.pdf"]},{"label":"1982","title":"Nectar of Devotion (1982)","url":"https://vanisource.org/wiki/Nectar_of_Devotion_(1982)","pdf_links":[]}]},{"id":"book-08","title":"Beyond Birth and Death","editions":[{"label":"Text and sources","title":"Beyond Birth and Death","url":"https://vanisource.org/wiki/Beyond_Birth_and_Death","pdf_links":["http://vanimedia.org/w/images/6/67/1972_Beyond_Birth_and_Death_1974_edition.pdf"]}]},{"id":"book-09","title":"Easy Journey to Other Planets","editions":[{"label":"Text and sources","title":"Easy Journey to Other Planets","url":"https://vanisource.org/wiki/Easy_Journey_to_Other_Planets","pdf_links":["http://vanimedia.org/w/images/e/e3/Easy-Journey-to-Other-Planets-original-India-edition.pdf","http://vanimedia.org/w/images/4/46/Easy-Journy-to-Other-Planets-1977.pdf"]}]},{"id":"book-10","title":"Elevation to Kṛṣṇa Consciousness","editions":[{"label":"Text and sources","title":"Elevation to Kṛṣṇa Consciousness","url":"https://vanisource.org/wiki/Elevation_to_Krsna_Consciousness","pdf_links":["http://vanimedia.org/w/images/1/1b/1973_Elevation_to_Krsna_Consciousness.pdf"]}]},{"id":"book-11","title":"Gītār Gān","editions":[{"label":"Text and sources","title":"Gītār Gān","url":"https://vanisource.org/wiki/Gitar_Gan","pdf_links":[]}]},{"id":"book-12","title":"Kṛṣṇa Consciousness, The Matchless Gift","editions":[{"label":"Text and sources","title":"Kṛṣṇa Consciousness, The Matchless Gift","url":"https://vanisource.org/wiki/Krsna_Consciousness,_The_Matchless_Gift","pdf_links":["http://vanimedia.org/w/images/c/c3/1974-Krsna_Consciousness-The_Matchless_Gift.pdf"]}]},{"id":"book-13","title":"Kṛṣṇa Consciousness, The Topmost Yoga System","editions":[{"label":"Text and sources","title":"Kṛṣṇa Consciousness, The Topmost Yoga System","url":"https://vanisource.org/wiki/Krsna_Consciousness_The_Topmost_Yoga_System","pdf_links":[]}]},{"id":"book-14","title":"Kṛṣṇa, the Reservoir of Pleasure","editions":[{"label":"Text and sources","title":"Kṛṣṇa, the Reservoir of Pleasure","url":"https://vanisource.org/wiki/Krsna_the_Reservoir_of_Pleasure","pdf_links":["http://vanimedia.org/w/images/f/fb/1969-TWO_ESSAYS-Krishna_the_Reservoir_of_Pleasure-%26-Who_is_Crazy.pdf","http://vanimedia.org/w/images/9/9d/KRSNA-the-Reservoir-of-Pleasure-1970.pdf"]}]},{"id":"book-15","title":"On the Way to Kṛṣṇa","editions":[{"label":"Text and sources","title":"On the Way to Kṛṣṇa","url":"https://vanisource.org/wiki/On_the_Way_to_Krsna","pdf_links":["http://vanimedia.org/w/images/e/ee/1973-On_the_Way_to_Krsna.pdf"]}]},{"id":"book-16","title":"Perfect Questions, Perfect Answers","editions":[{"label":"Text and sources","title":"Perfect Questions, Perfect Answers","url":"https://vanisource.org/wiki/Perfect_Questions,_Perfect_Answers","pdf_links":["http://vanimedia.org/w/images/9/9e/1977-Perfect_Questions_Perfect_Answers_Original.pdf"]}]},{"id":"book-17","title":"The Perfection of Yoga","editions":[{"label":"1972","title":"The Perfection of Yoga (1972)","url":"https://vanisource.org/wiki/The_Perfection_of_Yoga_(1972)","pdf_links":["http://vanimedia.org/w/images/8/8b/1972_Perfection_of_Yoga_2008_Original.pdf"]},{"label":"1983","title":"The Perfection of Yoga (1983)","url":"https://vanisource.org/wiki/The_Perfection_of_Yoga_(1983)","pdf_links":[]}],"related":[{"title":"The Path of Yoga","note":"Krishna.com provides the contents: Part One is The Path of Perfection and Part Two is The Perfection of Yoga. The combined edition is not a third independent work.","source":"https://www.bbt.org/book/path-yoga"}]},{"id":"book-18","title":"Rāja-Vidyā: The King of Knowledge","editions":[{"label":"Text and sources","title":"Rāja-Vidyā: The King of Knowledge","url":"https://vanisource.org/wiki/Raja-Vidya_The_King_of_Knowledge","pdf_links":["http://vanimedia.org/w/images/b/b1/1973_Raja-Vidya_The_King_of_Knowledge.pdf"]}]},{"id":"book-19","title":"Teachings of Lord Kapila","editions":[{"label":"Text and sources","title":"Teachings of Lord Kapila","url":"https://vanisource.org/wiki/Teachings_of_Lord_Kapila,_the_Son_of_Devahuti","pdf_links":["http://vanimedia.org/w/images/1/19/1977-Teachings-of-Lord-Kapila.pdf"]}]},{"id":"book-20","title":"Transcendental Teachings of Prahlāda Mahārāja","editions":[{"label":"Text and sources","title":"Transcendental Teachings of Prahlāda Mahārāja","url":"https://vanisource.org/wiki/Transcendental_Teachings_of_Prahlada_Maharaja","pdf_links":[]}]},{"id":"book-21","title":"Beyond Illusion & Doubt","editions":[{"label":"Text and sources","title":"Beyond Illusion & Doubt","url":"https://vanisource.org/wiki/Beyond_Illusion_%26_Doubt","pdf_links":[]}]},{"id":"book-22","title":"Civilization and Transcendence","editions":[{"label":"Text and sources","title":"Civilization and Transcendence","url":"https://vanisource.org/wiki/Civilization_and_Transcendence","pdf_links":[]}]},{"id":"book-23","title":"Dharma - The Way of Transcendence","editions":[{"label":"Text and sources","title":"Dharma - The Way of Transcendence","url":"https://vanisource.org/wiki/Dharma_-_The_Way_of_Transcendence","pdf_links":[]}]},{"id":"book-24","title":"In Search of the Ultimate Goal of Life","editions":[{"label":"1993","title":"In Search of the Ultimate Goal of Life (1993)","url":"https://vanisource.org/wiki/In_Search_of_the_Ultimate_Goal_of_Life","pdf_links":[]}]},{"id":"book-25","title":"Journey of Self-Discovery","editions":[{"label":"Text and sources","title":"Journey of Self-Discovery","url":"https://vanisource.org/wiki/The_Journey_of_Self-Discovery","pdf_links":["https://vanisource.org/w/images/The_Journey_of_Self-Discovery.pdf"]}]},{"id":"book-26","title":"Laws of Nature, An Infallible Justice","editions":[{"label":"Text and sources","title":"Laws of Nature, An Infallible Justice","url":"https://vanisource.org/wiki/The_Laws_of_Nature_An_Infallible_Justice","pdf_links":[]}]},{"id":"book-27","title":"Life Comes From Life","editions":[{"label":"Text and sources","title":"Life Comes From Life","url":"https://vanisource.org/wiki/Life_Comes_From_Life","pdf_links":[]}]},{"id":"book-28","title":"Light of the Bhagavata","editions":[{"label":"Text and sources","title":"Light of the Bhagavata","url":"https://vanisource.org/wiki/Light_of_the_Bhagavata","pdf_links":[]}]},{"id":"book-29","title":"Message of Godhead","editions":[{"label":"1955","title":"Message of Godhead (1955)","url":"https://vanisource.org/wiki/Message_of_Godhead_(1955)","pdf_links":["http://vanimedia.org/w/images/e/e5/1955-Message_of_Godhead-handwritten.pdf","http://vanimedia.org/w/images/6/65/1955-Message_of_Godhead.pdf"]},{"label":"1990","title":"Message of Godhead (1990)","url":"https://vanisource.org/wiki/Message_of_Godhead_(1990)","pdf_links":[]}]},{"id":"book-30","title":"Mukunda-mala-stotra","editions":[{"label":"Text and sources","title":"Mukunda-mala-stotra","url":"https://vanisource.org/wiki/Mukunda-mala-stotra","pdf_links":[]}],"note":"BBT credits this commentary publication to Śrīla Prabhupāda and his disciples."},{"id":"book-31","title":"Narada Bhakti Sutra","editions":[{"label":"Text and sources","title":"Narada Bhakti Sutra","url":"https://vanisource.org/wiki/Narada_Bhakti_Sutra","pdf_links":[]}],"note":"Begun by Śrīla Prabhupāda and completed by Satsvarūpa dāsa Goswami."},{"id":"book-32","title":"Path of Perfection","editions":[{"label":"Text and sources","title":"Path of Perfection","url":"https://vanisource.org/wiki/The_Path_of_Perfection","pdf_links":[]}],"related":[{"title":"The Path of Yoga","note":"Krishna.com provides the contents: Part One is The Path of Perfection and Part Two is The Perfection of Yoga. The combined edition is not a third independent work.","source":"https://www.bbt.org/book/path-yoga"}]},{"id":"book-33","title":"Renunciation Through Wisdom","editions":[{"label":"Text and sources","title":"Renunciation Through Wisdom","url":"https://vanisource.org/wiki/Renunciation_Through_Wisdom","pdf_links":[]}]},{"id":"book-34","title":"Science of Self-Realization","editions":[{"label":"Text and sources","title":"Science of Self-Realization","url":"https://vanisource.org/wiki/The_Science_of_Self-Realization","pdf_links":[]}]},{"id":"book-35","title":"Second Chance - The Story of a Near-Death Experience","editions":[{"label":"Text and sources","title":"Second Chance - The Story of a Near-Death Experience","url":"https://vanisource.org/wiki/A_Second_Chance_-_The_Story_of_a_Near-Death_Experience","pdf_links":[]}]},{"id":"book-36","title":"Teachings of Queen Kuntī","editions":[{"label":"Text and sources","title":"Teachings of Queen Kuntī","url":"https://vanisource.org/wiki/Teachings_of_Queen_Kunti","pdf_links":["http://vanimedia.org/w/images/1/17/1978-Teachings-Of-Queen-Kunti.pdf"]}]},{"id":"book-37","title":"Quest for Enlightenment","editions":[{"label":"Text and sources","title":"Quest for Enlightenment","url":"https://vanisource.org/wiki/The_Quest_for_Enlightenment","pdf_links":["http://vanimedia.org/w/images/f/f4/1997-The_Quest_for_Enlightenment.pdf"]}]}];
    var byId = {};
    books.forEach(function (book) { byId[book.id] = book; });
    var dialog, content, heading, closeButton, invoker;
    var storageKey = 'vs:preferred-editions:v1';
    function preferences() {
        try {
            var value = JSON.parse(localStorage.getItem(storageKey) || '{}');
            return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
        } catch (e) { return {}; }
     }
     }
     function initSearch() {
     function remember(id, url) {
         var slot = document.getElementById('vs-search-slot');
         try { var value = preferences(); value[id] = url; localStorage.setItem(storageKey, JSON.stringify(value)); }
        if (!slot || slot.querySelector('form')) return;
         catch (e) { /* Reading must work with storage disabled. */ }
        var form = element('form', 'vs-search');
        form.method = 'get';
        form.action = mw.config.get('wgScript') || '/w/index.php';
        form.setAttribute('role', 'search');
        var title = element('input'); title.type = 'hidden'; title.name = 'title'; title.value = 'Special:Search';
        var label = element('label', '', 'Search Vanisource');
        label.htmlFor = 'vs-main-search';
        var input = element('input'); input.type = 'search'; input.id = 'vs-main-search'; input.name = 'search';
        input.placeholder = 'Search Śrīla Prabhupāda’s teachings';
        var button = element('button', '', 'Search'); button.type = 'submit';
        label.appendChild(input); form.append(title, label, button);
         slot.replaceChildren(form);
     }
     }
     function setPanel(panel, button, open, restoreFocus) {
     function node(tag, name, text) {
         panel.hidden = !open;
         var element = document.createElement(tag);
        button.setAttribute('aria-expanded', String(open));
         if (name) element.className = name;
         if (open) {
        if (text) element.textContent = text;
            var first = panel.querySelector('a[href], button, input:not([type="hidden"])');
         return element;
            if (first) first.focus();
         } else if (restoreFocus) button.focus();
     }
     }
     function setupHeader() {
     function ensureDialog() {
         if (document.getElementById('vs-site-header')) return;
         if (dialog && dialog.isConnected) return true;
         var nativeHeader = document.querySelector('header.vector-header, header.mw-header');
         dialog = document.createElement('dialog');
        // Other skins retain their own working menu, account and search controls.
         if (typeof dialog.showModal !== 'function') return false;
         if (!nativeHeader) return;
         dialog.id = 'vs-edition-dialog';
        var header = element('header'); header.id = 'vs-site-header';
         dialog.setAttribute('aria-labelledby', 'vs-edition-dialog-title');
        var left = element('div', 'vs-header-tools');
         var header = node('div', 'vs-modal-header');
         var menuButton = element('button', 'vs-menu-button', '☰ Menu');
         heading = node('h2', '', 'Choose edition');
         menuButton.type = 'button'; menuButton.setAttribute('aria-controls', 'vs-menu-panel'); menuButton.setAttribute('aria-expanded', 'false');
         heading.id = 'vs-edition-dialog-title';
        left.append(menuButton, link('Home', siteLinks[0][1]));
         closeButton = node('button', 'vs-modal-close', 'Close ×');
         var brand = element('div', 'vs-brand');
         closeButton.type = 'button';
        var title = link('VANISOURCE', '/wiki/Main_Page'); title.className = 'vs-name';
         closeButton.setAttribute('aria-label', 'Close edition choices');
        brand.append(title, element('div', 'vs-subtitle', 'Books · Letters · Lectures · Conversations'), navigation(petals, 'vs-header-petals', 'Other petals'));
         closeButton.addEventListener('click', function () { dialog.close(); });
         var accountButton = element('button', 'vs-account-button', 'Account');
         header.append(heading, closeButton);
         accountButton.type = 'button'; accountButton.setAttribute('aria-controls', 'vs-account-panel'); accountButton.setAttribute('aria-expanded', 'false');
         content = node('div', 'vs-modal-content');
         var menuPanel = element('div', 'vs-shell-panel'); menuPanel.id = 'vs-menu-panel'; menuPanel.hidden = true;
         dialog.append(header, content);
        menuPanel.appendChild(navigation(siteLinks.concat(petals), 'vs-menu-links', 'Site navigation'));
         dialog.addEventListener('close', function () {
         var accountPanel = element('div', 'vs-shell-panel'); accountPanel.id = 'vs-account-panel'; accountPanel.hidden = true;
            document.documentElement.classList.remove('vs-edition-modal-open');
         header.append(left, brand, accountButton, menuPanel, accountPanel);
            if (invoker && invoker.isConnected) invoker.focus({ preventScroll: true });
        // Move live MediaWiki nodes rather than reproducing login/logout or notification URLs.
        var nativeAccount = nativeHeader.querySelector('.vector-header-end');
        var nativeMenu = document.getElementById('vector-main-menu');
        if (nativeAccount) accountPanel.appendChild(nativeAccount);
        if (!nativeAccount || !nativeAccount.querySelector('a, button, input')) {
            accountPanel.appendChild(link('Log in', '/w/index.php?title=Special:UserLogin&returnto=' + encodeURIComponent(mw.config.get('wgPageName') || 'Main_Page')));
         }
        if (nativeMenu) {
            menuPanel.appendChild(nativeMenu);
            nativeMenu.classList.remove('vanipedia-sidebar-menu', 'vanipedia-collapsed');
            nativeMenu.querySelectorAll('.vanipedia-sidebar-menu').forEach(function (menu) { menu.classList.remove('vanipedia-sidebar-menu', 'vanipedia-collapsed'); });
         }
        // Keep article search available when the main-page search is absent.
        if (!isMainView()) {
            var nativeSearch = document.getElementById('p-search');
            if (nativeSearch) menuPanel.appendChild(nativeSearch);
            else menuPanel.appendChild(link('Search Vanisource', '/wiki/Special:Search'));
         }
        // Essential editing routes stay available even when absent from a custom sidebar.
        var page = mw.config.get('wgPageName') || 'Main_Page';
        var script = mw.config.get('wgScript') || '/w/index.php';
        menuPanel.appendChild(navigation([
            ['Edit this page', script + '?title=' + encodeURIComponent(page) + '&action=edit'],
            ['Page history', script + '?title=' + encodeURIComponent(page) + '&action=history'],
            ['Special pages', '/wiki/Special:SpecialPages']
        ], 'vs-menu-links', 'Wiki tools'));
         document.body.insertBefore(header, document.body.firstChild);
         nativeHeader.classList.add('vs-native-header-replaced');
        document.body.classList.add('vs-shell-ready');
        var pairs = [[menuPanel, menuButton], [accountPanel, accountButton]];
        pairs.forEach(function (pair) {
            pair[1].addEventListener('click', function () {
                var open = pair[0].hidden;
                pairs.forEach(function (other) { setPanel(other[0], other[1], false, false); });
                setPanel(pair[0], pair[1], open, !open);
            });
         });
         });
         document.addEventListener('keydown', function (event) {
         dialog.addEventListener('click', function (event) {
             if (event.key !== 'Escape') return;
             if (event.target !== dialog) return;
             // Let an inner MediaWiki dropdown close itself first.
             var bounds = dialog.getBoundingClientRect();
             if (header.querySelector('.vector-dropdown-checkbox:checked')) return;
             if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) dialog.close();
            pairs.forEach(function (pair) { if (!pair[0].hidden) setPanel(pair[0], pair[1], false, true); });
         });
         });
         document.addEventListener('click', function (event) {
         document.body.appendChild(dialog);
             if (!header.contains(event.target)) pairs.forEach(function (pair) { setPanel(pair[0], pair[1], false, false); });
        return true;
    }
    function openBook(book, trigger) {
        if (!ensureDialog()) return false;
        invoker = trigger;
        heading.textContent = book.title;
        content.replaceChildren();
        content.appendChild(node('p', 'vs-modal-intro', book.editions.length > 1 ? 'Choose the edition you wish to read.' : 'Read this edition or consult its sources.'));
        if (book.note) content.appendChild(node('p', 'vs-modal-note', book.note));
        var preferred = preferences()[book.id];
        book.editions.forEach(function (edition) {
            var row = node('div', 'vs-modal-edition');
            var description = node('div', 'vs-modal-edition-description');
            var title = node('h3', '', edition.label);
            description.appendChild(title);
             if (preferred === edition.url) description.appendChild(node('span', 'vs-modal-last-used', 'Last used'));
            description.appendChild(node('p', '', edition.title));
            var actions = node('div', 'vs-modal-actions');
            var read = node('a', 'vs-modal-read', 'Read edition →');
            read.href = edition.url;
            read.addEventListener('click', function () { remember(book.id, edition.url); });
            actions.appendChild(read);
            edition.pdf_links.forEach(function (url, index) {
                var pdf = node('a', 'vs-modal-pdf', 'PDF source' + (edition.pdf_links.length > 1 ? ' ' + (index + 1) : '') + ' ↗');
                pdf.href = url; pdf.target = '_blank'; pdf.rel = 'noopener noreferrer';
                actions.appendChild(pdf);
            });
            row.append(description, actions);
            content.appendChild(row);
         });
         });
         header.addEventListener('focusout', function () {
         if (book.related && book.related.length) {
             window.setTimeout(function () {
            var sources = node('details', 'vs-modal-more-sources');
                if (!header.contains(document.activeElement)) pairs.forEach(function (pair) { setPanel(pair[0], pair[1], false, false); });
             sources.appendChild(node('summary', '', 'Related publications and formats'));
             }, 0);
             book.related.forEach(function (publication) {
        });
                var item = node('div', 'vs-modal-related');
    }
                item.append(node('h3', '', publication.title), node('p', '', publication.note));
    function setupFooter() {
                var record = node('a', '', 'Publisher record ↗');
        if (document.getElementById('vs-site-footer')) return;
                record.href = publication.source; record.target = '_blank'; record.rel = 'noopener noreferrer';
        var footer = element('footer'); footer.id = 'vs-site-footer';
                item.appendChild(record);
        footer.append(navigation(petals, 'vs-footer-petals', 'Other petals'), navigation(siteLinks, 'vs-footer-links', 'Site links'));
                sources.appendChild(item);
        var invitation = element('p', 'vs-invitation');
             });
        invitation.appendChild(link('Collaborate with us to invoke and fully manifest Śrīla Prabhupāda’s Vani-presence', 'https://vaniseva.org'));
             content.appendChild(sources);
        footer.appendChild(invitation);
        }
        footer.appendChild(navigation([
        try {
             ['YouTube', 'https://www.youtube.com/@VanimediaPrabhupada'],
             dialog.showModal();
             ['Facebook', 'https://www.facebook.com/vanipedia.org'],
             document.documentElement.classList.add('vs-edition-modal-open');
             ['Facebook Group', 'https://www.facebook.com/groups/VanipediaGroup'],
            closeButton.focus();
             ['Instagram', 'https://www.instagram.com/vanipediaprabhupada/']
            return true;
        ], 'vs-footer-social', 'Social media'));
         } catch (e) { return false; }
         document.body.appendChild(footer);
     }
     }
     function init() {
     function init() {
         if (isMainView()) {
        var home = document.getElementById('vs-home');
             document.body.classList.add('vs-main-view');
         if (!home || home.dataset.vsPopupReady) return;
             initSearch();
        home.dataset.vsPopupReady = 'true';
             // Reserve dimensions even if the wiki renderer adds wrapper elements.
        home.querySelectorAll('.vs-book-card[data-vs-book]').forEach(function (card) {
             var photo = document.querySelector('#vs-portrait-frame img');
             var book = byId[card.dataset.vsBook];
             if (photo) { photo.width = 230; photo.height = 230; photo.decoding = 'async'; }
            if (!book) return;
        }
            card.querySelectorAll('a').forEach(function (link) {
        setupHeader(); setupFooter();
                if (book.editions.length > 1 || link.closest('.vs-book-action')) {
                    link.setAttribute('aria-haspopup', 'dialog');
                }
             });
        });
        home.addEventListener('click', function (event) {
             var link = event.target.closest('a');
             var card = link && link.closest('.vs-book-card[data-vs-book]');
             if (!card || !home.contains(card)) return;
            var book = byId[card.dataset.vsBook];
            if (!book) return;
            // Modified clicks keep ordinary link behaviour, including new tabs.
            if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
            if (book.editions.length === 1 && !link.closest('.vs-book-action')) {
                remember(book.id, book.editions[0].url);
                return;
            }
            if (openBook(book, link)) event.preventDefault();
        });
     }
     }
     mw.loader.using(['mediawiki.util']).then(function () {
     $(init);
        if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init, { once: true });
    mw.hook('wikipage.content').add(init);
        else init();
        mw.hook('wikipage.content').add(init);
    });
})();
})();

Latest revision as of 09:23, 12 October 2026

/* INSTALL ONLY IN MediaWiki:Common.js — Vanisource V15 */
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
/* Any JavaScript here will be loaded for all users on every page load. */

if (mw.config.get('wgPageName' ) === 'Krishna_says_in_Bhagavad-gita') { 
  /* switch tooltip texts from content-div to label-div */
  const v_labels = Array.from(document.getElementsByClassName("tabs-label"));
  const v_content = Array.from(document.getElementsByClassName("tabs-content"));
  for (var i = 0; i < v_labels.length; i++) {
    v_labels[i].title = v_content[i].title;
    v_content[i].title = "";
  }
  /* adjust wikitables */
  var arr = Array.from(document.getElementsByClassName("wikitable"));
  for (var t = 0; t < arr.length; t++) {
    /* insert THEAD in wikitable */
    var thead = document.createElement("thead");
    thead.style.display = "block";
    var wtbl = arr[t];
    wtbl.insertBefore(thead, wtbl.firstChild);
    /* move first row of TBODY to THEAD */
    thead.appendChild(wtbl.rows[0]);
    /* make TBODY scrollable */
    var tbody = wtbl.tBodies[0];
    tbody.style.display = "block";
    tbody.style.overflowY = "auto";
    tbody.style.maxHeight = "500px";    
    for (var r = 0; r < wtbl.rows.length; r++) {
      var row = wtbl.rows[r];
      /* adjust column widths and hide from-until columns */
      row.cells[0].classList = "cw_0";
      row.cells[1].classList = "cw_150";
      row.cells[2].classList = "cw_500";
      /* mark the text */ 
      if (r == 0) continue;
      var v_text = row.cells[2].textContent;
      var v_html = ""; var v_from = 0;
      var marks = JSON.parse(row.cells[0].textContent.replaceAll("O", "[").replaceAll("C", "]"));
      for (var m = 0; m < marks.length; m++) {
        v_html += 
          v_text.substr(v_from,marks[m][0]-v_from) + "<mark>" +
          v_text.substr(marks[m][0],marks[m][1]-marks[m][0]+1) + "</mark>";
        v_from = marks[m][1]+1;
      }
      v_html += v_text.substr(v_from);
      row.cells[2].innerHTML = v_html;
    }
  }
}

// install Google Search
// document.write('<script type="text/javascript" src="'
// + 'http://vanipedia.org/w/index.php?title=MediaWiki:GoogleSearch.js'
// + '&action=raw&ctype=text/javascript"></' + 'script>');

// install JQuery
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:JQuery.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');

// install WikEd toolbar and Vanify
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:Vaniquotes.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');
 
// install Replace
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:TextboxReplace.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');
 
// install Unify
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:Unify.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');
 
// install Vanify
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:Vanify.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');

// install Vani_suggest for diacritics auto-suggest pulldown on the search bar
//document.write('<script type="text/javascript" src="'
//+ 'http://vanipedia.org/w/index.php?title=MediaWiki:Vani_suggest.js'
//+ '&action=raw&ctype=text/javascript"></' + 'script>');

// install previous/next links for video categories in all languages
 //document.write('<script type="text/javascript" src="/navcat/navcat.js"></' + 'script>');
 
// Buttons
 
//addOnloadHook(function() {
 
//if (document.editform) {
//addPortletLink("p-cactions", "javascript:Unify()", "unify", "ca-unify", "Convert Balarama fonts to Unicode", "");
// addPortletLink("p-cactions", "javascript:Vanify()", "vanify", "ca-vanify", "Corrects vani markup", "");
// addPortletLink('p-cactions', 'javascript:format()', 'format', 'ca-format', 'Format article', '');
//addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace', 'Replaces text in the edit window', 'R');
//}
//});
 
// end Buttons

// --- YouTube Random Shorts (Kasya) ---
$(document).ready(function() {
    var $widget = $('.vani-shorts-viewport');
    
    if ($widget.length) {
        var $viewport = $widget;
        var $titleFrame = $widget.find('.vani-shorts-title');
        
        new mw.Api().get({
            action: 'query',
            prop: 'revisions',
            titles: 'VanimediaMayapur YouTube SHORTS List',
            rvprop: 'content',
            format: 'json'
        }).done(function(data) {
            try {
                var pages = data.query.pages;
                var pageId = Object.keys(pages)[0];
                
                if (pageId == "-1" || !pages[pageId].revisions) {
                    $viewport.text("Database list page not found.");
                    return;
                }
                
                // FIXED: Corrected MediaWiki revision array syntax lookup
                var rawWikiText = pages[pageId].revisions[0]['*'];
                var lines = rawWikiText.split('\n');
                var validShorts = [];
                
                for (var i = 0; i < lines.length; i++) {
                    var line = $.trim(lines[i]);
                    if (line.indexOf('File:') === 0 && line.toLowerCase().indexOf('link=') !== -1) {
                        validShorts.push(line);
                    }
                }
                
                if (validShorts.length === 0) {
                    $viewport.text("No gallery entries recognized.");
                    return;
                }
                
                var randomLine = validShorts[Math.floor(Math.random() * validShorts.length)];
                var parts = randomLine.split('|');
                
                // Reset defaults before parsing line elements
                var rawUrl = "";
                
                for (var j = 0; j < parts.length; j++) {
                    var part = $.trim(parts[j]);
                    
                    if (part.toLowerCase().indexOf('link=') === 0) {
                        rawUrl = part.substring(5).trim();
                    }
                }
                
                // Clean all template formatting brackets, space characters, and hidden control markers
                var urlCleaned = rawUrl.replace(/[\u200e\u200f\s\}\}\]]/g, ''); 
                
                // Direct YouTube Alphanumeric Pattern Matcher
                var idRegex = /(?:shorts\/|v=|embed\/|\/)([a-zA-Z0-9_-]{11})/;
                var matchResults = urlCleaned.match(idRegex);
                var videoId = "";
                
                if (matchResults && matchResults[1]) {
                    // FIXED: Grabbed index 1 to pull the standalone 11-digit ID without any slashes
                    videoId = matchResults[1].trim();
                }
                
                if (videoId && videoId.length === 11) {
                    // FIXED: Isolated to inject ONLY the video player iframe at the correct 280px width
                   var embedUrl = "https://www.youtube.com/embed/" + videoId;

                    $viewport.html('<iframe width="280" height="225" src="' + embedUrl + '" frameborder="0" allowfullscreen style="border-radius: 8px; border: none;"></iframe>');
                } else {
                    $viewport.html("<div style='color:#c0392b; padding:10px; font-size:11px;'>Invalid video ID sequence extracted.</div>");
                }
                
            } catch (err) {
                console.error("Shorts engine exception:", err);
                $viewport.text("Error handling text structure values.");
            }
        }).fail(function() {
            $viewport.text("API connection failed.");
        });
    }
});

// Kasya
/* Open Timeline links in a new tab ONLY on the Chapters page */
mw.hook('wikipage.content').add(function($content) {
    // Check if we are exactly on the timeline page
    if (mw.config.get('wgPageName') === "Chapters_in_Srila_Prabhupada's_Life") {
        
        // If yes, apply the new tab rule to the table
        $content.find('#mp-tfp a').attr('target', '_blank').attr('rel', 'noopener noreferrer');
    }
});

// Wait for MediaWiki core modules and the DOM to load
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
    $(document).ready(function () {
        
// 1. FIND THE "102 Languages" SIDEBAR SECTION
        var $sidebarMenu = $('#p-102_Languages ul').first();
        
        // Fallback in case your specific MediaWiki version formats the ID differently
        if ($sidebarMenu.length === 0) {
            $('.vector-menu-heading, .portal h3').each(function() {
                // Looks for the heading text directly
                if ($(this).text().trim() === '102 Languages') {
                    $sidebarMenu = $(this).closest('.vector-menu, .portal').find('ul').first();
                }
            });
        }
        
        // Exit if the 102 Languages menu isn't found on the page
        if (!$sidebarMenu || $sidebarMenu.length === 0) return;

        // 2. CREATE THE SEARCH BAR AS A MENU ITEM
        var $searchLi = $('<li id="n-language-search" style="margin-top: 10px; margin-bottom: 5px; list-style: none;"></li>');
        var $searchBox = $('<input type="text" id="sidebarLanguageSearch" placeholder="Search 102 Languages..." style="width: 100%; box-sizing: border-box; padding: 5px; font-size: 0.85em; border: 1px solid #a2a9b1; border-radius: 2px;" autocomplete="off" />');
        
        // Container for the results (hidden by default)
        var $resultsContainer = $('<ul id="sidebarLanguageResults" style="list-style: none; padding: 0; margin: 4px 0 0 0; max-height: 200px; overflow-y: auto; border: 1px solid #eaecf0; background: #ffffff; display: none;"></ul>');

        // Build the menu item and append it to the sidebar
        $searchLi.append($searchBox).append($resultsContainer);
        $sidebarMenu.prepend($searchLi); 

        var api = new mw.Api();
        var languageList = [];

        // 3. FETCH LANGUAGES FROM THE CATEGORY VIA API IN THE BACKGROUND
        api.get({
            action: 'query',
            list: 'categorymembers',
            cmtitle: 'Category:Languages_with_Total_Pages',
            cmlimit: 'max', 
            format: 'json'
        }).done(function (data) {
            if (data.query && data.query.categorymembers) {
                languageList = data.query.categorymembers.map(function (member) {
                    return {
                        title: member.title,
                        url: mw.util.getUrl(member.title) 
                    };
                });
            }
        });

        // 4. ADD SEARCH FUNCTIONALITY TO THE SIDEBAR BOX
        $('#sidebarLanguageSearch').on('keyup', function (e) {
            e.stopPropagation(); 
            var searchTerm = $(this).val().toLowerCase();
            $resultsContainer.empty();

            // Hide the results box if the search is empty
            if (searchTerm.length === 0) {
                $resultsContainer.hide();
                return; 
            }

            // Filter the fetched languages
            var filteredLanguages = languageList.filter(function (lang) {
                return lang.title.toLowerCase().indexOf(searchTerm) > -1;
            });

            // Show results container
            $resultsContainer.show();

            // Append results using Vector's standard dark text color
            if (filteredLanguages.length > 0) {
                filteredLanguages.forEach(function (lang) {
                    $resultsContainer.append('<li style="padding: 4px 6px; border-bottom: 1px solid #f8f9fa;"><a href="' + lang.url + '" style="text-decoration: none; color: #0645ad; display: block; font-size: 0.9em;">' + lang.title + '</a></li>');
                });
            } else {
                $resultsContainer.append('<li style="padding: 4px 6px; color: #72777d; font-size: 0.9em;">No languages found</li>');
            }
        });

        // Prevent typing from accidentally triggering global keyboard shortcuts
        $('#sidebarLanguageSearch').on('keydown', function(e) {
            e.stopPropagation();
        });
        
        // Optional: Hide results when clicking outside the sidebar search
        $(document).on('click', function(e) {
            if (!$(e.target).closest('#n-language-search').length) {
                $resultsContainer.hide();
            }
        });
        
        // Re-show results if they click back into the search box
        $('#sidebarLanguageSearch').on('click', function() {
            if ($(this).val().length > 0) {
                $resultsContainer.show();
            }
        });
        
    });
});

// 5. SIDEBAR ACCORDION - STRICT LEFT-COLUMN ISOLATION & TRUE ACCORDION
(function() {
    // 1. Tag ONLY menus physically located in the left sidebar
    function tagSidebarMenus() {
        var allMenus = document.querySelectorAll('.vector-menu');
        for (var i = 0; i < allMenus.length; i++) {
            var menu = allMenus[i];
            
            // STRICT INCLUSION: Only tag menus inside the modern or legacy left sidebar containers
            if (!menu.closest('#vs-site-header') && menu.closest('#vector-main-menu, #mw-panel, #mw-navigation')) {
                menu.classList.add('vanipedia-sidebar-menu');
                
                // Collapse them by default if they have a heading
                if (menu.querySelector('.vector-menu-heading') && !menu.classList.contains('vanipedia-collapsed')) {
                    menu.classList.add('vanipedia-collapsed');
                }
            }
        }
    }
    
    // Run tagging immediately, and again on load as a failsafe
    tagSidebarMenus();
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', tagSidebarMenus);
    }

    // 2. Inject CSS targeted STRICTLY at our newly tagged custom class
    var style = document.createElement('style');
    style.textContent = 
        /* Widen only our tagged sidebar menus */
        '.vanipedia-sidebar-menu { width: 185px !important; } ' + 
        
        /* Core functional hiding rule */
        '.vanipedia-sidebar-menu.vanipedia-collapsed .vector-menu-content { display: none !important; } ' + 
        
        /* Bold, Dark Header */
        '.vanipedia-sidebar-menu .vector-menu-heading { ' +
        '   cursor: pointer !important; ' +
        '   background-color: #2c4c50 !important; ' +     
        '   border: 1px solid #1b3033 !important; ' +     
        '   border-radius: 4px !important; ' +            
        '   margin-bottom: 4px !important; ' +            
        '   padding: 10px 12px !important; ' +
        '   font-weight: 600 !important; ' +
        '   color: #ffffff !important; ' +                
        '   display: flex !important; ' +
        '   justify-content: space-between !important; ' + 
        '   align-items: center !important; ' +
        '   gap: 10px !important; ' + 
        '   transition: all 0.2s ease; ' +
        '} ' +
        
        /* Fix header corners when expanded */
        '.vanipedia-sidebar-menu:not(.vanipedia-collapsed) .vector-menu-heading { ' +
        '   border-radius: 4px 4px 0 0 !important; ' +
        '   margin-bottom: 0 !important; ' +
        '} ' +
        
        /* Hover effect */
        '.vanipedia-sidebar-menu .vector-menu-heading:hover { background-color: #385e63 !important; } ' +
        
        /* The dropdown caret */
        '.vanipedia-sidebar-menu .vector-menu-heading::after { ' +
        '   content: "▼"; ' + 
        '   font-size: 0.75em; ' +
        '   color: #ffffff !important; ' +
        '   transition: transform 0.2s ease; ' +
        '} ' +
        
        /* Rotate the arrow when collapsed */
        '.vanipedia-sidebar-menu.vanipedia-collapsed .vector-menu-heading::after { ' +
        '   transform: rotate(-90deg); ' +
        '} ' +

        /* The Expanded Content Area */
        '.vanipedia-sidebar-menu .vector-menu-content { ' +
        '   background-color: #eaeff0 !important; ' +     
        '   border: 1px solid #2c4c50 !important; ' +     
        '   border-top: none !important; ' +              
        '   border-radius: 0 0 4px 4px !important; ' +    
        '   padding: 0 0 4px 0 !important; ' + 
        '   margin-bottom: 6px !important; ' +            
        '   box-shadow: 0 3px 6px rgba(0,0,0,0.15) !important; ' + 
        '} ' +

        /* Reset the list styles */
        '.vanipedia-sidebar-menu .vector-menu-content ul { ' +
        '   list-style: none !important; ' +
        '   margin: 0 !important; ' +
        '   padding: 0 !important; ' +
        '} ' +

        /* Menu links */
        '.vanipedia-sidebar-menu .vector-menu-content li a { ' +
        '   display: block !important; ' +                
        '   padding: 8px 12px 8px 16px !important; ' +    
        '   color: #1b3033 !important; ' +                
        '   text-decoration: none !important; ' +         
        '   border-left: 3px solid transparent !important; ' + 
        '   border-bottom: 1px solid rgba(44, 76, 80, 0.1) !important; ' + 
        '   transition: all 0.15s ease !important; ' +
        '} ' +
        
        /* Remove separator from last item */
        '.vanipedia-sidebar-menu .vector-menu-content li:last-child a { ' +
        '   border-bottom: none !important; ' +
        '} ' +

        /* Hover effect for individual menu items */
        '.vanipedia-sidebar-menu .vector-menu-content li a:hover { ' +
        '   background-color: #dbe4e6 !important; ' +     
        '   border-left: 3px solid #2c4c50 !important; ' + 
        '   color: #000000 !important; ' +                
        '} ';
        
    document.head.appendChild(style);

    // 3. Helper function to collapse all of our securely tagged menus
    function collapseAllSidebarMenus() {
        var menus = document.querySelectorAll('.vanipedia-sidebar-menu');
        for (var i = 0; i < menus.length; i++) {
            menus[i].classList.add('vanipedia-collapsed');
        }
    }

    // 4. Intercept clicks for True Accordion Behavior
    document.addEventListener('click', function(e) {
        var heading = e.target.closest('.vector-menu-heading');
        if (!heading) return;

        // ONLY react if this click belongs to one of our tagged sidebar menus
        var navContainer = heading.closest('.vanipedia-sidebar-menu');
        if (navContainer) {
            var isAlreadyOpen = !navContainer.classList.contains('vanipedia-collapsed');
            
            // Forcefully collapse ALL left sidebar menus first
            collapseAllSidebarMenus();

            // Open the clicked one if it wasn't already open
            if (!isAlreadyOpen) {
                navContainer.classList.remove('vanipedia-collapsed');
            }
            
            e.stopPropagation();
            e.preventDefault();
        }
    }, true);
})();

mw.loader.using('mediawiki.user').then(function() {
    // Fetch the user's assigned groups
    var userGroups = mw.config.get('wgUserGroups') || [];
    
    // Define the roles that SHOULD see the administrative tabs
    var isAuthorized = userGroups.includes('sysop') || 
                       userGroups.includes('interface-admin') || 
                       userGroups.includes('Editor');
                       
    // If the user is not in one of those groups, restrict the UI
    if (!isAuthorized) {
        document.body.classList.add('restricted-ui');
    }
});

// Function to open accordion from TOC and jump there //

mw.hook('wikipage.content').add(function() {
    
    function handleAccordionTOC(hash) {
        if (!hash || hash === '#') return false;
        
        try {
            var targetId = hash.substring(1);
            var targetElement = document.getElementById(targetId) || document.getElementById(decodeURIComponent(targetId));
            
            if (!targetElement) return false;

            var $target = $(targetElement);
            // Match either h2 or h3
            var $heading = $target.is('h2, h3') ? $target : $target.closest('h2, h3');
            
            if (!$heading.length) return false;

            var $accordion = $heading.next('.book-accordion');
            
            // If the heading itself is not followed directly by an accordion, 
            // check if the heading is located INSIDE a parent accordion (e.g., nested h3)
            var $parentAccordions = $heading.parents('.book-accordion');

            // If there's no direct accordion next to it and it's not inside any accordion,
            // let the browser handle standard jump.
            if (!$accordion.length && !$parentAccordions.length) return false;

            // 1. Open all ancestor accordions (if target heading is nested inside one)
            $parentAccordions.each(function() {
                var $parentCollapsible = $(this).children('.mw-collapsible');
                if ($parentCollapsible.length && $parentCollapsible.hasClass('mw-collapsed')) {
                    var pId = $parentCollapsible.attr('id');
                    if (pId) {
                        var pToggleClass = pId.replace('mw-customcollapsible-', 'mw-customtoggle-');
                        $('.' + pToggleClass).first().click();
                    }
                }
            });

            // 2. Open the accordion immediately following this heading (if present)
            if ($accordion.length) {
                var $collapsible = $accordion.children('.mw-collapsible, .mw-collapsible-content').first();
                if (!$collapsible.length) {
                    $collapsible = $accordion.find('.mw-collapsible');
                }
                
                if ($collapsible.length && $collapsible.hasClass('mw-collapsed')) {
                    var collapsibleId = $collapsible.attr('id'); 
                    if (collapsibleId) {
                        var toggleClass = collapsibleId.replace('mw-customcollapsible-', 'mw-customtoggle-');
                        $('.' + toggleClass).first().click();
                    }
                }
            }

            // Target element to scroll to (the accordion, or the heading itself if accordion is missing)
            var $scrollTarget = $accordion.length ? $accordion : $heading;

            // 3. Scroll to the visible section
            setTimeout(function() {
                $('html, body').animate({
                    scrollTop: $scrollTarget.offset().top - 75
                }, 300);
            }, 100);

            // Return true to indicate we successfully handled the TOC accordion click
            return true;

        } catch (e) {
            console.error("TOC Accordion script error:", e);
            return false;
        }
    }

    $(document).off('click.tocAccordion').on('click.tocAccordion', 'a[href^="#"]', function(e) {
        if ($(this).closest('#toc, .toc, .vector-toc').length > 0) {
            var href = $(this).attr('href');
            
            // Run our function to see if this is an accordion/heading link
            var isAccordion = handleAccordionTOC(href);
            
            // ONLY stop the default browser jump if we handled it
            if (isAccordion) {
                e.preventDefault(); 
                
                // Update the URL manually so the user can still share the link
                if (history.pushState) {
                    history.pushState(null, null, href);
                } else {
                    window.location.hash = href;
                }
            }
        }
    });

    if (window.location.hash) {
        setTimeout(function() {
            handleAccordionTOC(window.location.hash);
        }, 500);
    }
});

/* Sticky burger menu - Pure Floating Dropdown (Forces Unpinned & Full Title) */
(function () {
    let isMenuOpen = false;

    // 1. Force the sidebar out of pinned mode and return menu into the dropdown container
    function forceUnpinSidebar() {
        document.documentElement.classList.remove('vector-feature-main-menu-pinned-enabled', 'vector-feature-main-menu-pinned-clientpref-1');
        document.documentElement.classList.add('vector-feature-main-menu-pinned-disabled', 'vector-feature-main-menu-pinned-clientpref-0');
        if (document.body) {
            document.body.classList.remove('vector-feature-main-menu-pinned-enabled', 'vector-feature-main-menu-pinned-clientpref-1');
            document.body.classList.add('vector-feature-main-menu-pinned-disabled', 'vector-feature-main-menu-pinned-clientpref-0');
        }

        // Clear stored pin preference
        document.cookie = "vector-feature-main-menu-pinned=0; path=/; max-age=31536000";
        try { localStorage.setItem('vector-feature-main-menu-pinned', '0'); } catch(e) {}

        // If #vector-main-menu was moved into the pinned container, move it back into dropdown
        const mainMenu = document.getElementById('vector-main-menu');
        const unpinnedContainer = document.getElementById('vector-main-menu-unpinned-container') || 
                                  document.querySelector('#vector-main-menu-dropdown .vector-dropdown-content');
        const pinnedContainer = document.getElementById('vector-main-menu-pinned-container');

        if (mainMenu && unpinnedContainer && pinnedContainer && pinnedContainer.contains(mainMenu)) {
            unpinnedContainer.appendChild(mainMenu);
        }
    }

    function getDropdownElement() {
        return document.querySelector('#vector-main-menu-dropdown .vector-dropdown-content') || 
               document.getElementById('vector-main-menu-dropdown-content') ||
               document.getElementById('vector-main-menu-unpinned-container') ||
               document.getElementById('vector-main-menu');
    }

    function openMenu(menuBtn) {
        forceUnpinSidebar();

        const checkbox = document.getElementById('vector-main-menu-dropdown-checkbox');
        const dropdown = getDropdownElement();
        if (!dropdown) return;

        if (checkbox) {
            checkbox.checked = true;
            checkbox.dispatchEvent(new Event('change', { bubbles: true }));
        }

        const rect = menuBtn.getBoundingClientRect();
        dropdown.style.setProperty('position', 'fixed', 'important');
        dropdown.style.setProperty('top', rect.bottom + 'px', 'important');
        dropdown.style.setProperty('left', rect.left + 'px', 'important');
        dropdown.style.setProperty('z-index', '99999', 'important');
        dropdown.style.setProperty('max-height', (window.innerHeight - rect.bottom - 16) + 'px', 'important');
        dropdown.style.setProperty('overflow-y', 'auto', 'important');
        dropdown.style.setProperty('display', 'block', 'important');
        dropdown.style.setProperty('visibility', 'visible', 'important');
        dropdown.style.setProperty('opacity', '1', 'important');
        dropdown.style.setProperty('background-color', 'var(--background-color-base, #ffffff)', 'important');
        dropdown.style.setProperty('box-shadow', '0 4px 16px rgba(0, 0, 0, 0.2)', 'important');
        dropdown.style.setProperty('border-radius', '4px', 'important');

        isMenuOpen = true;
    }

    function closeMenu() {
        const checkbox = document.getElementById('vector-main-menu-dropdown-checkbox');
        const dropdown = getDropdownElement();
        if (!dropdown) return;

        if (checkbox) {
            checkbox.checked = false;
            checkbox.dispatchEvent(new Event('change', { bubbles: true }));
        }

        dropdown.style.removeProperty('position');
        dropdown.style.removeProperty('top');
        dropdown.style.removeProperty('left');
        dropdown.style.removeProperty('z-index');
        dropdown.style.removeProperty('max-height');
        dropdown.style.removeProperty('overflow-y');
        dropdown.style.removeProperty('background-color');
        dropdown.style.removeProperty('box-shadow');
        dropdown.style.removeProperty('border-radius');
        dropdown.style.setProperty('display', 'none', 'important');
        dropdown.style.setProperty('visibility', 'hidden', 'important');
        dropdown.style.setProperty('opacity', '0', 'important');

        isMenuOpen = false;
    }

    function initStickyBurger() {
        forceUnpinSidebar();

        const stickyHeader = document.getElementById('vector-sticky-header');
        if (!stickyHeader) return false;
        if (document.getElementById('vanipedia-sticky-main-menu')) return true;

        // 1. Create burger button
        const menuBtn = document.createElement('div');
        menuBtn.id = 'vanipedia-sticky-main-menu';
        menuBtn.title = 'Main menu';
        menuBtn.style.cursor = 'pointer'; 
        menuBtn.className = 'vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--icon-only';

        // 2. Add hamburger icon
        const iconSpan = document.createElement('span');
        iconSpan.className = 'vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu'; 
        menuBtn.appendChild(iconSpan);

        // 3. Toggle click handler (1st click opens, 2nd click rolls back)
        menuBtn.addEventListener('click', function (e) {
            e.preventDefault();
            e.stopPropagation();

            if (isMenuOpen) {
                closeMenu();
            } else {
                openMenu(menuBtn);
            }
        });

        // 4. Inject into start container
        let startContainer = stickyHeader.querySelector('.vector-sticky-header-start');
        if (!startContainer) {
            startContainer = document.createElement('div');
            startContainer.className = 'vector-sticky-header-start';
            stickyHeader.insertBefore(startContainer, stickyHeader.firstChild);
        }
        
        startContainer.insertBefore(menuBtn, startContainer.firstChild);
        return true;
    }

    // 5. Close when clicking anywhere outside
    document.addEventListener('click', function (e) {
        if (!isMenuOpen) return;
        const menuBtn = document.getElementById('vanipedia-sticky-main-menu');
        const dropdown = getDropdownElement();
        if (dropdown && menuBtn && !menuBtn.contains(e.target) && !dropdown.contains(e.target)) {
            closeMenu();
        }
    });

    // 6. Bootstrap initializer
    if (!initStickyBurger()) {
        const checkTimer = setInterval(function () {
            if (initStickyBurger()) {
                clearInterval(checkTimer);
            }
        }, 100);
        setTimeout(function () { clearInterval(checkTimer); }, 4000);
    }

    mw.hook('wikipage.content').add(initStickyBurger);
    $(initStickyBurger);
})();


/* Floating "Back to Top" Button Controller */
(function () {
    function initBackToTop() {
        if (document.getElementById('vanipedia-back-to-top')) return;

        // 1. Create button element with an up-arrow SVG icon
        const btn = document.createElement('button');
        btn.id = 'vanipedia-back-to-top';
        btn.title = 'Back to top';
        btn.setAttribute('aria-label', 'Back to top');
        
        btn.innerHTML = `
            <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                <polyline points="18 15 12 9 6 15"></polyline>
            </svg>
        `;

        // 2. Smooth scroll to top on click
        btn.addEventListener('click', function (e) {
            e.preventDefault();
            window.scrollTo({ top: 0, behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' });
        });

        // 3. Show button only after scrolling down 300px
        function toggleVisibility() {
            if (window.scrollY > 300) {
                btn.classList.add('visible');
            } else {
                btn.classList.remove('visible');
            }
        }

        window.addEventListener('scroll', toggleVisibility, { passive: true });
        toggleVisibility();

        document.body.appendChild(btn);
    }

    $(initBackToTop);
    mw.hook('wikipage.content').add(initBackToTop);
})();

});


mw.loader.using(["mediawiki.util"]).then(function () {
(function() {
var titleText = "VANISOURCE - BOOKS · LETTERS · LECTURES · CONVERSATIONS";
var targetUrl = "/wiki/Main_Page";
function removeGlobalSiteNotice() {
$('#siteNotice, #localNotice, .vector-sitenotice-container, #mainbanner, .sitenotice, .mw-sitenotice, .anonnotice, .dismissable-notice, #centralNotice').remove();
}
function createHomeLink() {
var homeSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>';
return $('<a>', {
id: 'vanipedia-topbar-home-link',
href: 'https://dev.vanipedia.org/',
title: 'Vanipedia Home / Entry Portal',
'aria-label': 'Home',
class: 'vanipedia-topbar-home'
}).html('<span class="vanipedia-home-icon">' + homeSvg + '</span><span class="vanipedia-home-text">Home</span>');
}
function createCenterBlock() {
var blockStyle = 'position:absolute !important; left:50% !important; top:54% !important; transform:translate(-50%, -50%) !important; display:flex !important; flex-direction:column !important; align-items:center !important; justify-content:center !important; text-align:center !important; white-space:nowrap !important; z-index:10 !important; pointer-events:auto !important;';
var titleStyle = 'position:static !important; transform:none !important; display:block !important; font-family:"Cinzel", Georgia, serif !important; font-size:18px !important; font-weight:700 !important; letter-spacing:2px !important; color:#f5d77f !important; text-decoration:none !important; text-shadow:0 2px 4px rgba(0,0,0,0.9), 0 0 10px rgba(245,215,127,0.3) !important; line-height:1.25 !important; margin:0 0 4px 0 !important; padding:0 !important; user-select:text !important;';
var vanisevaWrapStyle = 'position:static !important; transform:none !important; display:block !important; margin:0 0 4px 0 !important; line-height:1.2 !important;';
var vanisevaLinkStyle = 'color:#fff2c4 !important; font-family:"Noto Serif", Georgia, serif !important; font-size:12.5px !important; font-style:normal !important; font-weight:500 !important; letter-spacing:0.35px !important; text-decoration:none !important; border:1px solid rgba(223,173,62,0.35) !important; background:rgba(245,215,127,0.08) !important; outline:none !important; padding:2px 14px !important; border-radius:12px !important; cursor:pointer !important; display:inline-block !important; transition:all 0.18s ease !important;';
var sisterWrapStyle = 'position:static !important; transform:none !important; display:flex !important; align-items:center !important; justify-content:center !important; gap:14px !important; margin:0 !important; line-height:1.2 !important;';
var sisterLinkStyle = 'color:#f5d77f !important; font-family:"Noto Serif", Georgia, serif !important; font-size:13px !important; font-weight:600 !important; letter-spacing:0.4px !important; text-decoration:none !important; border:none !important; border-bottom:none !important; outline:none !important; padding:2px 8px !important; border-radius:3px !important; display:inline-flex !important; align-items:center !important; cursor:pointer !important; transition:all 0.18s ease !important;';
var sepStyle = 'color:rgba(245,215,127,0.4) !important; font-size:11px !important; line-height:1 !important; user-select:none !important;';
var $block = $('<div>', {
id: 'vanipedia-topbar-center-block',
class: 'vanipedia-topbar-center-block',
style: blockStyle
});
var $title = $('<div>', {
id: 'vanipedia-topbar-title',
class: 'vanipedia-topbar-main-title',
style: titleStyle,
text: titleText
});
var $vaniseva = $('<div>', {
class: 'vanipedia-topbar-vaniseva-title',
style: vanisevaWrapStyle
}).html('<a href="https://vaniseva.org" target="_blank" rel="noopener noreferrer" title="Vaniseva" style="' + vanisevaLinkStyle + '">Collaborate with us to invoke and fully manifest Śrīla Prabhupāda&#39;s Vani-presence</a>');
var $sisterLinks = $('<div>', {
class: 'vanipedia-topbar-sister-links',
style: sisterWrapStyle
}).html(
'<a href="https://vanipedia.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vanipedia" style="' + sisterLinkStyle + '">vanipedia.org</a>' +
'<span class="vanipedia-topbar-sister-sep" aria-hidden="true" style="' + sepStyle + '">•</span>' +
'<a href="https://vaniquotes.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vaniquotes" style="' + sisterLinkStyle + '">vaniquotes.org</a>' +
'<span class="vanipedia-topbar-sister-sep" aria-hidden="true" style="' + sepStyle + '">•</span>' +
'<a href="https://vanimedia.org" target="_blank" rel="noopener noreferrer" class="vanipedia-topbar-sister-link" title="Vanimedia" style="' + sisterLinkStyle + '">vanimedia.org</a>'
);
$block.append($title, $vaniseva, $sisterLinks);
return $block;
}
function updateTopBar() {
removeGlobalSiteNotice();
$('#vanipedia-topbar-center-block, #vanipedia-topbar-center-block-mobile, #vanipedia-topbar-title, #vanipedia-topbar-title-mobile, #vanipedia-topbar-title-link, #vanipedia-topbar-center-title, #vanipedia-topbar-home-link, #vanipedia-topbar-sister-links, #vanipedia-topbar-sister-links-mobile, .vanipedia-topbar-sister-links, .vanipedia-topbar-center-block').remove();
$('.vector-header-container').css({
'background': 'transparent',
'background-color': 'transparent',
'border': 'none',
'box-shadow': 'none',
'padding': '0',
'margin': '0',
'min-height': '0',
'height': 'auto',
'width': '100%',
'max-width': '100%'
});
var isMobile = (window.innerWidth <= 999) || $('body').hasClass('skin-minerva') || $('body').hasClass('skin-vector-mobile') || $('.minerva-header').length > 0;
var $header = $('header.mw-header, header.vector-header').not('.minerva-header').first();
if (!$header.length && !$('body').hasClass('skin-minerva') && !$('.minerva-header').length) {
$header = $('#mw-head, header').not('.minerva-header').filter(':visible').first();
}
if ($header.length) {
$header.css({
'min-height': isMobile ? '52px' : '86px',
'height': isMobile ? '52px' : 'auto',
'max-height': isMobile ? '52px' : 'none',
'padding': isMobile ? '0 10px' : '10px 24px',
'background-color': '#345B63',
'border-bottom': '2px solid #b1873d',
'box-shadow': '0 4px 18px rgba(0,0,0,0.35)',
'position': 'relative',
'display': 'flex',
'flex-wrap': 'nowrap',
'align-items': 'center',
'justify-content': 'space-between',
'box-sizing': 'border-box',
'width': '100%',
'max-width': '100%'
});
if (!isMobile) {
$header.append(createCenterBlock());
}
var $search = $header.find('.vector-header-start #p-search, #p-search');
if ($search.length) {
$search.after(createHomeLink());
} else if ($header.find('.vector-header-start').length) {
$header.find('.vector-header-start').append(createHomeLink());
}
}
var $minervaHeader = $('.minerva-header');
if ($minervaHeader.length) {
// 1. Ensure "Vanipedia" Title Link exists with text in the branding box
var $branding = $minervaHeader.find('.branding-box');
if ($branding.length) {
var $brandLink = $branding.find('a');
if ($brandLink.length) {
if (!$brandLink.text().trim()) {
$brandLink.html('<span>Vanipedia</span>');
}
} else {
$branding.html('<a href="/wiki/Main_Page"><span>Vanipedia</span></a>');
}
} else {
var brandHtml = '<div class="branding-box"><a href="/wiki/Main_Page"><span>Vanipedia</span></a></div>';
var $burger = $minervaHeader.find('#mw-mf-main-menu-button, .navigation-drawer.toggle-list').first();
if ($burger.length) {
$burger.after(brandHtml);
} else {
$minervaHeader.prepend(brandHtml);
}
}
// 2. Ensure Home Link is inserted cleanly
var $minervaForm = $minervaHeader.find('.minerva-search-form, #searchform').first();
if ($minervaForm.length && !$minervaHeader.find('#vanipedia-topbar-home-link').length) {
$minervaForm.before(createHomeLink());
} else if (!$minervaHeader.find('#vanipedia-topbar-home-link').length) {
var $minervaUser = $minervaHeader.find('.minerva-user-navigation, #ca-mytalks').first();
if ($minervaUser.length) {
$minervaUser.before(createHomeLink());
} else {
$minervaHeader.append(createHomeLink());
}
}
$minervaHeader.css({
'flex-wrap': 'nowrap',
'height': '52px',
'min-height': '52px',
'max-height': '52px',
'padding': '0 10px',
'display': 'flex',
'align-items': 'center',
'justify-content': 'space-between',
'box-sizing': 'border-box'
});
}
var $stageHeader = $('#vani-stage-header-slot');
if ($stageHeader.length && !$stageHeader.find('.vanipedia-topbar-center-block').length) {
var $stageSearch = $stageHeader.find('#p-search, .search-box, .minerva-search-form').first();
if ($stageSearch.length && !$stageHeader.find('#vanipedia-topbar-home-link').length) {
$stageSearch.after(createHomeLink());
}
if (!isMobile) {
$stageHeader.append(createCenterBlock());
}
}
var $stickyTitle = $('#vector-sticky-header .vector-sticky-header-title, #vector-sticky-header .vector-sticky-header-context-bar .mw-headline');
if ($stickyTitle.length) {
$stickyTitle.html('<a href="' + targetUrl + '" style="color: inherit; text-decoration: none;">' + titleText + '</a>');
}
}
$(function() {
removeGlobalSiteNotice();
});
var topbarResizeTimer;
$(window).on('resize orientationchange', function() {
clearTimeout(topbarResizeTimer);
topbarResizeTimer = setTimeout(updateTopBar, 150);
});
$(document).ready(updateTopBar);
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(updateTopBar);
}
})();

(function initPermanentBottomBar() {
function isEntryPage() {
return (
document.body.classList.contains('ext-vp3d-fullscreen') ||
!!document.querySelector('.vp-entry3d-container') ||
!!document.querySelector('.vp-entry3d-wrapper') ||
window.location.pathname === '/' ||
(window.location.pathname === '/index.php' && !window.location.search) ||
(window.mw && mw.config && (mw.config.get('wgPageName') === 'Entry_Page' || mw.config.get('wgTitle') === 'Entry Page'))
);
}
function setupBottomBar() {
// Never inject on the 3D entry page; remove if already present
if (isEntryPage()) {
var existing = document.getElementById('vh-bottom-bar');
if (existing) existing.remove();
return;
}
if (document.getElementById('vh-bottom-bar')) return;
var bar = document.createElement('nav');
bar.id = 'vh-bottom-bar';
bar.className = 'vh-bottom-bar';
bar.setAttribute('aria-label', 'Vanisource Global Navigation');
bar.innerHTML =
'<div class="vh-bottom-bar-inner" style="display:flex !important; align-items:center !important; width:100% !important; max-width:100% !important; height:100% !important; padding:0 24px !important; box-sizing:border-box !important;">' +
'<div class="vh-bottom-bar-left-space" style="flex:1 1 0 !important; min-width:0 !important;"></div>' +
'<div class="vh-bottom-nav-links" style="flex:0 0 auto !important; display:flex !important; align-items:center !important; justify-content:center !important; gap:12px !important; white-space:nowrap !important;">' +
'<a href="https://dev.vanipedia.org/" class="vh-bottom-link vh-bottom-entry">Home</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="/wiki/Main_Page" class="vh-bottom-link vh-bottom-home">Main Page</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vanipedia_Vision" class="vh-bottom-link">Core Principles</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vaniseva" class="vh-bottom-link">Volunteer</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Vanipedia_Community" class="vh-bottom-link">Community</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/contact.php" target="_blank" rel="noopener noreferrer" class="vh-bottom-link">Contact</a>' +
'<span class="vh-bottom-sep" aria-hidden="true">•</span>' +
'<a href="https://dev.vanipedia.org/wiki/Special:IframePage" class="vh-bottom-link vh-bottom-donate">Donate</a>' +
'</div>' +
'<div class="vh-bottom-bar-right-space" style="flex:1 1 0 !important; min-width:0 !important; display:flex !important; align-items:center !important; justify-content:center !important;">' +
'<div class="vh-bottom-social-links" style="position:static !important; transform:none !important; display:inline-flex !important; align-items:center !important; gap:24px !important;">' +
'<a href="https://www.youtube.com/@VanimediaPrabhupada" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="YouTube" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/YouTube_Logo_B.png" alt="YouTube" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.facebook.com/vanipedia.org" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Facebook Page" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Facebook_Group_Logo.png" alt="Facebook" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.facebook.com/groups/VanipediaGroup" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Facebook Group" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Facebook_Logo_2023.png" alt="Facebook Group" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'<a href="https://www.instagram.com/vanipediaprabhupada/" target="_blank" rel="noopener noreferrer" class="vh-bottom-social-item" title="Instagram" style="display:inline-flex !important;align-items:center !important;">' +
'<img src="/wiki/Special:FilePath/Insta_Logo.png" alt="Instagram" style="height:20px !important;width:auto !important;vertical-align:middle !important;display:block !important;">' +
'</a>' +
'</div>' +
'</div>' +
'</div>';
var stageSlot = document.getElementById('vani-stage-footer-slot');
if (stageSlot) {
stageSlot.appendChild(bar);
} else {
document.body.appendChild(bar);
}
}
// Remove bar if 3D entry page activates asynchronously
if (window.MutationObserver && document.body) {
var observer = new MutationObserver(function() {
if (isEntryPage()) {
var existing = document.getElementById('vh-bottom-bar');
if (existing) existing.remove();
}
});
observer.observe(document.body, { attributes: true, attributeFilter: ['class'], childList: true });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setupBottomBar);
} else {
setupBottomBar();
}
})();

/* V7: wiki-native shell controls and one selection per page load. */
(function () {
    var selected = null;
    var passages = [
        { text: 'The self-realized soul is not bewildered by such a change.', title: 'Bhagavad-gītā 2.13 · 1972 edition', href: 'https://vanisource.org/wiki/BG_2.13_(1972)' },
        { text: 'Just try to learn the truth by approaching a spiritual master. Inquire from him submissively and render service unto him.', title: 'Bhagavad-gītā 4.34 · 1972 edition', href: 'https://vanisource.org/wiki/BG_4.34_(1972)' }
    ];
    function init() {
        var home = document.getElementById('vs-home');
        var action = mw.config.get('wgAction') || 'view';
        var main = !!home && (action === 'view' || action === 'purge');
        if (main) {
            document.body.classList.add('vs-main-view');
            var slot = document.getElementById('vs-search-slot');
            if (slot && !slot.querySelector('form')) {
                var form = document.createElement('form');
                form.className = 'vs-search'; form.method = 'get'; form.action = mw.config.get('wgScript') || '/w/index.php'; form.setAttribute('role','search');
                var hidden = document.createElement('input'); hidden.type='hidden'; hidden.name='title'; hidden.value='Special:Search';
                var label=document.createElement('label');label.htmlFor='vs-main-search';label.textContent='Search Vanisource';
                var input=document.createElement('input');input.type='search';input.name='search';input.id='vs-main-search';input.placeholder='Search Śrīla Prabhupāda’s teachings';
                var button=document.createElement('button');button.type='submit';button.textContent='Search';
                label.appendChild(input);form.append(hidden,label,button);slot.replaceChildren(form);
            }
            if (!selected) selected={passage:passages[Math.floor(Math.random()*passages.length)],photo:Math.floor(Math.random()*12)+1};
            if (!home.dataset.vsSelectionApplied) {
                home.dataset.vsSelectionApplied='true';
                var quote=home.querySelector('.vs-source-quote');var reference=home.querySelector('.vs-source-meta a');
                if (quote && reference) {quote.textContent='“'+selected.passage.text+'”';reference.textContent=selected.passage.title;reference.href=selected.passage.href;}
                var portrait=home.querySelector('#vs-portrait-frame img');
                if (portrait) {
                    var preload=new Image();
                    preload.onload=function(){if(portrait.isConnected){portrait.removeAttribute('srcset');portrait.removeAttribute('sizes');portrait.src=preload.src;}};
                    preload.src='/wiki/Special:Redirect/file/Srila-Prabhupada-Hero-'+String(selected.photo).padStart(2,'0')+'.jpg';
                }
            }
            // Keep the native menu reachable when the reading-area sidebars are hidden.
            var menu=document.getElementById('vector-main-menu');
            var unpinned=document.getElementById('vector-main-menu-unpinned-container') || document.querySelector('#vector-main-menu-dropdown .vector-dropdown-content');
            if(menu && unpinned && !unpinned.contains(menu)) unpinned.appendChild(menu);
        }
        var header=document.querySelector('header.vector-header, header.mw-header');
        var start=header && header.querySelector('.vector-header-start');
        var search=document.getElementById('p-search');
        if(start && search && !start.contains(search)) start.appendChild(search);
        var portal=document.getElementById('vanipedia-topbar-home-link');
        if(start && portal) start.appendChild(portal);
        document.querySelectorAll('#searchInput, input[name="search"]').forEach(function(input){
            if(input.id!=='vs-main-search') {input.placeholder='Search Vanisource';input.setAttribute('aria-label','Search Vanisource');}
        });
        // Label the real native menu toggle; its skin handlers remain in charge.
        var menuLabel=document.querySelector('#vector-main-menu-dropdown .vector-dropdown-label');
        if(menuLabel) menuLabel.setAttribute('aria-label','Main menu');
    }
    $(init);mw.hook('wikipage.content').add(init);
    var pending;
    $(window).on('resize orientationchange',function(){clearTimeout(pending);pending=setTimeout(init,200);});
})();

});

/* V12: place the live header outside the reading grid so sticky positioning
   lasts for the entire page, and reserve an anchor-scroll offset. */
(function () {
 function initStickyHeader() {
  var header=document.querySelector('header.vector-header, header.mw-header');
  if(!header)return;
  var container=header.closest('.vector-header-container') || header;
  if(container.parentElement!==document.body)document.body.insertBefore(container,document.body.firstChild);
  function updateOffset(){
   document.documentElement.style.setProperty('--vs-header-height',container.getBoundingClientRect().height+'px');
  }
  updateOffset();
  if(!container.dataset.vsStickyReady){
   container.dataset.vsStickyReady='true';
   if(window.ResizeObserver){var observer=new ResizeObserver(updateOffset);observer.observe(container);}
   else window.addEventListener('resize',updateOffset);
  }
 }
 $(initStickyHeader);
 mw.hook('wikipage.content').add(initStickyHeader);
})();

/* V13: the edition page works as a complete ordinary wiki page without JS.
   With JS, a book hash shows only that title. Native links/history remain. */
(function () {
    function showSelection(moveFocus) {
        var root = document.getElementById('vs-editions');
        if (!root) return;
        var action = mw.config.get('wgAction') || 'view';
        if (action !== 'view' && action !== 'purge') return;
        var fragment;
        try { fragment = decodeURIComponent(window.location.hash.slice(1)); }
        catch (e) { fragment = ':invalid-fragment:'; }
        var target = fragment ? document.getElementById(fragment) : null;
        var selected = target && root.contains(target) ? target.closest('.vs-edition-book') : null;
        var index = root.querySelector('.vs-edition-index');
        var books = root.querySelectorAll('.vs-edition-book');
        if (selected) {
            if (index) index.hidden = true;
            books.forEach(function (book) { book.hidden = book !== selected; });
        } else {
            // The title index stays compact with JS. Unknown hashes expose
            // all text so older chapter/book anchors never produce a blank page.
            if (index) index.hidden = false;
            var indexOnly = !!index && (!fragment || fragment === 'all-books');
            books.forEach(function (book) { book.hidden = indexOnly; });
        }
        if (moveFocus && selected) {
            selected.setAttribute('tabindex', '-1');
            selected.focus({ preventScroll: true });
            selected.scrollIntoView({ block: 'start', behavior: 'auto' });
        }
    }
    $(function () { showSelection(false); });
    mw.hook('wikipage.content').add(function () { showSelection(false); });
    window.addEventListener('hashchange', function () { showSelection(true); });
})();

/* V14: reuse native shared File references. If a dev thumbnail is missing,
   use the existing audited Vanimedia image; never duplicate/upload the file. */
(function () {
    function initSharedCovers() {
        document.querySelectorAll('#vs-home [data-vs-cover-source], #vs-editions [data-vs-cover-source]').forEach(function (frame) {
            var source = frame.dataset.vsCoverSource;
            var parsed;
            try { parsed = new URL(source); } catch (e) { return; }
            if (parsed.protocol !== 'https:' || parsed.hostname !== 'vanimedia.org' || !parsed.pathname.startsWith('/w/images/')) return;
            var image = frame.querySelector('img');
            if (!image) {
                // A transient repository lookup failure may yield a red File
                // link instead of an image. Keep the book navigation usable.
                image = document.createElement('img');
                image.alt = frame.dataset.vsCoverAlt || 'Representative book cover';
                var destination = frame.dataset.vsCoverLink;
                if (destination && (destination.startsWith('/wiki/Books_and_Editions#') || /^https:\/\/(?:www\.)?vanisource\.org\/wiki\//.test(destination))) {
                    var link = document.createElement('a');
                    link.href = destination;
                    link.appendChild(image);
                    frame.replaceChildren(link);
                } else {
                    frame.replaceChildren(image);
                }
                image.dataset.vsCoverFallback = 'true';
                image.src = source;
                return;
            }
            if (image.dataset.vsCoverReady) return;
            image.dataset.vsCoverReady = 'true';
            function fallback() {
                if (!image.isConnected || image.dataset.vsCoverFallback) return;
                image.dataset.vsCoverFallback = 'true';
                image.removeAttribute('srcset');
                image.removeAttribute('sizes');
                var picture = image.closest('picture');
                if (picture) picture.querySelectorAll('source').forEach(function (item) { item.remove(); });
                image.src = source;
            }
            image.addEventListener('error', fallback, { once: true });
            if (image.complete && image.naturalWidth === 0) fallback();
        });
    }
    $(initSharedCovers);
    mw.hook('wikipage.content').add(initSharedCovers);
})();

/* V15: edition choices stay over the bookshelf; wiki links remain the fallback. */
(function () {
    var books = [{"id":"book-00","title":"Bhagavad-gītā As It Is","editions":[{"label":"1968 · Abridged","title":"Bhagavad Gita As It Is (1968)","url":"https://vanisource.org/wiki/Bhagavad_Gita_As_It_Is_(1968)_Collier-Macmillan_Abridged_Edition","pdf_links":[]},{"label":"1972","title":"Bhagavad-gītā As It Is (1972)","url":"https://vanisource.org/wiki/Bhagavad-gita_As_It_Is_(1972)","pdf_links":["http://vanimedia.org/w/images/7/7a/1972-73_Bhagavad_gita-As_It_Is.pdf"]},{"label":"1983+","title":"Bhagavad-gītā As It Is (1983+)","url":"https://vanisource.org/wiki/Bhagavad-gita_As_It_Is_(1983%2B)","pdf_links":[]}],"related":[{"title":"Introduction to Bhagavad-gita","note":"A publication format of the introduction, not another full Bhagavad-gītā work. Related Vanisource text is explicitly the 1972 edition; do not label it as the standalone booklet.","source":"https://www.bbt.org/book/introduction-bhagavad-gita"},{"title":"Srimad Bhagavad-Gita Verse Book","note":"BBT describes roman transliterations of the Sanskrit verses. Keep under formats; no matching Vanisource standalone verse-book edition verified.","source":"https://www.bbt.org/book/srimad-bhagavad-gita-verse-book"}]},{"id":"book-01","title":"Śrīmad-Bhāgavatam","editions":[{"label":"1962-65","title":"Srimad Bhagwatam (1962-65)","url":"https://vanisource.org/wiki/Srimad_Bhagwatam_(1962-65)","pdf_links":["http://vanimedia.org/w/images/c/c5/1962-SB-Vol-1.pdf","http://vanimedia.org/w/images/7/77/1964-SB-Vol-2.pdf","http://vanimedia.org/w/images/1/1c/1965-SB-Vol-3.pdf"]},{"label":"Text and sources","title":"Śrīmad-Bhāgavatam","url":"https://vanisource.org/wiki/Srimad-Bhagavatam","pdf_links":[]},{"label":"1972–1977 · PDFs","title":"Śrīmad-Bhāgavatam (1972-77)","url":"https://vanisource.org/wiki/Srimad-Bhagavatam_(1972-77)","pdf_links":["http://vanimedia.org/w/images/9/94/SB1.1-1972.pdf","http://vanimedia.org/w/images/9/96/SB1.2-1972.pdf","http://vanimedia.org/w/images/c/c9/SB1.3-1972.pdf","http://vanimedia.org/w/images/6/68/SB2.1-1972.pdf","http://vanimedia.org/w/images/8/8b/SB2.2-1972.pdf","http://vanimedia.org/w/images/d/d2/SB3.1-1972.pdf","http://vanimedia.org/w/images/f/fc/SB3.2-1974.pdf","http://vanimedia.org/w/images/2/2b/SB3.3-1974.pdf","http://vanimedia.org/w/images/3/31/SB3.4-1974.pdf","http://vanimedia.org/w/images/9/9c/SB4.1-1972.pdf","http://vanimedia.org/w/images/4/4c/SB4.2-1974.pdf","http://vanimedia.org/w/images/5/51/SB4.3-1974.pdf","http://vanimedia.org/w/images/8/88/SB4.4-1974.pdf","http://vanimedia.org/w/images/a/a8/SB5.1-1975.pdf","http://vanimedia.org/w/images/f/f6/SB5.2-1975.pdf","http://vanimedia.org/w/images/7/7a/SB6.1-1975.pdf","http://vanimedia.org/w/images/6/6e/SB6.2-1975.pdf","http://vanimedia.org/w/images/5/54/SB6.3-1976.pdf","http://vanimedia.org/w/images/1/1b/SB7.1-1976.pdf","http://vanimedia.org/w/images/a/a0/SB7.2-1976.pdf","http://vanimedia.org/w/images/a/a6/SB7.3-1976.pdf","http://vanimedia.org/w/images/c/c8/SB8.1-1976.pdf","http://vanimedia.org/w/images/8/8c/SB8.2-1976.pdf","http://vanimedia.org/w/images/0/00/SB8.3-1976.pdf","http://vanimedia.org/w/images/b/b8/SB9.1-1977.pdf","http://vanimedia.org/w/images/e/e6/SB9.2-1977.pdf","http://vanimedia.org/w/images/1/11/SB9.3-1977.pdf","http://vanimedia.org/w/images/6/63/SB10.1-1977.pdf","http://vanimedia.org/w/images/1/10/SB10.2-1977.pdf","http://vanimedia.org/w/images/5/56/SB10.3-1980.pdf"]}],"note":"Volume attribution matters: BBTmedia credits later continuation cantos 11 and 12 to Hridayānanda Goswami and Gopīparāṇadhana Dāsa."},{"id":"book-02","title":"Śrī Caitanya-caritāmṛta","editions":[{"label":"1975","title":"Śrī Caitanya-caritāmṛta (1975)","url":"https://vanisource.org/wiki/Sri_Caitanya-caritamrta_(1975)","pdf_links":[]},{"label":"1996","title":"Śrī Caitanya-caritāmṛta (1996)","url":"https://vanisource.org/wiki/Sri_Caitanya-caritamrta","pdf_links":[]}]},{"id":"book-03","title":"Nectar of Instruction","editions":[{"label":"1975","title":"Nectar of Instruction (1975)","url":"https://vanisource.org/wiki/The_Nectar_of_Instruction_(1975)","pdf_links":["http://vanimedia.org/w/images/f/f6/1975-The_Nectar_of_Instruction.pdf"]}]},{"id":"book-04","title":"Śrī Īśopaniṣad","editions":[{"label":"1974","title":"Śrī Īśopaniṣad (1974)","url":"https://vanisource.org/wiki/Sri_Isopanisad_(1974)","pdf_links":["http://vanimedia.org/w/images/f/fe/1969-edition-Sri-Isopanisad.pdf"]},{"label":"2001","title":"Śrī Īśopaniṣad (2001)","url":"https://vanisource.org/wiki/Sri_Isopanisad_(2001)","pdf_links":[]}]},{"id":"book-05","title":"Kṛṣṇa, the Supreme Personality of Godhead","editions":[{"label":"1970","title":"Kṛṣṇa, The Supreme Personality of Godhead (1970)","url":"https://vanisource.org/wiki/Krsna_The_Supreme_Personality_of_Godhead_(1970)","pdf_links":["http://vanimedia.org/w/images/0/06/1970-KRSNA_Book_Vol.1.pdf","http://vanimedia.org/w/images/e/ef/1970-KRSNA_Book_Vol.2.pdf"]},{"label":"1996+","title":"Kṛṣṇa, The Supreme Personality of Godhead (1996+)","url":"https://vanisource.org/wiki/Krsna_The_Supreme_Personality_of_Godhead_(1996%2B)","pdf_links":[]}]},{"id":"book-06","title":"Teachings of Lord Caitanya","editions":[{"label":"1975","title":"Teachings of Lord Caitanya (1975)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Caitanya_(1975)","pdf_links":[]},{"label":"2011","title":"Teachings of Lord Caitanya (2011)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Caitanya_(2011)","pdf_links":[]},{"label":"1968","title":"Teachings of Lord Chaitanya (1968)","url":"https://vanisource.org/wiki/Teachings_of_Lord_Chaitanya_(1968)","pdf_links":["http://vanimedia.org/w/images/2/21/1968-Teachings_of_Lord_Chaitanya.pdf"]}]},{"id":"book-07","title":"Nectar of Devotion","editions":[{"label":"1970","title":"Nectar of Devotion (1970)","url":"https://vanisource.org/wiki/Nectar_of_Devotion_(1970)","pdf_links":["http://vanimedia.org/w/images/a/a5/1970-The_Nectar_of_Devotion.pdf"]},{"label":"1982","title":"Nectar of Devotion (1982)","url":"https://vanisource.org/wiki/Nectar_of_Devotion_(1982)","pdf_links":[]}]},{"id":"book-08","title":"Beyond Birth and Death","editions":[{"label":"Text and sources","title":"Beyond Birth and Death","url":"https://vanisource.org/wiki/Beyond_Birth_and_Death","pdf_links":["http://vanimedia.org/w/images/6/67/1972_Beyond_Birth_and_Death_1974_edition.pdf"]}]},{"id":"book-09","title":"Easy Journey to Other Planets","editions":[{"label":"Text and sources","title":"Easy Journey to Other Planets","url":"https://vanisource.org/wiki/Easy_Journey_to_Other_Planets","pdf_links":["http://vanimedia.org/w/images/e/e3/Easy-Journey-to-Other-Planets-original-India-edition.pdf","http://vanimedia.org/w/images/4/46/Easy-Journy-to-Other-Planets-1977.pdf"]}]},{"id":"book-10","title":"Elevation to Kṛṣṇa Consciousness","editions":[{"label":"Text and sources","title":"Elevation to Kṛṣṇa Consciousness","url":"https://vanisource.org/wiki/Elevation_to_Krsna_Consciousness","pdf_links":["http://vanimedia.org/w/images/1/1b/1973_Elevation_to_Krsna_Consciousness.pdf"]}]},{"id":"book-11","title":"Gītār Gān","editions":[{"label":"Text and sources","title":"Gītār Gān","url":"https://vanisource.org/wiki/Gitar_Gan","pdf_links":[]}]},{"id":"book-12","title":"Kṛṣṇa Consciousness, The Matchless Gift","editions":[{"label":"Text and sources","title":"Kṛṣṇa Consciousness, The Matchless Gift","url":"https://vanisource.org/wiki/Krsna_Consciousness,_The_Matchless_Gift","pdf_links":["http://vanimedia.org/w/images/c/c3/1974-Krsna_Consciousness-The_Matchless_Gift.pdf"]}]},{"id":"book-13","title":"Kṛṣṇa Consciousness, The Topmost Yoga System","editions":[{"label":"Text and sources","title":"Kṛṣṇa Consciousness, The Topmost Yoga System","url":"https://vanisource.org/wiki/Krsna_Consciousness_The_Topmost_Yoga_System","pdf_links":[]}]},{"id":"book-14","title":"Kṛṣṇa, the Reservoir of Pleasure","editions":[{"label":"Text and sources","title":"Kṛṣṇa, the Reservoir of Pleasure","url":"https://vanisource.org/wiki/Krsna_the_Reservoir_of_Pleasure","pdf_links":["http://vanimedia.org/w/images/f/fb/1969-TWO_ESSAYS-Krishna_the_Reservoir_of_Pleasure-%26-Who_is_Crazy.pdf","http://vanimedia.org/w/images/9/9d/KRSNA-the-Reservoir-of-Pleasure-1970.pdf"]}]},{"id":"book-15","title":"On the Way to Kṛṣṇa","editions":[{"label":"Text and sources","title":"On the Way to Kṛṣṇa","url":"https://vanisource.org/wiki/On_the_Way_to_Krsna","pdf_links":["http://vanimedia.org/w/images/e/ee/1973-On_the_Way_to_Krsna.pdf"]}]},{"id":"book-16","title":"Perfect Questions, Perfect Answers","editions":[{"label":"Text and sources","title":"Perfect Questions, Perfect Answers","url":"https://vanisource.org/wiki/Perfect_Questions,_Perfect_Answers","pdf_links":["http://vanimedia.org/w/images/9/9e/1977-Perfect_Questions_Perfect_Answers_Original.pdf"]}]},{"id":"book-17","title":"The Perfection of Yoga","editions":[{"label":"1972","title":"The Perfection of Yoga (1972)","url":"https://vanisource.org/wiki/The_Perfection_of_Yoga_(1972)","pdf_links":["http://vanimedia.org/w/images/8/8b/1972_Perfection_of_Yoga_2008_Original.pdf"]},{"label":"1983","title":"The Perfection of Yoga (1983)","url":"https://vanisource.org/wiki/The_Perfection_of_Yoga_(1983)","pdf_links":[]}],"related":[{"title":"The Path of Yoga","note":"Krishna.com provides the contents: Part One is The Path of Perfection and Part Two is The Perfection of Yoga. The combined edition is not a third independent work.","source":"https://www.bbt.org/book/path-yoga"}]},{"id":"book-18","title":"Rāja-Vidyā: The King of Knowledge","editions":[{"label":"Text and sources","title":"Rāja-Vidyā: The King of Knowledge","url":"https://vanisource.org/wiki/Raja-Vidya_The_King_of_Knowledge","pdf_links":["http://vanimedia.org/w/images/b/b1/1973_Raja-Vidya_The_King_of_Knowledge.pdf"]}]},{"id":"book-19","title":"Teachings of Lord Kapila","editions":[{"label":"Text and sources","title":"Teachings of Lord Kapila","url":"https://vanisource.org/wiki/Teachings_of_Lord_Kapila,_the_Son_of_Devahuti","pdf_links":["http://vanimedia.org/w/images/1/19/1977-Teachings-of-Lord-Kapila.pdf"]}]},{"id":"book-20","title":"Transcendental Teachings of Prahlāda Mahārāja","editions":[{"label":"Text and sources","title":"Transcendental Teachings of Prahlāda Mahārāja","url":"https://vanisource.org/wiki/Transcendental_Teachings_of_Prahlada_Maharaja","pdf_links":[]}]},{"id":"book-21","title":"Beyond Illusion & Doubt","editions":[{"label":"Text and sources","title":"Beyond Illusion & Doubt","url":"https://vanisource.org/wiki/Beyond_Illusion_%26_Doubt","pdf_links":[]}]},{"id":"book-22","title":"Civilization and Transcendence","editions":[{"label":"Text and sources","title":"Civilization and Transcendence","url":"https://vanisource.org/wiki/Civilization_and_Transcendence","pdf_links":[]}]},{"id":"book-23","title":"Dharma - The Way of Transcendence","editions":[{"label":"Text and sources","title":"Dharma - The Way of Transcendence","url":"https://vanisource.org/wiki/Dharma_-_The_Way_of_Transcendence","pdf_links":[]}]},{"id":"book-24","title":"In Search of the Ultimate Goal of Life","editions":[{"label":"1993","title":"In Search of the Ultimate Goal of Life (1993)","url":"https://vanisource.org/wiki/In_Search_of_the_Ultimate_Goal_of_Life","pdf_links":[]}]},{"id":"book-25","title":"Journey of Self-Discovery","editions":[{"label":"Text and sources","title":"Journey of Self-Discovery","url":"https://vanisource.org/wiki/The_Journey_of_Self-Discovery","pdf_links":["https://vanisource.org/w/images/The_Journey_of_Self-Discovery.pdf"]}]},{"id":"book-26","title":"Laws of Nature, An Infallible Justice","editions":[{"label":"Text and sources","title":"Laws of Nature, An Infallible Justice","url":"https://vanisource.org/wiki/The_Laws_of_Nature_An_Infallible_Justice","pdf_links":[]}]},{"id":"book-27","title":"Life Comes From Life","editions":[{"label":"Text and sources","title":"Life Comes From Life","url":"https://vanisource.org/wiki/Life_Comes_From_Life","pdf_links":[]}]},{"id":"book-28","title":"Light of the Bhagavata","editions":[{"label":"Text and sources","title":"Light of the Bhagavata","url":"https://vanisource.org/wiki/Light_of_the_Bhagavata","pdf_links":[]}]},{"id":"book-29","title":"Message of Godhead","editions":[{"label":"1955","title":"Message of Godhead (1955)","url":"https://vanisource.org/wiki/Message_of_Godhead_(1955)","pdf_links":["http://vanimedia.org/w/images/e/e5/1955-Message_of_Godhead-handwritten.pdf","http://vanimedia.org/w/images/6/65/1955-Message_of_Godhead.pdf"]},{"label":"1990","title":"Message of Godhead (1990)","url":"https://vanisource.org/wiki/Message_of_Godhead_(1990)","pdf_links":[]}]},{"id":"book-30","title":"Mukunda-mala-stotra","editions":[{"label":"Text and sources","title":"Mukunda-mala-stotra","url":"https://vanisource.org/wiki/Mukunda-mala-stotra","pdf_links":[]}],"note":"BBT credits this commentary publication to Śrīla Prabhupāda and his disciples."},{"id":"book-31","title":"Narada Bhakti Sutra","editions":[{"label":"Text and sources","title":"Narada Bhakti Sutra","url":"https://vanisource.org/wiki/Narada_Bhakti_Sutra","pdf_links":[]}],"note":"Begun by Śrīla Prabhupāda and completed by Satsvarūpa dāsa Goswami."},{"id":"book-32","title":"Path of Perfection","editions":[{"label":"Text and sources","title":"Path of Perfection","url":"https://vanisource.org/wiki/The_Path_of_Perfection","pdf_links":[]}],"related":[{"title":"The Path of Yoga","note":"Krishna.com provides the contents: Part One is The Path of Perfection and Part Two is The Perfection of Yoga. The combined edition is not a third independent work.","source":"https://www.bbt.org/book/path-yoga"}]},{"id":"book-33","title":"Renunciation Through Wisdom","editions":[{"label":"Text and sources","title":"Renunciation Through Wisdom","url":"https://vanisource.org/wiki/Renunciation_Through_Wisdom","pdf_links":[]}]},{"id":"book-34","title":"Science of Self-Realization","editions":[{"label":"Text and sources","title":"Science of Self-Realization","url":"https://vanisource.org/wiki/The_Science_of_Self-Realization","pdf_links":[]}]},{"id":"book-35","title":"Second Chance - The Story of a Near-Death Experience","editions":[{"label":"Text and sources","title":"Second Chance - The Story of a Near-Death Experience","url":"https://vanisource.org/wiki/A_Second_Chance_-_The_Story_of_a_Near-Death_Experience","pdf_links":[]}]},{"id":"book-36","title":"Teachings of Queen Kuntī","editions":[{"label":"Text and sources","title":"Teachings of Queen Kuntī","url":"https://vanisource.org/wiki/Teachings_of_Queen_Kunti","pdf_links":["http://vanimedia.org/w/images/1/17/1978-Teachings-Of-Queen-Kunti.pdf"]}]},{"id":"book-37","title":"Quest for Enlightenment","editions":[{"label":"Text and sources","title":"Quest for Enlightenment","url":"https://vanisource.org/wiki/The_Quest_for_Enlightenment","pdf_links":["http://vanimedia.org/w/images/f/f4/1997-The_Quest_for_Enlightenment.pdf"]}]}];
    var byId = {};
    books.forEach(function (book) { byId[book.id] = book; });
    var dialog, content, heading, closeButton, invoker;
    var storageKey = 'vs:preferred-editions:v1';
    function preferences() {
        try {
            var value = JSON.parse(localStorage.getItem(storageKey) || '{}');
            return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
        } catch (e) { return {}; }
    }
    function remember(id, url) {
        try { var value = preferences(); value[id] = url; localStorage.setItem(storageKey, JSON.stringify(value)); }
        catch (e) { /* Reading must work with storage disabled. */ }
    }
    function node(tag, name, text) {
        var element = document.createElement(tag);
        if (name) element.className = name;
        if (text) element.textContent = text;
        return element;
    }
    function ensureDialog() {
        if (dialog && dialog.isConnected) return true;
        dialog = document.createElement('dialog');
        if (typeof dialog.showModal !== 'function') return false;
        dialog.id = 'vs-edition-dialog';
        dialog.setAttribute('aria-labelledby', 'vs-edition-dialog-title');
        var header = node('div', 'vs-modal-header');
        heading = node('h2', '', 'Choose edition');
        heading.id = 'vs-edition-dialog-title';
        closeButton = node('button', 'vs-modal-close', 'Close ×');
        closeButton.type = 'button';
        closeButton.setAttribute('aria-label', 'Close edition choices');
        closeButton.addEventListener('click', function () { dialog.close(); });
        header.append(heading, closeButton);
        content = node('div', 'vs-modal-content');
        dialog.append(header, content);
        dialog.addEventListener('close', function () {
            document.documentElement.classList.remove('vs-edition-modal-open');
            if (invoker && invoker.isConnected) invoker.focus({ preventScroll: true });
        });
        dialog.addEventListener('click', function (event) {
            if (event.target !== dialog) return;
            var bounds = dialog.getBoundingClientRect();
            if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) dialog.close();
        });
        document.body.appendChild(dialog);
        return true;
    }
    function openBook(book, trigger) {
        if (!ensureDialog()) return false;
        invoker = trigger;
        heading.textContent = book.title;
        content.replaceChildren();
        content.appendChild(node('p', 'vs-modal-intro', book.editions.length > 1 ? 'Choose the edition you wish to read.' : 'Read this edition or consult its sources.'));
        if (book.note) content.appendChild(node('p', 'vs-modal-note', book.note));
        var preferred = preferences()[book.id];
        book.editions.forEach(function (edition) {
            var row = node('div', 'vs-modal-edition');
            var description = node('div', 'vs-modal-edition-description');
            var title = node('h3', '', edition.label);
            description.appendChild(title);
            if (preferred === edition.url) description.appendChild(node('span', 'vs-modal-last-used', 'Last used'));
            description.appendChild(node('p', '', edition.title));
            var actions = node('div', 'vs-modal-actions');
            var read = node('a', 'vs-modal-read', 'Read edition →');
            read.href = edition.url;
            read.addEventListener('click', function () { remember(book.id, edition.url); });
            actions.appendChild(read);
            edition.pdf_links.forEach(function (url, index) {
                var pdf = node('a', 'vs-modal-pdf', 'PDF source' + (edition.pdf_links.length > 1 ? ' ' + (index + 1) : '') + ' ↗');
                pdf.href = url; pdf.target = '_blank'; pdf.rel = 'noopener noreferrer';
                actions.appendChild(pdf);
            });
            row.append(description, actions);
            content.appendChild(row);
        });
        if (book.related && book.related.length) {
            var sources = node('details', 'vs-modal-more-sources');
            sources.appendChild(node('summary', '', 'Related publications and formats'));
            book.related.forEach(function (publication) {
                var item = node('div', 'vs-modal-related');
                item.append(node('h3', '', publication.title), node('p', '', publication.note));
                var record = node('a', '', 'Publisher record ↗');
                record.href = publication.source; record.target = '_blank'; record.rel = 'noopener noreferrer';
                item.appendChild(record);
                sources.appendChild(item);
            });
            content.appendChild(sources);
        }
        try {
            dialog.showModal();
            document.documentElement.classList.add('vs-edition-modal-open');
            closeButton.focus();
            return true;
        } catch (e) { return false; }
    }
    function init() {
        var home = document.getElementById('vs-home');
        if (!home || home.dataset.vsPopupReady) return;
        home.dataset.vsPopupReady = 'true';
        home.querySelectorAll('.vs-book-card[data-vs-book]').forEach(function (card) {
            var book = byId[card.dataset.vsBook];
            if (!book) return;
            card.querySelectorAll('a').forEach(function (link) {
                if (book.editions.length > 1 || link.closest('.vs-book-action')) {
                    link.setAttribute('aria-haspopup', 'dialog');
                }
            });
        });
        home.addEventListener('click', function (event) {
            var link = event.target.closest('a');
            var card = link && link.closest('.vs-book-card[data-vs-book]');
            if (!card || !home.contains(card)) return;
            var book = byId[card.dataset.vsBook];
            if (!book) return;
            // Modified clicks keep ordinary link behaviour, including new tabs.
            if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
            if (book.editions.length === 1 && !link.closest('.vs-book-action')) {
                remember(book.id, book.editions[0].url);
                return;
            }
            if (openBook(book, link)) event.preventDefault();
        });
    }
    $(init);
    mw.hook('wikipage.content').add(init);
})();