ChapterSlides.js: Difference between revisions
From Illustrations in German Translations of Mark Twain's Works
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 86: | Line 86: | ||
// Klick öffnet File-Seite in neuem Tab | // Klick öffnet File-Seite in neuem Tab | ||
imageElement.onclick = function () { | imageElement.onclick = function () { | ||
window.open("/File:" + imageId, "_blank"); | window.open("/File:" + imageId + ".jpg", "_blank"); | ||
}; | }; | ||
Revision as of 15:03, 16 September 2025
// Acht feste Illustratoren definieren
const illustrators = [
"Kemble",
"Schroedter",
"Hirth",
"Busoni",
"Kellerer",
"Harder",
"Trier",
"Bebié"
];
// Bildlisten und aktuelle Indizes
let slides = {};
let currentIndex = {};
illustrators.forEach(name => {
slides[name] = [];
currentIndex[name] = 0;
});
// Eingabe verarbeiten
function loadSlideshowsByChapter() {
const chapterInput = document.getElementById("chapterInput").value.trim();
const chapterNumber = parseInt(chapterInput, 10);
if (isNaN(chapterNumber) || chapterNumber < 1 || chapterNumber > 43) {
alert("Please enter a number between 1 and 43.");
return;
}
const chapterTag = "ch" + String(chapterNumber).padStart(3, "0");
// Tabelle durchsuchen
const rows = document.querySelectorAll("#catalog tbody tr");
illustrators.forEach(name => {
slides[name] = [];
currentIndex[name] = 0;
const imageElement = document.getElementById("slide-" + name);
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const illustratorCell = row.cells[2];
const idCell = row.cells[8];
const illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : "";
const idLink = idCell ? idCell.getElementsByTagName("a")[0] : null;
const idText = idLink ? idLink.textContent.trim().toLowerCase() : "";
if (
illustratorText.indexOf(name.toLowerCase()) !== -1 &&
idText.indexOf(chapterTag) !== -1
) {
slides[name].push(idLink.textContent.trim()); // Name ohne .toLowerCase(), weil wir die Original-Dateinamen brauchen
}
}
if (slides[name].length === 0) {
imageElement.src = "https://illus.twainframe.org/images/2/2b/ChapterPlaceholder.png";
imageElement.title = "No matching images found.";
imageElement.onclick = null;
updateCounter(name); // Counter aktualisieren
} else {
showSlide(name, 0);
}
});
}
// Ein Bild anzeigen
function showSlide(illustrator, index) {
const imageElement = document.getElementById("slide-" + illustrator);
const slideArray = slides[illustrator];
if (!imageElement || slideArray.length === 0) return;
currentIndex[illustrator] = (index + slideArray.length) % slideArray.length;
const imageId = slideArray[currentIndex[illustrator]];
// Bild setzen
imageElement.src = "/index.php/Special:Redirect/file/" + imageId + ".jpg";
imageElement.alt = imageId;
imageElement.title = imageId;
imageElement.style.cursor = "pointer";
// Klick öffnet File-Seite in neuem Tab
imageElement.onclick = function () {
window.open("/File:" + imageId + ".jpg", "_blank");
};
// Counter aktualisieren
updateCounter(illustrator);
// MediaInfo laden und Infobox füllen
loadMediaInfo(illustrator, imageId);
}
// Counter aktualisieren
function updateCounter(illustrator) {
const counterElement = document.getElementById("counter-" + illustrator);
const slideArray = slides[illustrator];
const index = currentIndex[illustrator];
if (counterElement) {
if (slideArray.length === 0) {
counterElement.textContent = "0/0";
} else {
counterElement.textContent = (index + 1) + "/" + slideArray.length;
}
}
}
// Buttons
function nextSlide(illustrator) {
showSlide(illustrator, currentIndex[illustrator] + 1);
}
function prevSlide(illustrator) {
showSlide(illustrator, currentIndex[illustrator] - 1);
}
/* --- Hover-Infobox CSS (kann auch direkt ins Common.css) --- */
const style = document.createElement('style');
style.textContent = `
.slideshow-box { position: relative; }
.mediainfo-box {
display: none;
position: absolute;
top: 5px;
left: 5px;
background: rgba(255,255,255,0.95);
border: 1px solid #ccc;
padding: 0.5em 1em;
border-radius: 4px;
font-size: 0.9em;
z-index: 10;
max-width: 90%;
text-align: left;
}
.slideshow-box img:hover + .mediainfo-box { display: block; }
`;
document.head.appendChild(style);