PageSourceSearch

https://www.tourismebretagne.com/app/dist/crt-bretagne/addons/wood…/woody-favorites-map-view.76b6bfc1c4.mjs

js tourismebretagne.com collected 2026-10-02 05:17:46 UTC 6,243 bytes, 1 lines download raw bytes

1import a,{getHeaderHeight as o}from"woody_library_header_utils";import{createActiveItemObserver as n}from"woody_lib_active_item_observer";class r{static SCROLL_SETTLE_MS=800;static DEFINE_TIMEOUT_MS=5e3;constructor(e,t){this.root=e,this.config=t||{},this.mapSlot=e.querySelector("[data-wfav-map]"),this.mapEl=this.mapSlot?this.mapSlot.querySelector("woody-map"):null,this.geoGrid=e.querySelector("[data-wfav-geo-grid]"),this.mapObserver=null,this.activeCell=null,this.mapReady=null,this.listeners=[],this.resizeScheduled=!1}async init(){return!this.mapSlot||!this.mapEl||!this.geoGrid?!1:(this.mapObserver=n({getTargets:()=>this.geoGrid.querySelectorAll("[data-wfav-item][data-location-lat]"),getKey:e=>e.dataset.wfavPid,onActiveChange:(e,t)=>this.selectAndCenter(e,t)}),this.setupHandle(),this.setupOffsets(),this.mapObserver.start(),this.ensureMap())}ensureMap(){return this.mapReady?this.mapReady:(this.mapReady=(async()=>{if(!window.customElements)return!1;try{if(!await Promise.race([customElements.whenDefined("woody-map").then(()=>!0),new Promise(s=>setTimeout(()=>s(!1),r.DEFINE_TIMEOUT_MS))]))return console.warn("[favorites] <woody-map> non enregistre : carte abandonnee"),this.teardownMap(),!1;const{default:t}=await import("woody_favorites_map_manager");await this.mapEl.init({manager:new t})}catch(e){return console.warn("[favorites] initialisation de la carte impossible",e),this.teardownMap(),!1}return this.on(this.mapEl,"pinclick",e=>this.onPinClick(e)),this.refreshMarkers(),!0})(),this.mapReady)}teardownMap(){if(this.mapSlot&&this.mapSlot.contains(document.activeElement)){const e=this.root.querySelector(".wfav-items__title");e&&e.focus()}this.mapSlot&&this.mapSlot.parentNode&&this.mapSlot.parentNode.removeChild(this.mapSlot),this.mapSlot=null,this.mapEl=null}on(e,t,s,i){e.addEventListener(t,s,i),this.listeners.push([e,t,s,i])}destroy(){this.listeners.forEach(([e,t,s,i])=>e.removeEventListener(t,s,i)),this.listeners=[],this.mapObserver&&(this.mapObserver.destroy(),this.mapObserver=null)}markerDefaults(){if(this.markerDefaultsCache)return this.markerDefaultsCache;const e=this.mapSlot?this.mapSlot.querySelector("[data-wfav-map-model]"):null;try{this.markerDefaultsCache=e?JSON.parse(e.textContent):{}}catch(t){console.warn("[favorites] mod\xE8le de marqueurs illisible",t),this.markerDefaultsCache={}}return this.markerDefaultsCache}normalizePin(e,t){const s=e.properties&&e.properties.post_id!==void 0?e.properties.post_id:e.post_id;return{lat:parseFloat(e.lat),lon:parseFloat(e.lon!==void 0?e.lon:e.lng),name:e.name||"",properties:{post_id:parseInt(s,10),index:e.properties&&e.properties.index!==void 0?e.properties.index:t}}}currentPins(){const e=this.removedPostIds||new Set;return(this.config.geo||[]).filter(t=>{const s=t.properties?parseInt(t.properties.post_id,10):0;return s&&!e.has(s)}).map((t,s)=>this.normalizePin(t,s))}refreshMarkers(){if(!this.mapEl||!this.mapEl.loaded)return;const e=this.currentPins();if(e.length===0){this.teardownMap();return}this.mapEl.setMarkersModel(Object.assign({},this.markerDefaults(),{pins:e}),null),this.mapEl.fitBounds(!this.prefersReducedMotion())}onFavoriteRemoved(e){const t=parseInt(e,10);t&&(this.removedPostIds=this.removedPostIds||new Set,this.removedPostIds.add(t),this.refreshMarkers(),this.mapObserver&&this.mapObserver.refresh())}onGridUpdated(){this.mapObserver&&this.mapObserver.refresh()}selectAndCenter(e,t){if(this.setActiveCell(t),!this.mapEl||!this.mapEl.loaded||!this.mapEl.manager||!this.mapEl.manager.getMappedPinIndex)return;const s=this.mapEl.manager.getMappedPinIndex(e);s!==void 0&&(this.mapEl.setSelectedPinIndex(s,!this.prefersReducedMotion(),!1),this.centerOn(t.dataset.locationLat,t.dataset.locationLng))}centerOn(e,t){if(!this.mapEl||!this.mapEl.tmaps)return;const s=[parseFloat(t),parseFloat(e)];if(!(Number.isNaN(s[0])||Number.isNaN(s[1])))try{this.mapEl.tmaps.position({center:s,animate:!this.prefersReducedMotion()})}catch(i){console.warn("[favorites] recentrage de la carte indisponible",i)}}setActiveCell(e){this.activeCell!==e&&(this.activeCell&&this.activeCell.classList.remove("wfav-cell--active"),this.activeCell=e,e&&e.classList.add("wfav-cell--active"))}onPinClick(e){const t=e.detail&&e.detail.properties?e.detail.properties.post_id:null;if(!t)return;const s=this.geoGrid.querySelector('[data-wfav-item][data-wfav-pid="'+t+'"]');s&&(this.mapObserver.selectExternally(String(t)),this.focusCard(s))}async focusCard(e){await this.mapObserver.runExclusive(async()=>{const t=a()+this.reservedHeaderHeight();if(!this.isInViewport(e,t)){const i=e.getBoundingClientRect().top+window.scrollY-t;window.scrollTo({top:Math.max(0,i),behavior:this.prefersReducedMotion()?"auto":"smooth"})}const s=e.querySelector("a[href]");s?s.focus({preventScroll:!0}):(e.setAttribute("tabindex","-1"),e.focus({preventScroll:!0})),this.setActiveCell(e),await new Promise(i=>setTimeout(i,r.SCROLL_SETTLE_MS))})}isInViewport(e,t=0){const s=e.getBoundingClientRect();return s.top>=t&&s.bottom<=(window.innerHeight||document.documentElement.clientHeight)}reservedHeaderHeight(){return o()>0?0:this.topHeaderHeight()}topHeaderHeight(){let e=0;return document.querySelectorAll(".woody-component-headnavs, .woody-component-mobilenavs").forEach(t=>{const s=window.getComputedStyle(t);s.display==="none"||s.position!=="fixed"&&s.position!=="sticky"||t.getBoundingClientRect().top>=window.innerHeight/2||(e=Math.max(e,t.offsetHeight))}),e}setupHandle(){const e=this.mapSlot.querySelector("[data-wfav-map-handle]");e&&this.on(e,"click",()=>{const t=this.root.classList.toggle("wfav-map-expanded");e.setAttribute("aria-expanded",t?"true":"false")})}setupOffsets(){this.updateOffsets(),this.on(window,"resize",()=>{this.resizeScheduled||(this.resizeScheduled=!0,window.requestAnimationFrame(()=>{this.resizeScheduled=!1,this.updateOffsets()}))})}updateOffsets(){let e=this.topHeaderHeight();const t=document.getElementById("wpadminbar");t&&window.getComputedStyle(t).position==="fixed"&&(e+=t.offsetHeight),this.root.style.setProperty("--wfav-map-offset-top",e+"px"),this.root.style.setProperty("--wfav-map-mobile-offset-top",e+"px")}prefersReducedMotion(){return window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}}export{r as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.