MediaWiki

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:
// ===============================
// ===============================
// Character Slideshows
// Huck Slideshows
// ===============================
// ===============================


// --- Helper Factory ---
// Helper Factory
function createCharacterSlideshow(tag) {
function createCharacterSlideshow(tag) {
   return {
   return {
     tag: tag,
     tag: tag,
     slides: { A: [], B: [], C: [], D: [] },
     slides: { A: [], B: [] },
     currentIndex: { A: 0, B: 0, C: 0, D: 0 },
     currentIndex: { A: 0, B: 0 },


     load: function(target) {
     load: function(target) {
       const dropdownId = 'illustratorDropdown' + target;
       const dropdownId = 'huckDropdown' + target;
      const imageId = 'huckSlide' + target;
       const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
       const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
       const imageElement = document.getElementById('slide' + target);
       const imageElement = document.getElementById(imageId);


       if (!imageElement) return console.error(this.tag + ' Slideshow ' + target + ' not found.');
       if (!imageElement) return;


       this.slides[target] = [];
       this.slides[target] = [];
Line 27: Line 28:


       const rows = document.querySelectorAll('#catalog tbody tr');
       const rows = document.querySelectorAll('#catalog tbody tr');
       rows.forEach((row, i) => {
       rows.forEach((row) => {
         const illustratorText = row.cells[2]?.textContent.trim().toLowerCase() || '';
         const illustratorText = row.cells[2]?.textContent.trim().toLowerCase() || '';
         const tagsText = row.cells[7]?.textContent.trim().toLowerCase() || '';
         const tagsText = row.cells[7]?.textContent.trim().toLowerCase() || '';
         const idLink = row.cells[8]?.getElementsByTagName('a')[0];
         const idLink = row.cells[8]?.getElementsByTagName('a')[0];
         const idText = idLink?.textContent.trim().toLowerCase() || '';
         const idText = idLink?.textContent.trim() || '';


         if (illustratorText.includes(selectedIllustrator) && tagsText.includes(this.tag)) {
         if (illustratorText.includes(selectedIllustrator) && tagsText.includes(this.tag)) {
           this.slides[target].push(idText);
           this.slides[target].push(idText);
          console.log('✓ ' + this.tag + ' row ' + i + ': ID=' + idText);
         }
         }
       });
       });
Line 49: Line 49:


     show: function(target, index) {
     show: function(target, index) {
       const imageElement = document.getElementById('slide' + target);
       const imageElement = document.getElementById('huckSlide' + target);
       const slideArray = this.slides[target];
       const slideArray = this.slides[target];
       if (!imageElement || slideArray.length === 0) return;
       if (!imageElement || slideArray.length === 0) return;
Line 65: Line 65:
}
}


// --- Character Slideshow Objects ---
// Huck slideshow object
const huckSlideshow = createCharacterSlideshow('huck');
const huckSlideshow = createCharacterSlideshow('huck');
const jimSlideshow = createCharacterSlideshow('jim');
const papSlideshow = createCharacterSlideshow('pap');
const kdSlideshow = createCharacterSlideshow('king'); // King & Duke: einfach beide Tags zusammen filtern
kdSlideshow.altTags = ['duke']; // zusätzlich Duke-Tag berücksichtigen
const tomSlideshow = createCharacterSlideshow('tom');
const sdcSlideshow = createCharacterSlideshow('sdc');
const femSlideshow = createCharacterSlideshow('fem');
const aacSlideshow = createCharacterSlideshow('aac');


// Anpassung für KD, dass beide Tags funktionieren
// Event listeners für Dropdowns
kdSlideshow.load = function(target) {
document.addEventListener("DOMContentLoaded", function() {
   const dropdownId = 'illustratorDropdown' + target;
   ['A', 'B'].forEach((target) => {
  const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
     const dropdown = document.getElementById('huckDropdown' + target);
  const imageElement = document.getElementById('slide' + target);
     if (dropdown) {
 
      dropdown.addEventListener('change', function() {
  if (!imageElement) return console.error('KD Slideshow ' + target + ' not found.');
        huckSlideshow.load(target);
 
       });
  this.slides[target] = [];
  this.currentIndex[target] = 0;
 
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "No illustrator selected.";
    return;
  }
 
  const rows = document.querySelectorAll('#catalog tbody tr');
  rows.forEach((row, i) => {
     const illustratorText = row.cells[2]?.textContent.trim().toLowerCase() || '';
    const tagsText = row.cells[7]?.textContent.trim().toLowerCase() || '';
    const idLink = row.cells[8]?.getElementsByTagName('a')[0];
    const idText = idLink?.textContent.trim().toLowerCase() || '';
 
     if (illustratorText.includes(selectedIllustrator) &&
      (tagsText.includes('king') || tagsText.includes('duke'))) {
      this.slides[target].push(idText);
       console.log('✓ KD row ' + i + ': ID=' + idText);
     }
     }
   });
   });
 
});
  if (this.slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "No matching images.";
    return;
  }
 
  this.show(target, 0);
};

Revision as of 22:37, 2 September 2025

// ===============================
// Huck Slideshows
// ===============================

// Helper Factory
function createCharacterSlideshow(tag) {
  return {
    tag: tag,
    slides: { A: [], B: [] },
    currentIndex: { A: 0, B: 0 },

    load: function(target) {
      const dropdownId = 'huckDropdown' + target;
      const imageId = 'huckSlide' + target;
      const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
      const imageElement = document.getElementById(imageId);

      if (!imageElement) return;

      this.slides[target] = [];
      this.currentIndex[target] = 0;

      if (!selectedIllustrator) {
        imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
        imageElement.title = "No illustrator selected.";
        return;
      }

      const rows = document.querySelectorAll('#catalog tbody tr');
      rows.forEach((row) => {
        const illustratorText = row.cells[2]?.textContent.trim().toLowerCase() || '';
        const tagsText = row.cells[7]?.textContent.trim().toLowerCase() || '';
        const idLink = row.cells[8]?.getElementsByTagName('a')[0];
        const idText = idLink?.textContent.trim() || '';

        if (illustratorText.includes(selectedIllustrator) && tagsText.includes(this.tag)) {
          this.slides[target].push(idText);
        }
      });

      if (this.slides[target].length === 0) {
        imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
        imageElement.title = "No matching images.";
        return;
      }

      this.show(target, 0);
    },

    show: function(target, index) {
      const imageElement = document.getElementById('huckSlide' + target);
      const slideArray = this.slides[target];
      if (!imageElement || slideArray.length === 0) return;

      this.currentIndex[target] = (index + slideArray.length) % slideArray.length;
      const imageId = slideArray[this.currentIndex[target]];
      imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
      imageElement.alt = imageId;
      imageElement.title = imageId;
    },

    next: function(target) { this.show(target, this.currentIndex[target] + 1); },
    prev: function(target) { this.show(target, this.currentIndex[target] - 1); }
  };
}

// Huck slideshow object
const huckSlideshow = createCharacterSlideshow('huck');

// Event listeners für Dropdowns
document.addEventListener("DOMContentLoaded", function() {
  ['A', 'B'].forEach((target) => {
    const dropdown = document.getElementById('huckDropdown' + target);
    if (dropdown) {
      dropdown.addEventListener('change', function() {
        huckSlideshow.load(target);
      });
    }
  });
});