frontend: fix event listeners
This commit is contained in:
parent
8564ac5240
commit
9b9f31420e
@ -126,7 +126,7 @@ function setupMap(
|
|||||||
const mapImg = document.querySelector<HTMLImageElement>("#map")!;
|
const mapImg = document.querySelector<HTMLImageElement>("#map")!;
|
||||||
const fetcher = new Throttler(200);
|
const fetcher = new Throttler(200);
|
||||||
|
|
||||||
mapImg.onmousemove = async (event: MouseEvent) => {
|
mapImg.addEventListener('mousemove', async (event: MouseEvent) => {
|
||||||
const mousePosition: Position = { x: event.offsetX, y: event.offsetY };
|
const mousePosition: Position = { x: event.offsetX, y: event.offsetY };
|
||||||
displayMousePosition(mousePositionElement, mousePosition);
|
displayMousePosition(mousePositionElement, mousePosition);
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ function setupMap(
|
|||||||
displayCoords(coordsElement, coords);
|
displayCoords(coordsElement, coords);
|
||||||
|
|
||||||
fetcher.call(async () => await fetchAndDisplayZipCode(coords));
|
fetcher.call(async () => await fetchAndDisplayZipCode(coords));
|
||||||
};
|
});
|
||||||
|
|
||||||
mapImg.onmouseup = async (event: MouseEvent) => {
|
mapImg.addEventListener("mouseup", async (event: MouseEvent) => {
|
||||||
const mousePosition: Position = { x: event.offsetX, y: event.offsetY };
|
const mousePosition: Position = { x: event.offsetX, y: event.offsetY };
|
||||||
displayMousePosition(mousePositionElement, mousePosition);
|
displayMousePosition(mousePositionElement, mousePosition);
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ function setupMap(
|
|||||||
displayCoords(coordsElement, coords);
|
displayCoords(coordsElement, coords);
|
||||||
|
|
||||||
fetcher.call(async () => await fetchAndDisplayZipCode(coords));
|
fetcher.call(async () => await fetchAndDisplayZipCode(coords));
|
||||||
}
|
});
|
||||||
|
|
||||||
mapImg.onmouseleave = (_event: MouseEvent) => {
|
mapImg.onmouseleave = (_event: MouseEvent) => {
|
||||||
displayZipCode(zipCodeElement, null, null, null, null);
|
displayZipCode(zipCodeElement, null, null, null, null);
|
||||||
@ -167,10 +167,10 @@ function setupSearchBar(zipCodeElement: HTMLParagraphElement) {
|
|||||||
const searchInput =
|
const searchInput =
|
||||||
document.querySelector<HTMLInputElement>("#search-input")!;
|
document.querySelector<HTMLInputElement>("#search-input")!;
|
||||||
|
|
||||||
// Prevent typing letters
|
searchInput.addEventListener("keydown", (event) => {
|
||||||
searchBar.onkeypress = event => {
|
if (event.key.length === 1 && !"0123456789".includes(event.key))
|
||||||
event.key !== "Enter" || !isNaN(parseInt(event.key));
|
event.preventDefault();
|
||||||
}
|
});
|
||||||
|
|
||||||
searchBar.addEventListener("submit", async (event: Event) => {
|
searchBar.addEventListener("submit", async (event: Event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user