MediaWiki

CharacterFilter.js: Difference between revisions

From Illustrations in German Translations of Mark Twain's Works

No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
// Slideshow Script: Illustrations of Tom, filter by illustrator
// ===============================
// Character Slideshows
// ===============================


// Globale Bildlisten und aktuelle Indizes
// --- Helper Factory ---
var slides = {
function createCharacterSlideshow(tag) {
   A: [],
   return {
  B: [],
    tag: tag,
  C: [],
    slides: { A: [], B: [], C: [], D: [] },
  D: [],
    currentIndex: { A: 0, B: 0, C: 0, D: 0 },


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


var currentIndex = {
      if (!imageElement) return console.error(this.tag + ' Slideshow ' + target + ' not found.');
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};


// Slideshow laden
      this.slides[target] = [];
function filterAndLoadSlideshowT(target) {
      this.currentIndex[target] = 0;
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
 
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
 
  slides[target] = [];
  currentIndex[target] = 0;
 
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
 
  var rows = document.querySelectorAll('#catalog tbody tr');
 
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
 
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
 
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('tom') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }


  if (slides[target].length === 0) {
      if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
        imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
        imageElement.title = "No illustrator selected.";
    return;
        return;
  }
      }


  showSlide(target, 0);
      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() || '';


// Zeige ein einzelnes Bild
        if (illustratorText.includes(selectedIllustrator) && tagsText.includes(this.tag)) {
function showSlide(target, index) {
          this.slides[target].push(idText);
  var imageElement = document.getElementById('slide' + target);
          console.log('✓ ' + this.tag + ' row ' + i + ': ID=' + idText);
  var slideArray = slides[target];
        }
      });


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


  currentIndex[target] = (index + slideArray.length) % slideArray.length;
      this.show(target, 0);
  var imageId = slideArray[currentIndex[target]];
    },


  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
    show: function(target, index) {
  imageElement.alt = imageId;
      const imageElement = document.getElementById('slide' + target);
  imageElement.title = imageId;
      const slideArray = this.slides[target];
}
      if (!imageElement || slideArray.length === 0) return;


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


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


// Slideshow Script: Illustrations of Huck, filter by illustrator
// --- Character Slideshow Objects ---
 
const huckSlideshow = createCharacterSlideshow('huck');
// Globale Bildlisten und aktuelle Indizes
const jimSlideshow = createCharacterSlideshow('jim');
var slides = {
const papSlideshow = createCharacterSlideshow('pap');
  A: [],
const kdSlideshow = createCharacterSlideshow('king'); // King & Duke: einfach beide Tags zusammen filtern
  B: [],
kdSlideshow.altTags = ['duke']; // zusätzlich Duke-Tag berücksichtigen
  C: [],
const tomSlideshow = createCharacterSlideshow('tom');
  D: [],
const sdcSlideshow = createCharacterSlideshow('sdc');
const femSlideshow = createCharacterSlideshow('fem');
const aacSlideshow = createCharacterSlideshow('aac');


};
// Anpassung für KD, dass beide Tags funktionieren
kdSlideshow.load = function(target) {
  const dropdownId = 'illustratorDropdown' + target;
  const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  const imageElement = document.getElementById('slide' + target);


var currentIndex = {
   if (!imageElement) return console.error('KD Slideshow ' + target + ' not found.');
   A: 0,
  B: 0,
  C: 0,
  D: 0,
};


// Slideshow laden
   this.slides[target] = [];
function filterAndLoadSlideshowH(target) {
   this.currentIndex[target] = 0;
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
 
   if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
 
  slides[target] = [];
   currentIndex[target] = 0;


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


   var rows = document.querySelectorAll('#catalog tbody tr');
   const rows = document.querySelectorAll('#catalog tbody tr');
 
   rows.forEach((row, i) => {
   for (var i = 0; i < rows.length; i++) {
     const illustratorText = row.cells[2]?.textContent.trim().toLowerCase() || '';
     var row = rows[i];
     const tagsText = row.cells[7]?.textContent.trim().toLowerCase() || '';
    var illustratorCell = row.cells[2];
     const idLink = row.cells[8]?.getElementsByTagName('a')[0];
    var tagsCell = row.cells[7];
     const idText = idLink?.textContent.trim().toLowerCase() || '';
    var idCell = row.cells[8];
 
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
     var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
     var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
     var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';


     if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('huck') !== -1) {
     if (illustratorText.includes(selectedIllustrator) &&
       slides[target].push(idText);
      (tagsText.includes('king') || tagsText.includes('duke'))) {
       console.log('✓ Zeile ' + i + ': ID=' + idText);
       this.slides[target].push(idText);
       console.log('✓ KD row ' + i + ': ID=' + idText);
     }
     }
   }
   });


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


   showSlide(target, 0);
   this.show(target, 0);
}
 
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
 
  if (!imageElement || slideArray.length === 0) return;
 
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
 
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
 
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
 
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
 
// Slideshow Script: Illustrations of Jim, filter by illustrator
 
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
 
};
 
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
};
// Slideshow laden
function filterAndLoadSlideshowJ(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('jim') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
// Slideshow Script: Illustrations of Pap, filter by illustrator
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
};
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
// Slideshow laden
function filterAndLoadSlideshowP(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('papfinn') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
// Slideshow Script: Illustrations of King and Duke, filter by illustrator
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
};
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
// Slideshow laden
function filterAndLoadSlideshowKD(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (
  illustratorText.indexOf(selectedIllustrator) !== -1 &&
  (
    tagsText.indexOf('king') !== -1 ||
    tagsText.indexOf('duke') !== -1
  )
) {
  slides[target].push(idText);
  console.log('✓ Zeile ' + i + ': ID=' + idText);
}
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
// Slideshow Script: Illustrations of other characters, filter by illustrator
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
};
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
// Slideshow laden
function filterAndLoadSlideshowSDC(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('sdc') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
// Slideshow Script: Illustrations of female characters, filter by illustrator
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
};
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
// Slideshow laden
function filterAndLoadSlideshowFem(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('fem') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}
// Slideshow Script: Illustrations of black characters, filter by illustrator
// Globale Bildlisten und aktuelle Indizes
var slides = {
  A: [],
  B: [],
  C: [],
  D: [],
};
var currentIndex = {
  A: 0,
  B: 0,
  C: 0,
  D: 0,
};
// Slideshow laden
function filterAndLoadSlideshowAAC(target) {
  var dropdownId = 'illustratorDropdown' + target;
  var selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  var imageElement = document.getElementById('slide' + target);
  if (!imageElement) {
    console.error('Slideshow ' + target + ': Bild-Element nicht gefunden.');
    return;
  }
  slides[target] = [];
  currentIndex[target] = 0;
  if (!selectedIllustrator) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Kein Illustrator ausgewählt.";
    return;
  }
  var rows = document.querySelectorAll('#catalog tbody tr');
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var illustratorCell = row.cells[2];
    var tagsCell = row.cells[7];
    var idCell = row.cells[8];
    var illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : '';
    var tagsText = tagsCell ? tagsCell.textContent.trim().toLowerCase() : '';
    var idLink = idCell ? idCell.getElementsByTagName('a')[0] : null;
    var idText = idLink ? idLink.textContent.trim().toLowerCase() : '';
    if (illustratorText.indexOf(selectedIllustrator) !== -1 && tagsText.indexOf('aac') !== -1) {
      slides[target].push(idText);
      console.log('✓ Zeile ' + i + ': ID=' + idText);
    }
  }
  if (slides[target].length === 0) {
    imageElement.src = "https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png";
    imageElement.title = "Keine passenden Bilder gefunden.";
    return;
  }
  showSlide(target, 0);
}
// Zeige ein einzelnes Bild
function showSlide(target, index) {
  var imageElement = document.getElementById('slide' + target);
  var slideArray = slides[target];
  if (!imageElement || slideArray.length === 0) return;
  currentIndex[target] = (index + slideArray.length) % slideArray.length;
  var imageId = slideArray[currentIndex[target]];
  imageElement.src = '/index.php/Special:Redirect/file/' + imageId + '.jpg';
  imageElement.alt = imageId;
  imageElement.title = imageId;
}
// Buttons
function nextSlide(target) {
  showSlide(target, currentIndex[target] + 1);
}
function prevSlide(target) {
  showSlide(target, currentIndex[target] - 1);
}

Revision as of 22:31, 2 September 2025

// ===============================
// Character Slideshows
// ===============================

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

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

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

      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(this.tag)) {
          this.slides[target].push(idText);
          console.log('✓ ' + this.tag + ' 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);
    },

    show: function(target, index) {
      const imageElement = document.getElementById('slide' + 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); }
  };
}

// --- Character Slideshow Objects ---
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
kdSlideshow.load = function(target) {
  const dropdownId = 'illustratorDropdown' + target;
  const selectedIllustrator = document.getElementById(dropdownId).value.toLowerCase();
  const imageElement = document.getElementById('slide' + target);

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

  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);
};