refactor: extract shared entry-map partial (Phase 2)
trip.html.twig and home.html.twig hand-wrote near-identical map-column markup + a MapUtils.initEntryMap() invocation. Extract both into partials/entry-map.html.twig, parameterised (map id, global, entries, gpx config, story markers). Callers now pass resolved header values. The map engine (js/map.js initEntryMap) is unchanged; emitted config is byte-equivalent to the previous inline scripts. Verified: trip-map, home-map and window.tripMap/homeMap Playwright tests pass; both pages 200. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -60,16 +60,18 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="home-layout">
|
||||
<div class="home-map-col">
|
||||
<div class="home-map" id="home-map">
|
||||
<button class="feed-map-fullscreen-btn" id="home-map-fullscreen" aria-label="Expand map">
|
||||
<svg class="feed-map-fs-open" aria-hidden="true" width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
|
||||
<path d="M0 0v4h1.5V1.5H4V0z M14 0H10v1.5h2.5V4H14z M0 14v-4h1.5v2.5H4V14z M14 14H10v-1.5h2.5V10H14z"/>
|
||||
</svg>
|
||||
<span class="feed-map-fs-close" aria-hidden="true">✕</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'partials/entry-map.html.twig' with {
|
||||
map_id: 'home-map',
|
||||
map_global: 'homeMap',
|
||||
entries: map_entries,
|
||||
card_prefix: 'entry-',
|
||||
story_markers: false,
|
||||
gpx_urls: home_gpx_urls,
|
||||
use_gpx: trip and trip.header.use_gpx is not null ? trip.header.use_gpx : true,
|
||||
autoconnect: trip ? (trip.header.autoconnect ?? 'on') : 'on',
|
||||
gpx_source_prefix: 'home-gpx',
|
||||
journey_id: 'home-journey'
|
||||
} only %}
|
||||
|
||||
{% if all_items|length == 0 %}
|
||||
{% include 'partials/home-predeparture.html.twig' with {
|
||||
@@ -90,26 +92,6 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if map_entries|length > 0 %}
|
||||
<script>
|
||||
var HOME_ENTRIES = {{ map_entries|json_encode|raw }};
|
||||
var HOME_GPX_URLS = {{ home_gpx_urls|json_encode|raw }};
|
||||
var USE_GPX = {{ trip and trip.header.use_gpx is not null ? (trip.header.use_gpx ? 'true' : 'false') : 'true' }};
|
||||
var AUTOCONNECT = "{{ trip ? (trip.header.autoconnect ?? 'on') : 'on' }}";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
window.homeMap = MapUtils.initEntryMap({
|
||||
container: 'home-map',
|
||||
entries: HOME_ENTRIES,
|
||||
cardPrefix: 'entry-',
|
||||
fullscreen: { btnId: 'home-map-fullscreen', colSelector: '.home-map-col' },
|
||||
gpx: { urls: HOME_GPX_URLS, use: USE_GPX, autoconnect: AUTOCONNECT, sourcePrefix: 'home-gpx', journeyId: 'home-journey' },
|
||||
fit: { padding: 60, maxZoom: 11, singleZoom: 10 }
|
||||
});
|
||||
}); // DOMContentLoaded
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
{# ══════════════════════════════════════════════════════ BETWEEN-TRIPS MODE #}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user