Skip to content

Commit

Permalink
controlAddedListener submodule extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Stassi committed Nov 14, 2024
1 parent f7156e0 commit 0feb092
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
30 changes: 30 additions & 0 deletions public/leaflet-fullscreen/control-added-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DomEvent } from '../leaflet/leaflet-src.esm.js'

import { setControlTitle } from './set-control-title.js'

export function controlAddedListener({
container,
getFullscreenState,
linkAssign,
onLinkClick,
title,
}) {
return function handleControlAdded(map) {
setControlTitle({
fullscreen: getFullscreenState(),
linkAssign,
title,
})

onLinkClick(async function handleLinkClick(e) {
DomEvent.stopPropagation(e)
DomEvent.preventDefault(e)

await (getFullscreenState()
? document?.exitFullscreen()
: map.getContainer()?.requestFullscreen())
})

return container
}
}
29 changes: 8 additions & 21 deletions public/leaflet-fullscreen/fullscreen-map.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
control as leafletControl,
DomEvent,
DomUtil,
map as leafletMap,
} from '../leaflet/leaflet-src.esm.js'

import { controlAddedListener } from './control-added-listener.js'
import { joinClassNames } from './join-class-names.js'
import { mapLifecycleListener } from './map-lifecycle-listener.js'
import { setControlTitle } from './set-control-title.js'
import { useBoolean } from './use-boolean.js'
import { useLink } from './use-link.js'

Expand Down Expand Up @@ -61,25 +60,13 @@ export function fullscreenMap({

linkAssign({ href: '#' })

control.onAdd = function handleControlAdded(addedMap) {
setControlTitle({
fullscreen: getFullscreenState(),
linkAssign,
title,
})

onLinkClick(async function handleLinkClick(e) {
DomEvent.stopPropagation(e)
DomEvent.preventDefault(e)

await (getFullscreenState()
? document?.exitFullscreen()
: addedMap.getContainer()?.requestFullscreen())
})

return container
}

control.onAdd = controlAddedListener({
container,
getFullscreenState,
linkAssign,
onLinkClick,
title,
})
control.addTo(map)

map.whenReady(handleMapLifecycleChange(true))
Expand Down

0 comments on commit 0feb092

Please sign in to comment.