Skip to content

Commit

Permalink
refactoring embedded script
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbesen committed Oct 9, 2024
1 parent 7c48db5 commit 003a22d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export function formatGeoInfo(loc) {
return str;
}

export function showLocations(html) {
document.querySelector('#results').innerHTML = html;
}

export function locationError(err) {
console.log('Error getting location', err);
let message = `
Expand All @@ -47,15 +43,15 @@ export function locationError(err) {
return `${message}</div>`;
}

export function populateResults(c) {
export function populateResults() {
navigator.geolocation.getCurrentPosition(
function (location) {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
const json = JSON.parse(xhr.response);
const html = formatResults(json);

return showLocations(html);
return document.querySelector('#results').innerHTML = html;
};
xhr.open(
'GET',
Expand All @@ -68,7 +64,7 @@ export function populateResults(c) {
xhr.send();
},
function (err) {
return showLocations(locationError(err));
return document.querySelector('#results').innerHTML = locationError(err);
},
);
}
Expand Down
10 changes: 3 additions & 7 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export function formatGeoInfo(loc) {
return str;
}

export function showLocations(html) {
document.querySelector('#results').innerHTML = html;
}

export function locationError(err) {
console.log('Error getting location', err);
let message = `
Expand All @@ -47,15 +43,15 @@ export function locationError(err) {
return `${message}</div>`;
}

export function populateResults(c) {
export function populateResults() {
navigator.geolocation.getCurrentPosition(
function (location) {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
const json = JSON.parse(xhr.response);
const html = formatResults(json);

return showLocations(html);
return document.querySelector('#results').innerHTML = html;
};
xhr.open(
'GET',
Expand All @@ -68,7 +64,7 @@ export function populateResults(c) {
xhr.send();
},
function (err) {
return showLocations(locationError(err));
return document.querySelector('#results').innerHTML = locationError(err);
},
);
}
Expand Down

0 comments on commit 003a22d

Please sign in to comment.