MediaWiki:Common.js
From Encyclopedium Universum
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener("DOMContentLoaded", function() {
const modalLinks = document.querySelectorAll('span[onclick^="showModal"]');
modalLinks.forEach(link => {
link.addEventListener("click", function() {
showModal(link);
});
});
const closeButtons = document.querySelectorAll('.modal-content span[onclick^="closeModal"]');
closeButtons.forEach(button => {
button.addEventListener("click", function() {
closeModal(button);
});
});
});
function showModal(element) {
alert("showModal function called"); // Confirm function call
const modal = element.nextElementSibling;
if (modal) {
alert("Modal element found. Setting display to 'block'"); // Confirm element
modal.style.display = 'block'; // Set display to block
modal.style.opacity = '1'; // Ensure opacity is fully visible
modal.style.visibility = 'visible'; // Set visibility to ensure no conflicts
} else {
alert("Modal element not found."); // Debugging alert
}
}
function closeModal(element) {
alert("closeModal function called"); // Confirm function call
const modal = element.closest('.modal');
if (modal) {
alert("Modal element found. Hiding it."); // Confirm element
modal.style.display = 'none'; // Set display to none
} else {
alert("Modal element not found in closeModal function"); // Debugging alert
}
}
(function(){
// Tanakh verse counts
const verseCounts = {
"Genesis": [31,25,24,26,32,22,24,22,29,32,32,20,18,24,21,16,27,33,38,18,34,24,20,67,34,35,46,22,35,43,55,32,20,31,29,43,36,30,23,23,57,38,34,34,31,22,33,26,22,25],
"Exodus": [22,25,22,31,23,30,25,32,35,29,10,51,22,31,27,36,16,27,25,26,37,30,33,18,40,37,21,43,46,38,18,35,23,35,35,38,29,31,43,38],
"Leviticus": [17,16,17,35,19,30,38,36,24,20,47,8,59,57,33,34,16,30,37,27,24,33,44,23,55,46,34],
"Numbers": [54,34,51,49,31,27,89,26,23,36,35,16,33,45,41,50,13,32,22,29,35,41,30,25,18,65,23,31,40,16,54,42,56,29,34,13],
"Deuteronomy": [46,37,29,49,33,25,26,20,29,22,32,32,18,29,23,22,20,22,21,20,23,30,25,22,19,19,26,68,29,20,30,52,29,12],
// Add rest of Tanakh...
};
const title = mw.config.get('wgTitle'); // current wiki page title
const match = title.match(/^(.*?) \((.*?)\)(?: (\d+))?$/);
if (!match) return; // doesn't match expected format
const translitName = match[1];
const englishName = match[2];
const chapterNum = match[3] ? parseInt(match[3], 10) : null;
if (!verseCounts[englishName]) return; // no data for this book
const container = document.getElementById('tanakh-selector');
if (!container) return;
const chapters = verseCounts[englishName];
// Title
const h2 = document.createElement('h2');
h2.textContent = `${translitName} (${englishName}) — Select Chapter & Verse`;
container.appendChild(h2);
// Chapter buttons grid
const chaptersDiv = document.createElement('div');
chaptersDiv.style.display = 'grid';
chaptersDiv.style.gridTemplateColumns = 'repeat(auto-fit, minmax(72px, 1fr))';
chaptersDiv.style.gap = '8px';
container.appendChild(chaptersDiv);
// Verse panel
const versesPanel = document.createElement('div');
versesPanel.style.display = 'none';
versesPanel.style.marginTop = '12px';
container.appendChild(versesPanel);
const versesHeader = document.createElement('div');
versesHeader.style.display = 'flex';
versesHeader.style.justifyContent = 'space-between';
versesHeader.style.alignItems = 'center';
versesPanel.appendChild(versesHeader);
const currentChLabel = document.createElement('strong');
versesHeader.appendChild(currentChLabel);
const closeBtn = document.createElement('button');
closeBtn.textContent = 'Close';
closeBtn.style.cssText = 'background:#eee;border:1px solid #ccc;padding:4px 8px;border-radius:6px;cursor:pointer;';
versesHeader.appendChild(closeBtn);
const versesDiv = document.createElement('div');
versesDiv.style.display = 'flex';
versesDiv.style.flexWrap = 'wrap';
versesDiv.style.gap = '6px';
versesDiv.style.marginTop = '8px';
versesPanel.appendChild(versesDiv);
// Function to open chapter
function openChapter(chNum) {
const verseCount = chapters[chNum - 1];
currentChLabel.textContent = `Chapter ${chNum} — ${verseCount} verses`;
versesDiv.innerHTML = '';
for (let v = 1; v <= verseCount; v++) {
const a = document.createElement('a');
const pageName = `${translitName} (${englishName}) ${chNum}`.replace(/ /g, '_');
a.href = `/wiki/${pageName}#v${v}`;
a.textContent = v;
a.style.cssText = 'display:inline-flex;align-items:center;justify-content:center;padding:6px 8px;border-radius:6px;border:1px solid #e0e0e0;text-decoration:none;min-width:36px;text-align:center;';
versesDiv.appendChild(a);
}
versesPanel.style.display = 'block';
versesPanel.scrollIntoView({behavior:'smooth', block:'nearest'});
}
// Build chapter buttons
chapters.forEach((verseCount, i) => {
const chNum = i + 1;
const btn = document.createElement('button');
btn.type = 'button';
btn.textContent = chNum;
btn.style.cssText = 'padding:10px 8px;border-radius:8px;border:1px solid #d0d0d0;background:#fff;cursor:pointer;';
btn.addEventListener('click', () => openChapter(chNum));
chaptersDiv.appendChild(btn);
});
closeBtn.addEventListener('click', () => {
versesPanel.style.display = 'none';
});
// Auto-open chapter if we are on a chapter page
if (chapterNum) {
openChapter(chapterNum);
}
})();