-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tomer #14
Open
tomergol15
wants to merge
5
commits into
ColmanDevClubORG:main
Choose a base branch
from
tomergol15:tomer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tomer #14
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e94c343
get the array from JSON-file, duplicate the cards, filter it by region
tomergol15 9c305ac
save the details of selected country when switch a page, and innerHtm…
tomergol15 9842051
added func of filter by search input that check if the countries arra…
tomergol15 1c4f3d0
added folder of js for index.js and details.js file
tomergol15 9d63493
changes after pull request : dill with white spaces in serach func, c…
tomergol15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
console.log("hello details.page"); | ||
const loader = document.querySelector(".loader"); | ||
loader.style.display = "none"; | ||
|
||
const countryDetails = JSON.parse(localStorage.getItem("selectedCountry")); | ||
console.log("selected country", countryDetails); | ||
|
||
const htmlDetails = document.querySelector('.country-details'); | ||
htmlDetails.innerHTML = `<a href="#" class="country scale-effect" data-country-name="${countryDetails.name}"> | ||
<div class="country-flag"> | ||
<img src=${countryDetails.flagImg} | ||
alt="${countryDetails.name} FLag" /> | ||
</div> | ||
<div class="country-info"> | ||
<h2 class="country-title">${countryDetails.name}</h2> | ||
<ul class="country-brief"> | ||
<li>${countryDetails.population}</li> | ||
<li>${countryDetails.region}</li> | ||
<li>${countryDetails.capital}</li> | ||
</ul> | ||
</div> | ||
</a>`; | ||
document.querySelector(".country-flag img").style.width = "450px"; |
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,155 @@ | ||
console.log('hello'); | ||
let countries = []; | ||
const containerCountries = document.querySelector(".countries-grid"); | ||
const countryCardTemplate = document.querySelector(".country.scale-effect"); | ||
|
||
fetch('./CountriesData.json') | ||
.then((res) => { | ||
if (!res.ok) { | ||
throw new Error(`HTTP error! Status: ${res.status}`); | ||
} | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
countries = data; | ||
console.log(data); | ||
innerDetailsIntoCards(countries); | ||
}) | ||
.catch((error) => { | ||
console.error("Unable to fetch data:", error); | ||
}); | ||
|
||
const innerDetailsIntoCards = (array) => { | ||
containerCountries.innerHTML = ''; | ||
|
||
array.forEach((country) => { | ||
const cloneCard = countryCardTemplate.cloneNode(true); | ||
|
||
const titleElement = cloneCard.querySelector(".country-title"); | ||
const flagImage = cloneCard.querySelector(".country-flag img"); | ||
const countryInfo = cloneCard.querySelectorAll(".country-brief li"); | ||
|
||
titleElement.textContent = country.name; | ||
flagImage.src = country.flag; | ||
flagImage.alt = `${country.name}`; | ||
|
||
countryInfo[0].textContent = "Population: "; | ||
const populationStrong = document.createElement("strong"); | ||
populationStrong.textContent = country.population; | ||
countryInfo[0].appendChild(populationStrong); | ||
|
||
countryInfo[1].textContent = "Region: "; | ||
const regionStrong = document.createElement("strong"); | ||
regionStrong.textContent = country.region; | ||
countryInfo[1].appendChild(regionStrong); | ||
|
||
|
||
countryInfo[2].textContent = "Capital: "; | ||
const capitalStrong = document.createElement("strong"); | ||
capitalStrong.textContent = country.capital; | ||
countryInfo[2].appendChild(capitalStrong); | ||
|
||
containerCountries.appendChild(cloneCard); | ||
}); | ||
}; | ||
|
||
const openDropDown = () => { | ||
const dropDown = document.querySelector(".dropdown-wrapper"); | ||
console.log('enter'); | ||
dropDown.classList.toggle("open"); | ||
} | ||
|
||
const regions = ["All", "Africa", "Americas", "Asia", "Europe", "Oceania"]; | ||
const createDropDownBody=()=>{ | ||
const dropdownBody = document.createElement("div"); | ||
dropdownBody.classList.add("dropdown-body"); | ||
const ul = document.createElement("ul"); | ||
|
||
regions.forEach((region)=>{ | ||
const li = document.createElement('li'); | ||
li.textContent = region; | ||
li.setAttribute("data-region", region.toLowerCase()); | ||
li.setAttribute("onClick", "filterByRegion(event)"); | ||
ul.appendChild(li); | ||
}); | ||
dropdownBody.appendChild(ul); | ||
const dropdownWrapper = document.querySelector(".dropdown-wrapper"); | ||
dropdownWrapper.appendChild(dropdownBody); | ||
} | ||
createDropDownBody(); | ||
|
||
const filterByRegion = (event) => { | ||
const region = event.target.getAttribute("data-region"); | ||
console.log("select region:" + region) | ||
|
||
if(region!="all"){ | ||
const result = countries.filter((country)=>{ | ||
return country.region.toLowerCase() == region.toLowerCase() | ||
}) | ||
console.log(result); | ||
innerDetailsIntoCards(result); | ||
} | ||
else{ | ||
innerDetailsIntoCards(countries); | ||
} | ||
|
||
// const result = countries.filter((country)=>{ | ||
// return country.region === "Africa"; | ||
// }) | ||
// console.log(result); | ||
} | ||
|
||
const matchValues = (country, input) => { | ||
return (country.name.toLowerCase().includes(input) || | ||
country.population.toString().includes(input)) || | ||
country.region.toLowerCase().includes(input) || | ||
country.capital.toLowerCase().includes(input) | ||
} | ||
const filterBySerach = (event) =>{ | ||
console.log("enter to filterbyserach func"); | ||
const input = event.target.value.toLowerCase().trim(); //ignore white spaces and make it lowercase letters | ||
console.log(input); | ||
|
||
const resultBySearch = countries.filter((country)=>{ | ||
return matchValues(country,input); | ||
}) | ||
console.log(resultBySearch); | ||
innerDetailsIntoCards(resultBySearch); | ||
} | ||
|
||
|
||
const switchPage = (event) =>{ | ||
const card = event.currentTarget; | ||
console.log(card.innerHTML); | ||
|
||
const titleElement = card.querySelector(".country-title").textContent; | ||
const flagImage = card.querySelector(".country-flag img").src; | ||
const population = card.querySelector(".country-brief li:nth-child(1)").textContent; | ||
const region = card.querySelector(".country-brief li:nth-child(2)").textContent; | ||
const capital = card.querySelector(".country-brief li:nth-child(3)").textContent; | ||
|
||
const countryInfo = {name:titleElement, flagImg:flagImage, population:population, region: region, capital:capital}; | ||
console.log(countryInfo); | ||
localStorage.setItem("selectedCountry", JSON.stringify(countryInfo)); | ||
window.location.href = "details.html"; | ||
} | ||
|
||
|
||
//maybe do this | ||
// const changeColorOfPage = () =>{ | ||
// console.log("enter"); | ||
// const currentColor = getComputedStyle(document.body).backgroundColor; | ||
|
||
// if (currentColor === "rgb(33, 37, 41)") { | ||
// document.body.style.backgroundColor = "rgb(255, 255, 255)"; | ||
// } else { | ||
// document.body.style.backgroundColor = "rgb(33, 37, 41)"; | ||
// } | ||
// }; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE!
Consider a case where the user enters " Israel " (with spaces and tabs before and after the word)
https://www.geeksforgeeks.org/string-strip-in-javascript/