6 Commits
Author SHA1 Message Date
bachir f4961e9679 custom masonry on page archhives projets 2026-10-26 21:02:33 +01:00
bachir bf8f265077 page archives evenements filters 2026-10-26 17:30:25 +01:00
bachir 101e7124c2 page archives projets filters 2026-10-26 16:31:07 +01:00
bachir 329459600b prod build drop console.log 2026-10-26 15:00:49 +01:00
bachir 51ce65aafe misc fixs 2026-10-26 14:57:52 +01:00
bachir 85ef9c962d misc 2026-10-20 21:01:35 +02:00
12 changed files with 536 additions and 23 deletions
+34 -2
View File
@@ -677,8 +677,8 @@ display:
value: all value: all
title_enable: false title_enable: false
title: All title: All
title_enable: true title_enable: false
title: 'Les projets | {{ arguments.tid }}' title: ''
default_argument_type: fixed default_argument_type: fixed
default_argument_options: default_argument_options:
argument: '' argument: ''
@@ -783,8 +783,25 @@ display:
arguments: false arguments: false
filters: false filters: false
filter_groups: false filter_groups: false
header: false
css_class: 'views-archives views-archives-projets' css_class: 'views-archives views-archives-projets'
display_description: '' display_description: ''
header:
leshed_helpers_term_links:
id: leshed_helpers_term_links
table: views
field: leshed_helpers_term_links
relationship: none
group_type: group
admin_label: ''
plugin_id: leshed_helpers_term_links
empty: true
vocabulary: type_de_projet
base_path: projets
list_title: 'type de projet'
show_all: true
only_used: true
used_bundle: projet
exposed_block: true exposed_block: true
display_extenders: { } display_extenders: { }
path: projets path: projets
@@ -1194,6 +1211,21 @@ display:
value: 'Événements à venir' value: 'Événements à venir'
format: wysiwyg format: wysiwyg
tokenize: false tokenize: false
leshed_helpers_term_links:
id: leshed_helpers_term_links
table: views
field: leshed_helpers_term_links
relationship: none
group_type: group
admin_label: ''
plugin_id: leshed_helpers_term_links
empty: true
vocabulary: type_d_evenement
base_path: evenements
list_title: 'type d''événement'
show_all: true
only_used: true
used_bundle: evenement
footer: footer:
view: view:
id: view id: view
@@ -80,3 +80,18 @@ function leshed_helpers_ensure_term_alias(EntityInterface $entity) {
'langcode' => $langcode, 'langcode' => $langcode,
])->save(); ])->save();
} }
/**
* Déclare le plugin d'area "liste de termes en liens" pour les vues.
*/
function leshed_helpers_views_data() {
$data['views']['leshed_helpers_term_links'] = [
'title' => t('Liste de termes en liens (Le Shed)'),
'help' => t("Liste les termes d'un vocabulaire en liens vers un chemin de base suivi du tid."),
'area' => [
'id' => 'leshed_helpers_term_links',
],
];
return $data;
}
@@ -0,0 +1,212 @@
<?php
/**
* @file
* Plugin d'area Views listant les termes d'un vocabulaire en liens.
*/
declare(strict_types=1);
namespace Drupal\leshed_helpers\Plugin\views\area;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\views\Attribute\ViewsArea;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Affiche les termes d'un vocabulaire en liens vers un chemin filtré par tid.
*
* Chaque terme pointe vers <base_path>/<tid> ; l'alias géré par
* leshed_helpers (ou pathauto) est appliqué automatiquement à la génération
* du lien.
*/
#[ViewsArea('leshed_helpers_term_links')]
class TermLinks extends AreaPluginBase implements ContainerFactoryPluginInterface {
/**
* Le gestionnaire d'entités.
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* La connexion à la base de données.
*/
protected Connection $connection;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->connection = $connection;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('database')
);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['vocabulary'] = ['default' => ''];
$options['base_path'] = ['default' => ''];
$options['list_title'] = ['default' => ''];
$options['show_all'] = ['default' => TRUE];
$options['only_used'] = ['default' => FALSE];
$options['used_bundle'] = ['default' => ''];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$vocabularies = [];
foreach ($this->entityTypeManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) {
$vocabularies[$vocabulary->id()] = $vocabulary->label();
}
$form['vocabulary'] = [
'#type' => 'select',
'#title' => $this->t('Vocabulaire'),
'#options' => $vocabularies,
'#default_value' => $this->options['vocabulary'],
'#required' => TRUE,
];
$form['base_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Chemin de base'),
'#description' => $this->t('Chemin de la vue filtrée, sans slash initial. Exemple : projets.'),
'#default_value' => $this->options['base_path'],
'#required' => TRUE,
];
$form['list_title'] = [
'#type' => 'textfield',
'#title' => $this->t('Titre de la liste'),
'#default_value' => $this->options['list_title'],
];
$form['show_all'] = [
'#type' => 'checkbox',
'#title' => $this->t('Ajouter un lien « Tous » vers la page non filtrée'),
'#default_value' => $this->options['show_all'],
];
$form['only_used'] = [
'#type' => 'checkbox',
'#title' => $this->t("N'afficher que les termes utilisés par au moins un contenu publié"),
'#default_value' => $this->options['only_used'],
];
$node_types = [];
foreach ($this->entityTypeManager->getStorage('node_type')->loadMultiple() as $node_type) {
$node_types[$node_type->id()] = $node_type->label();
}
$form['used_bundle'] = [
'#type' => 'select',
'#title' => $this->t('Type de contenu'),
'#options' => $node_types,
'#empty_option' => $this->t('- Tous types de contenu -'),
'#empty_value' => '',
'#default_value' => $this->options['used_bundle'],
'#states' => [
'visible' => [
':input[name="options[only_used]"]' => ['checked' => TRUE],
],
],
];
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
if (empty($this->options['vocabulary']) || empty($this->options['base_path'])) {
return [];
}
$storage = $this->entityTypeManager->getStorage('taxonomy_term');
$tree = $storage->loadTree($this->options['vocabulary']);
if (empty($tree)) {
return [];
}
// tids des termes du vocabulaire, dans l'ordre de l'arborescence.
$tids = array_map(static fn($term) => (int) $term->tid, $tree);
if (!empty($this->options['only_used'])) {
// taxonomy_index ne référence que les contenus publiés ; jointure sur
// node_field_data pour restreindre au type de contenu voulu. Une seule
// requête pour tout le vocabulaire.
$query = $this->connection->select('taxonomy_index', 'ti');
$query->distinct();
$query->fields('ti', ['tid']);
$query->condition('ti.tid', $tids, 'IN');
$query->join('node_field_data', 'nfd', 'nfd.nid = ti.nid AND nfd.status = 1');
if (!empty($this->options['used_bundle'])) {
$query->condition('nfd.type', $this->options['used_bundle']);
}
$used = array_map('intval', $query->execute()->fetchCol());
$tids = array_values(array_intersect($tids, $used));
}
$entities = $storage->loadMultiple($tids);
// tids présents dans les arguments de la vue, pour marquer le lien actif.
$current_tids = [];
foreach ($this->view->args as $arg) {
foreach (explode(',', (string) $arg) as $tid) {
$current_tids[] = trim($tid);
}
}
$base_path = '/' . trim($this->options['base_path'], '/');
$items = [];
if (!empty($this->options['show_all'])) {
$items[] = [
'#type' => 'link',
'#title' => $this->t('Tous'),
'#url' => Url::fromUserInput($base_path),
'#attributes' => $current_tids ? [] : ['class' => ['is-active']],
];
}
foreach ($tree as $position) {
$term = $entities[(int) $position->tid] ?? NULL;
if ($term === NULL || !$term->isPublished()) {
continue;
}
$items[] = [
'#type' => 'link',
'#title' => $term->label(),
'#url' => Url::fromUserInput($base_path . '/' . $term->id()),
'#attributes' => in_array((string) $term->id(), $current_tids, TRUE)
? ['class' => ['is-active']]
: [],
];
}
$cache_tags = ['taxonomy_term_list:' . $this->options['vocabulary']];
if (!empty($this->options['only_used'])) {
// Le filtrage par usage dépend des contenus publiés.
$cache_tags[] = 'node_list';
}
return [
'#theme' => 'item_list',
'#title' => $this->options['list_title'],
'#list_type' => 'ul',
'#items' => $items,
'#attributes' => ['class' => ['leshed-term-links']],
'#cache' => [
'tags' => $cache_tags,
],
];
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -69,6 +69,7 @@ gsap.registerPlugin(ScrollTrigger);
initHomeColumnScrollSync(); initHomeColumnScrollSync();
initFsLightbox(); initFsLightbox();
initPageFull(); initPageFull();
initMasonry();
// initVues() // initVues()
// titles.js traite les titres hors écran par lots, après la première // titles.js traite les titres hors écran par lots, après la première
@@ -351,6 +352,102 @@ gsap.registerPlugin(ScrollTrigger);
window.refreshFsLightbox(); window.refreshFsLightbox();
} }
// __ __ _ _ _
// | \/ | ___ _ __ ___| |__ ___ _ __ ___ ___| |_| |
// | |\/| |/ _ \| '_ \ / __| '_ \ / _ \ '__/ _ \/ __| __| |
// | | | | (_) | | | | (__| | | | __/ | | __/\__ \ |_|_|
// |_| |_|\___/|_| |_|\___|_| |_|\___|_| \___||___/\__(_)
//
// Masonry maison pour la grille des projets (.view-content de
// views-archives-projets) : CSS Grid + grid-auto-rows fin + span N par
// item. Pas de librairie ; l'ordre gauche→droite de la vue est préservé
// (auto-placement sparse, dense inutile : les trous résiduels font moins
// d'une rangée virtuelle). Sans JS (ou avant le premier pack), la grille
// CSS actuelle reste le fallback : des trous, mais rien de cassé.
function initMasonry(){
const containers = document.querySelectorAll('.views-archives-projets .view-content');
if (!containers.length) return;
// Granularité d'une rangée virtuelle : assez fine pour que les trous
// résiduels (≤ BASE) soient invisibles, assez grosse pour des spans
// raisonnables.
const BASE = 8; // px
const pack = (container) => {
const items = container.querySelectorAll(':scope > .views-row');
if (!items.length) return;
// Gouttière verticale : row-gap de la grille (0 ici — la gouttière
// vit dans le margin-bottom des items) ; le pas de quantification
// du span est donc BASE et non BASE + gouttière.
const rowGap = parseFloat(getComputedStyle(container).rowGap) || 0;
// Dense : sans lui, le placement sparse ne recule jamais — un item
// haut qui ne rentre pas dans un trou le saute, et les suivants ne
// peuvent plus y revenir (trous visibles sous la première rangée).
// Dense renvoie chaque item au premier trou où il tient, quitte à
// inverser localement l'ordre visuel — comportement standard d'un
// masonry.
container.style.gridAutoFlow = 'row dense';
// Les images portent width/height (ratio réservé au layout) et
// align-items: start (SCSS) garantit qu'un item garde sa hauteur de
// contenu, spans appliqués ou non. On mesure donc SANS reset des
// spans : pas de re-layout complet de la grille à chaque pack —
// chaque pack se résume à lire N hauteurs et n'écrire que les spans
// qui changent (sinon chaque image chargée pendant le scroll
// déclenchait deux layouts forcés des 110 items, d'où le lag).
items.forEach((item) => {
const cs = getComputedStyle(item);
const h = item.offsetHeight
+ (parseFloat(cs.marginTop) || 0)
+ (parseFloat(cs.marginBottom) || 0);
const span = Math.max(1, Math.ceil((h + rowGap) / (BASE + rowGap)));
if (item._masonrySpan !== span) {
item._masonrySpan = span;
item.style.gridRowEnd = `span ${span}`;
}
});
container.style.gridAutoRows = `${BASE}px`;
};
const schedule = (container) => {
// Une seule passe par frame, même si dix images lazy arrivent coup
// sur coup.
if (container._masonryRaf) return;
container._masonryRaf = requestAnimationFrame(() => {
container._masonryRaf = null;
pack(container);
});
};
containers.forEach((container) => {
// Toute variation de largeur (seuil mobile : 4→2 colonnes, zoom,
// rotation) repasse par un pack complet.
new ResizeObserver(() => schedule(container)).observe(container);
// Le contenu d'une carte peut changer de hauteur APRÈS un pack :
// troncature des h2 par titles.js (data-overflow-lines), chargement
// des images, polices… Or la views-row, étirée sur son span, ne
// change PAS de taille quand son contenu rétrécit : le span reste
// surdimensionné (l'espace mort dans la row) et aucun déclencheur
// extérieur ne le voit. On observe donc directement les articles.
const contentRO = new ResizeObserver(() => schedule(container));
container.querySelectorAll(':scope > .views-row > article').forEach((a) => contentRO.observe(a));
// Images lazy : chaque chargement change la hauteur d'un item.
container.addEventListener('load', () => schedule(container), true);
// La police variable (Epilogue) charge après le layout initial, et
// titles.js retouche les h2 par lots : les deux changent des hauteurs.
if (document.fonts && document.fonts.ready) {
document.fonts.ready.then(() => schedule(container));
}
document.addEventListener('leshed:titles-ready', () => schedule(container), { once: true });
schedule(container);
});
}
// function initVues(){ // function initVues(){
// console.log('initVues'); // console.log('initVues');
@@ -69,11 +69,11 @@ header[role="banner"]{
background-color: #000; background-color: #000;
} }
&:hover{ // &:hover{
&, &::before, &::after{ // &, &::before, &::after{
background-color: green; // // background-color: green;
} // }
} // }
&::before, &::after{ &::before, &::after{
content: ""; content: "";
position: absolute; position: absolute;
@@ -131,7 +131,16 @@ header[role="banner"]{
font-weight: 200; font-weight: 200;
text-transform: lowercase; text-transform: lowercase;
filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 5px #fff) drop-shadow(0 0 15px #fff); filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 5px #fff) drop-shadow(0 0 15px #fff);
display: inline-block;
transform-origin: left;
transition: all 0.4s ease-in-out;
&:hover{
transform: scale(1.1);
transition: all 0.2s ease-in-out;
}
} }
} }
} }
} }
@@ -155,7 +164,10 @@ header[role="banner"]{
} }
&.is-active{ &.is-active{
font-weight: 400; a{
font-weight: 400;
text-decoration: underline;
}
} }
} }
@@ -23,7 +23,7 @@ div.layout-container{
display: block; display: block;
position: relative; position: relative;
padding: 0.5em 0; padding: 0.5em 0;
flex: 1 1 $header-height-fluid; flex: 0 1 $header-height-fluid;
z-index: 100; z-index: 100;
// position: fixed; // position: fixed;
// top:0; // top:0;
@@ -8,6 +8,29 @@
div.views-archives-evenements { div.views-archives-evenements {
// Exclusivement les filtres (liste « type d'événement »). Le header texte
// « Événements passés » de l'embed vit dans un <p> : l'espacement est donc
// porté par la liste elle-même, pas par le <header>.
>header{
h3{
font-size: 1em;
margin:0 0 0.5em 0;
font-weight: 400;
}
ul.leshed-term-links{
padding:0;
margin: 0 0 2em 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 1em;
li{
list-style: none;
line-height: 0.4;
}
}
}
& > h3{ & > h3{
// border-bottom: 1px solid #999; // border-bottom: 1px solid #999;
margin-bottom: 0; margin-bottom: 0;
@@ -11,13 +11,56 @@
div.views-archives-projets{ div.views-archives-projets{
// Design : 4 colonnes ou 2, jamais 3 — grille explicite qui bascule au // Le header (liste « type de projet ») vit hors de la grille :
// seuil mobile. Une dernière rangée incomplète ne s'étire pas. >header{
display: grid; padding-bottom: 2em;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: $colsgap; h3{
@media #{$mobile}{ font-size: 1em;
grid-template-columns: repeat(2, minmax(0, 1fr)); margin:0 0 0.5em 0;
font-weight: 400;
// font-size: ;
}
ul{
padding:0;
margin: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 1em;
li{
list-style: none;
line-height: 0.4;
}
}
}
// les rows sont wrappées dans div.view-content (template
// views-view--archives--page-1.html.twig), qui porte la grille.
div.view-content{
// Design : 4 colonnes ou 2, jamais 3 — grille explicite qui bascule au
// seuil mobile. Une dernière rangée incomplète ne s'étire pas.
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
// Gouttière verticale portée par les items (margin-bottom), pas par le
// row-gap : avec le masonry JS, chaque rangée virtuelle de 8px ajouterait
// 32px de pas de quantification — un item peut « dépasser » de presque
// 40px dans son span. Avec row-gap: 0, l'arrondi résiduel tombe sous
// 8px. Sans JS, la marge produit la même gouttière que l'ancien gap.
column-gap: $colsgap;
row-gap: 0;
align-items: start;
>.views-row{
margin-bottom: $colsgap;
// Le whitespace du template crée une boîte de ligne anonyme (+16px)
// sous l'article. Un conteneur flex ignore les nœuds texte vides :
// la row fait exactement la hauteur de l'article.
display: flex;
flex-direction: column;
}
@media #{$mobile}{
grid-template-columns: repeat(2, minmax(0, 1fr));
}
} }
@@ -0,0 +1,74 @@
{#
/**
* @file
* Theme override for main view template — page Projets de la vue Archives.
*
* Les rows sont wrappées dans un div.view-content pour que le header
* (liste « type de projet ») ne soit pas un enfant direct de la grille.
*
* Available variables:
* - attributes: Remaining HTML attributes for the element.
* - css_name: A CSS-safe version of the view name.
* - css_class: The user-specified classes names, if any.
* - header: The optional header.
* - footer: The optional footer.
* - rows: The results of the view query, if any.
* - empty: The content to display if there are no rows.
* - pager: The optional pager next/prev links to display.
* - exposed: Exposed widget form/info to display.
* - feed_icons: Optional feed icons to display.
* - more: An optional link to the next page of results.
* - title: Title of the view, only used when displaying in the admin preview.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the view title.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the view title.
* - attachment_before: An optional attachment view to be displayed before the
* view content.
* - attachment_after: An optional attachment view to be displayed after the
* view content.
* - dom_id: Unique id for every view being printed to give unique class for
* Javascript.
*
* @see template_preprocess_views_view()
*/
#}
{%
set classes = [
dom_id ? 'js-view-dom-id-' ~ dom_id,
]
%}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{{ title }}
{{ title_suffix }}
{% if header %}
<header>
{{ header }}
</header>
{% endif %}
{{ exposed }}
{{ attachment_before }}
{% if rows -%}
<div class="view-content">
{{ rows }}
</div>
{% elseif empty -%}
{{ empty }}
{% endif %}
{{ pager }}
{{ attachment_after }}
{{ more }}
{% if footer %}
<footer>
{{ footer }}
</footer>
{% endif %}
{{ feed_icons }}
</div>
+5
View File
@@ -5,6 +5,11 @@ import { fileURLToPath, URL } from 'node:url'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
esbuild: {
// Marque console.log comme "pure" : esbuild le retire du build minifié
// (console.warn/error sont conservés). Sans effet en dev server.
pure: ['console.log'],
},
css: { css: {
preprocessorOptions: { preprocessorOptions: {
scss: { scss: {