Zwei Gestaltungswerte am Abschnitt (Höhe der Karten, Link in der Karte), gespeichert nur bei Abweichung von der Vorgabe. Karten nebeneinander füllen die Zeilenhöhe (CSS); ein kleines Skript gleicht Zeilen untereinander an. Links im Fließtext bleiben unberührt (ADR-66). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
87 lines
2.8 KiB
JavaScript
87 lines
2.8 KiB
JavaScript
/*
|
|
* Karten im Abschnitt gleich hoch (Abschnitts-Einstellung „Höhe der Karten“ = „Alle so hoch wie die größte Karte“, ADR-66).
|
|
*
|
|
* Das CSS (widgets.css) bringt Karten, die in einer Zeile stehen, schon ohne Skript auf gleiche Höhe. Dieses Skript gleicht
|
|
* zusätzlich die Zeilen und Plätze eines Abschnitts untereinander an: Alle Karten erhalten als Mindesthöhe die der höchsten.
|
|
* Stehen die Karten untereinander (schmaler Bildschirm, eine Karte je Zeile), bleibt jede bei ihrer eigenen Höhe; dort gäbe
|
|
* eine gleiche Höhe nur leeren Platz. Nichts wird begrenzt oder abgeschnitten, die Mindesthöhe ist nie kleiner als der Inhalt.
|
|
* Ohne Skript bleibt es bei der Gleichhöhe je Zeile.
|
|
*/
|
|
(function () {
|
|
var SECTION = '.section-cards-equal';
|
|
var CARDS = '.cards > .card, .catalog-list > .catalog-card, .lf-pc';
|
|
var widths = new WeakMap();
|
|
var queued = false;
|
|
|
|
function equalize(section) {
|
|
var cards = Array.prototype.filter.call(section.querySelectorAll(CARDS), function (card) {
|
|
return card.getClientRects().length > 0;
|
|
});
|
|
|
|
cards.forEach(function (card) {
|
|
card.style.minBlockSize = '';
|
|
});
|
|
|
|
if (cards.length < 2) {
|
|
return;
|
|
}
|
|
|
|
var tops = cards.map(function (card) {
|
|
return Math.round(card.getBoundingClientRect().top);
|
|
});
|
|
var sideBySide = tops.some(function (top, index) {
|
|
return tops.indexOf(top) !== index;
|
|
});
|
|
|
|
if (!sideBySide) {
|
|
return;
|
|
}
|
|
|
|
var tallest = Math.ceil(Math.max.apply(null, cards.map(function (card) {
|
|
return card.getBoundingClientRect().height;
|
|
})));
|
|
|
|
cards.forEach(function (card) {
|
|
card.style.minBlockSize = tallest + 'px';
|
|
});
|
|
}
|
|
|
|
function run(force) {
|
|
document.querySelectorAll(SECTION).forEach(function (section) {
|
|
var width = Math.round(section.getBoundingClientRect().width);
|
|
|
|
if (force || widths.get(section) !== width) {
|
|
widths.set(section, width);
|
|
equalize(section);
|
|
}
|
|
});
|
|
}
|
|
|
|
function schedule(force) {
|
|
if (queued) {
|
|
return;
|
|
}
|
|
|
|
queued = true;
|
|
window.requestAnimationFrame(function () {
|
|
queued = false;
|
|
run(force);
|
|
});
|
|
}
|
|
|
|
window.lfCardHeights = { run: function () { run(true); } };
|
|
|
|
window.addEventListener('resize', function () { schedule(false); });
|
|
window.addEventListener('load', function () { schedule(true); });
|
|
|
|
if (document.fonts && document.fonts.ready) {
|
|
document.fonts.ready.then(function () { schedule(true); });
|
|
}
|
|
|
|
if (document.readyState !== 'loading') {
|
|
schedule(true);
|
|
} else {
|
|
document.addEventListener('DOMContentLoaded', function () { schedule(true); });
|
|
}
|
|
})();
|