events : filtre En tournée via champ isLive
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3a14703407
commit
c072d4efb8
3 changed files with 37 additions and 44 deletions
|
|
@ -1,30 +1,19 @@
|
|||
const FILTER_TARGET_TO_COMPANY_VALUE = {
|
||||
"inside-company": "true",
|
||||
"outside-company": "",
|
||||
};
|
||||
|
||||
export function initEventFilters() {
|
||||
const filterButtons = document.querySelectorAll(".filter[data-target]");
|
||||
const eventCards = document.querySelectorAll(".event-card[data-company]");
|
||||
const eventCards = document.querySelectorAll(".event-card[data-live]");
|
||||
|
||||
if (!eventCards.length) return;
|
||||
|
||||
filterButtons.forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const isAlreadyActive = button.classList.contains("active");
|
||||
|
||||
filterButtons.forEach((btn) => btn.classList.remove("active"));
|
||||
|
||||
if (isAlreadyActive) {
|
||||
showAllCards(eventCards);
|
||||
return;
|
||||
}
|
||||
|
||||
button.classList.add("active");
|
||||
showMatchingCards(
|
||||
eventCards,
|
||||
FILTER_TARGET_TO_COMPANY_VALUE[button.dataset.target]
|
||||
);
|
||||
|
||||
if (button.dataset.target === "all") {
|
||||
showAllCards(eventCards);
|
||||
} else if (button.dataset.target === "live") {
|
||||
showMatchingCards(eventCards, "true");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -33,9 +22,9 @@ function showAllCards(eventCards) {
|
|||
eventCards.forEach((card) => card.removeAttribute("hidden"));
|
||||
}
|
||||
|
||||
function showMatchingCards(eventCards, companyValue) {
|
||||
function showMatchingCards(eventCards, liveValue) {
|
||||
eventCards.forEach((card) => {
|
||||
if (card.dataset.company === companyValue) {
|
||||
if (card.dataset.live === liveValue) {
|
||||
card.removeAttribute("hidden");
|
||||
} else {
|
||||
card.setAttribute("hidden", "");
|
||||
|
|
|
|||
|
|
@ -4,25 +4,29 @@ tabs:
|
|||
presentation:
|
||||
label: Présentation
|
||||
icon: text
|
||||
fields:
|
||||
isFromCompany:
|
||||
label: Spectacle de la compagnie
|
||||
type: toggle
|
||||
default: false
|
||||
width: 1/5
|
||||
text:
|
||||
- Non
|
||||
- Oui
|
||||
presentation:
|
||||
type: writer
|
||||
nodes: false
|
||||
required: true
|
||||
marks:
|
||||
- italic
|
||||
- bold
|
||||
- link
|
||||
- mail
|
||||
width: 4/5
|
||||
columns:
|
||||
- width: 1/4
|
||||
fields:
|
||||
isLive:
|
||||
label: En tournée
|
||||
type: toggle
|
||||
default: false
|
||||
help: |
|
||||
Permet le filtrage dans la page <a href="/spectacles" target="_blank">Spectacle</a>
|
||||
text:
|
||||
- Non
|
||||
- Oui
|
||||
- width: 3/4
|
||||
fields:
|
||||
presentation:
|
||||
type: writer
|
||||
nodes: false
|
||||
required: true
|
||||
marks:
|
||||
- italic
|
||||
- bold
|
||||
- link
|
||||
- mail
|
||||
|
||||
gallery:
|
||||
label: Galerie
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
|
||||
<ul class="sort-buttons">
|
||||
<li><button class="filter active" data-target="inside-company">Tout</button></li>
|
||||
<li><button class="filter" data-target="outside-company">En tournée</button></li>
|
||||
<li><button class="filter active" data-target="all">Tout</button></li>
|
||||
<li><button class="filter" data-target="live">En tournée</button></li>
|
||||
</ul>
|
||||
<ul class="events-grid">
|
||||
<?php foreach ($page->children() as $event): ?>
|
||||
<li
|
||||
class="event-card"
|
||||
data-company="<?= $event->isFromCompany() ?>"
|
||||
<li
|
||||
class="event-card"
|
||||
data-live="<?= $event->isLive() ? 'true' : 'false' ?>"
|
||||
<?= e($event->indexOf($page->children()) > 6, ' loading="lazy"') ?>
|
||||
>
|
||||
<a href="<?= $event->url() ?>">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue