CharacterFilter.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 1: | Line 1: | ||
// | $(function() { // jQuery ready | ||
// Huck | // --- Huck Slideshow --- | ||
const huckSlideshow = (function() { | |||
const tag = 'huck'; | |||
const slides = { A: [], B: [] }; | |||
const currentIndex = { A: 0, B: 0 }; | |||
function load(target) { | |||
function | |||
const dropdownId = 'huckDropdown' + target; | const dropdownId = 'huckDropdown' + target; | ||
const | const selectedIllustrator = $('#' + dropdownId).val()?.toLowerCase(); | ||
const img = $('#huckSlide' + target); | |||
const | |||
slides[target] = []; | |||
currentIndex[target] = 0; | |||
if (!selectedIllustrator) { | if (!selectedIllustrator) { | ||
img.attr('src', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png') | |||
.attr('title', 'No illustrator selected.'); | |||
return; | return; | ||
} | } | ||
$('#catalog tbody tr').each(function() { | |||
const row = $(this); | |||
const illustratorText = row. | const illustratorText = row.find('td:eq(2)').text().trim().toLowerCase(); | ||
const tagsText = row. | const tagsText = row.find('td:eq(7)').text().trim().toLowerCase(); | ||
const | const idText = row.find('td:eq(8) a').text().trim(); | ||
if (illustratorText.includes(selectedIllustrator) && tagsText.includes( | if (illustratorText.includes(selectedIllustrator) && tagsText.includes(tag)) { | ||
slides[target].push(idText); | |||
} | } | ||
}); | }); | ||
if ( | if (slides[target].length === 0) { | ||
img.attr('src', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png') | |||
.attr('title', 'No matching images.'); | |||
return; | return; | ||
} | } | ||
show(target, 0); | |||
} | } | ||
show | function show(target, index) { | ||
if (slides[target].length === 0) return; | |||
const | currentIndex[target] = (index + slides[target].length) % slides[target].length; | ||
const imageId = slides[target][currentIndex[target]]; | |||
$('#huckSlide' + target) | |||
.attr('src', '/index.php/Special:Redirect/file/' + imageId + '.jpg') | |||
.attr('alt', imageId) | |||
.attr('title', imageId); | |||
} | |||
function next(target) { show(target, currentIndex[target] + 1); } | |||
function prev(target) { show(target, currentIndex[target] - 1); } | |||
// Eventlistener für Dropdowns | |||
['A','B'].forEach(target => { | |||
$('#huckDropdown' + target).on('change', () => load(target)); | |||
}); | |||
return { load, show, next, prev }; | |||
})(); | |||
window.huckSlideshow = huckSlideshow; // global verfügbar für onclick Buttons | |||
}); | }); | ||
Revision as of 22:39, 2 September 2025
$(function() { // jQuery ready
// --- Huck Slideshow ---
const huckSlideshow = (function() {
const tag = 'huck';
const slides = { A: [], B: [] };
const currentIndex = { A: 0, B: 0 };
function load(target) {
const dropdownId = 'huckDropdown' + target;
const selectedIllustrator = $('#' + dropdownId).val()?.toLowerCase();
const img = $('#huckSlide' + target);
slides[target] = [];
currentIndex[target] = 0;
if (!selectedIllustrator) {
img.attr('src', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png')
.attr('title', 'No illustrator selected.');
return;
}
$('#catalog tbody tr').each(function() {
const row = $(this);
const illustratorText = row.find('td:eq(2)').text().trim().toLowerCase();
const tagsText = row.find('td:eq(7)').text().trim().toLowerCase();
const idText = row.find('td:eq(8) a').text().trim();
if (illustratorText.includes(selectedIllustrator) && tagsText.includes(tag)) {
slides[target].push(idText);
}
});
if (slides[target].length === 0) {
img.attr('src', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png')
.attr('title', 'No matching images.');
return;
}
show(target, 0);
}
function show(target, index) {
if (slides[target].length === 0) return;
currentIndex[target] = (index + slides[target].length) % slides[target].length;
const imageId = slides[target][currentIndex[target]];
$('#huckSlide' + target)
.attr('src', '/index.php/Special:Redirect/file/' + imageId + '.jpg')
.attr('alt', imageId)
.attr('title', imageId);
}
function next(target) { show(target, currentIndex[target] + 1); }
function prev(target) { show(target, currentIndex[target] - 1); }
// Eventlistener für Dropdowns
['A','B'].forEach(target => {
$('#huckDropdown' + target).on('change', () => load(target));
});
return { load, show, next, prev };
})();
window.huckSlideshow = huckSlideshow; // global verfügbar für onclick Buttons
});