first commit

This commit is contained in:
Tomas Dvorak
2025-01-04 11:45:15 +01:00
commit 882f91ebf6
335 changed files with 34705 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
'use strict';
import { updateWeather, error404 } from "./app.js";
const defaultLocation = "#/weather?lat=49.0419613&lon=17.4662204" // London
const currentLocation = function () {
window.navigator.geolocation.getCurrentPosition(res => {
const { latitude, longitude } = res.coords;
updateWeather(`lat=${latitude}`, `lon=${longitude}`);
}, err => {
window.location.hash = defaultLocation;
});
}
const searchedLocation = query => updateWeather(...query.split("&"));
// updateWeather("lat=51.5073219", "lon=-0.1276474")
const routes = new Map([
["/current-location", currentLocation],
["/weather", searchedLocation]
]);
const checkHash = function () {
const requestURL = window.location.hash.slice(1);
const [route, query] = requestURL.includes ? requestURL.split("?") : [requestURL];
routes.get(route) ? routes.get(route)(query) : error404();
}
window.addEventListener("hashchange", checkHash);
window.addEventListener("load", function () {
if (!window.location.hash) {
window.location.hash = "#/current-location";
} else {
checkHash();
}
});