| 7 | import observe from '../helpers/selector-observer.js'; |
| 8 | |
| 9 | function addLocation({nextElementSibling, nextSibling}: SVGElement): Element { |
| 10 | // `nextSibling` alone might point to an empty TextNode before an element, if there’s an element |
| 11 | const userLocation = nextElementSibling ?? nextSibling as Element; |
| 12 | |
| 13 | const locationName = userLocation.textContent.trim(); |
| 14 | const mapLink = `https://www.openstreetmap.org/search?query=${encodeURIComponent(locationName)}`; |
| 15 | |
| 16 | userLocation.before(' '); // Keeps the link’s underline from extending out to the icon |
| 17 | const link = <a className="Link--primary" href={mapLink} />; |
| 18 | |
| 19 | if (closestElementOptional('.Popover', userLocation.parentElement!)) { |
| 20 | // Match the style of other links in the hovercard |
| 21 | link.classList.add('text-underline'); |
| 22 | } |
| 23 | |
| 24 | wrap(userLocation, link); |
| 25 | |
| 26 | return link; |
| 27 | } |
| 28 | |
| 29 | function initOnce(): void { |
| 30 | observe([ |