diff --git a/docs/index.html b/docs/index.html index e8f4b84..55d0653 100644 --- a/docs/index.html +++ b/docs/index.html @@ -38,7 +38,7 @@

the planet.

- We have open positions for technical product designers & design leaders in San Francisco, Seattle, and elsewhere. + We have open positions for technical product designers & design leaders in San Francisco, Seattle, and elsewhere.

We use PCs, Macs, Figma, Sketch, GitHub, JavaScript, ZEIT, and other modern tools to design, prototype, and build the future @@ -116,12 +116,14 @@

document.documentElement.dataset.loaded = true }, 1000) } - addEventListener('load', markDocumentAsLoaded); + + + - \ No newline at end of file + diff --git a/docs/location.js b/docs/location.js new file mode 100644 index 0000000..d7f8505 --- /dev/null +++ b/docs/location.js @@ -0,0 +1,34 @@ +// Object to store location information based on user's IP +// elsewhere is the default +let appData = { + city: "", + country: "", + countryname: "elsewhere" +}; + +// Gets user location, sets the appData object, and renders the user's city onto the page +function getLocation() { + const key = YOUR_ACCESS_KEY; // @Microsoft, this line needs to be replaced with your API key for IPStack. + const api = `http://api.ipstack.com/24.52.253.12?access_key=${key}`; + + fetch(api) + .then(dataWrappedByPromise => dataWrappedByPromise.json()) + .then(APIdata => { + appData.country = APIdata.country_code; // Set the country + appData.countryname = APIdata.country_name; // Set the country name + appData.city = APIdata.city; // Set the city + }) + .then(detectLocation => { + changeLocation(); + }); +} + +// Gets the user's location from the appData object and renders it on-screen +function changeLocation() { + // Check to see that city is not empty, otherwise render user's city on-screen + let local = document.getElementById("location"); + appData.city == "" ? "" : (local.innerHTML = appData.city); +} + +// Run the getLocation function +getLocation(); diff --git a/example.env b/example.env index 369fd57..7b0ca5e 100644 --- a/example.env +++ b/example.env @@ -1,2 +1,3 @@ # Github access token https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ -ACCESS_TOKEN=*************************** \ No newline at end of file +ACCESS_TOKEN=*************************** +LOCATION_KEY=8fa1dab1f671740a6e295f8674fb1ca6