MediaWiki:CharacterFilter.js
From Illustrations in German Translations of Mark Twain's Works
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$(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
});