-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from GSG-G8/25-Refactor-Dom
Refactor the dom function
- Loading branch information
Showing
8 changed files
with
455 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* { | ||
margin: 0; | ||
padding: 0 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
const viewDetails = document.querySelector('#viewDetails'); | ||
const searchInput = document.querySelector('#searchInput'); | ||
const mapContainer = document.querySelector('.map__container'); | ||
const header = document.querySelector('.header'); | ||
|
||
// Extra coordinates for testing (41.40338, 2.17403) | ||
let mapSrc = '31.5129811,34.4464425'; | ||
const src = `https://www.google.com/maps/embed/v1/place?q=${mapSrc.split(',')[0]}%2C%20${mapSrc.split(',')[1]}&key=AIzaSyDDOHAK66Eu_kt42uNaSrmXoWZv8r3d_X8`; | ||
|
||
const iframe = document.createElement('iframe'); | ||
iframe.setAttribute('width', `${window.innerWidth}`); | ||
iframe.setAttribute('height', '300px'); | ||
iframe.setAttribute('frameborder', '0'); | ||
iframe.setAttribute('style', 'border:0'); | ||
iframe.setAttribute('allowfullscreen', ''); | ||
iframe.setAttribute('src', `${src}`); | ||
|
||
document.querySelector('.header').appendChild(iframe); | ||
const deleteNodeChilds = (node) => { | ||
while (node.firstChild) node.removeChild(node.firstChild); | ||
}; | ||
|
||
// Extra coordinates for testing (41.40338,2.17403) | ||
|
||
let mapSrc = '31.5129811,34.4464425'; // Here the default coordinates are Gaza Sky Geeks coordinates | ||
|
||
const createIframe = () => { | ||
deleteNodeChilds(mapContainer); | ||
const src = `https://www.google.com/maps/embed/v1/place?q=${mapSrc.split(',')[0]}%2C%20${mapSrc.split(',')[1]}&key=AIzaSyDDOHAK66Eu_kt42uNaSrmXoWZv8r3d_X8`; | ||
const iframe = document.createElement('iframe'); | ||
iframe.setAttribute('width', `${window.innerWidth}`); | ||
iframe.setAttribute('height', '300px'); | ||
iframe.setAttribute('frameborder', '0'); | ||
iframe.setAttribute('style', 'border:0'); | ||
iframe.setAttribute('allowfullscreen', ''); | ||
iframe.setAttribute('src', `${src}`); | ||
mapContainer.appendChild(iframe); | ||
}; | ||
(createIframe()); | ||
|
||
const renderTheData = (location) => { | ||
console.log(location); | ||
const section = document.querySelector('.results__container'); | ||
const resultsContainer = document.querySelector('.results__container'); | ||
const div = document.createElement('div'); | ||
const resultsName = document.createElement('h3'); | ||
resultsName.textContent = `Name: ${location[0].name}`; | ||
div.appendChild(resultsName); | ||
|
||
const resultCategory = document.createElement('h3'); | ||
resultCategory.textContent = `Category: ${location[0].category}`; | ||
div.appendChild(resultCategory); | ||
|
||
const resultDescription = document.createElement('h3'); | ||
resultDescription.textContent = `Description: ${location[0].description}`; | ||
div.appendChild(resultDescription); | ||
|
||
const resultCoordinates = document.createElement('h3'); | ||
resultCoordinates.textContent = `Coordinates: ${location[0].coordinates}`; | ||
div.appendChild(resultCoordinates); | ||
|
||
section.appendChild(div); | ||
deleteNodeChilds(resultsContainer); | ||
const createElements = (description, param2) => { | ||
const resultsName = document.createElement('h4'); | ||
resultsName.textContent = `${description}: ${location[0][param2]}`; | ||
div.appendChild(resultsName); | ||
}; | ||
|
||
createElements('Name', 'name'); | ||
createElements('Category', 'category'); | ||
createElements('Description', 'description'); | ||
createElements('Coordinates', 'coordinates'); | ||
|
||
resultsContainer.appendChild(div); | ||
}; | ||
|
||
viewDetails.addEventListener('click', () => { | ||
fetch(`/locations?location=${searchInput.value}`).then((res) => res.json()).then((result) => { | ||
mapSrc = result[0].coordinates; | ||
renderTheData(result); | ||
createIframe(); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.