forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 2
Week2-AmirHossein-Project added #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c985479
Folder Amirhossein added
amirhshad 7a6f20d
This is test
amirhshad 102f0ef
Ex1 finished
amirhshad 01b520d
Ex2 is added
amirhshad b49bf00
Merge pull request #1 from samravan/master
amirhshad caa2416
Merge branch 'master' into week2-AmirHossein
amirhshad e31194d
Pokoman app added - folders moved
amirhshad 0d074dd
Ex3 is finished and added
amirhshad 883ae1f
Minor bugs fixed
amirhshad 2914a78
Add folder Amirhossein to hackyourrepo-app
amirhshad 4a5c10a
Week2 project started
amirhshad 7fdf479
Element factory function is added
amirhshad 6fc3298
Elements are added to project week2
amirhshad da65b19
Projec's element is added
amirhshad dead44a
LEft box is finished
amirhshad 777ae24
Some major bugs of project is fixed
amirhshad c65245a
Hackyourepo project - insert items to DOM is done
amirhshad 5f72ae7
Hackyourrepo project is finish and added
amirhshad 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,11 @@ | ||
| function checkDoubleDigits(number) { | ||
| return new Promise((resolve, reject) => { | ||
| if(number > 10) { | ||
| resolve('The number is bigger than 10!'); | ||
| } else { | ||
| reject('Error! The number is smaller than 10'); | ||
| }; | ||
| }); | ||
|
|
||
| } | ||
| checkDoubleDigits(30).then(response => console.log(response)); |
This file contains hidden or 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,16 +1,21 @@ | ||
| const getAnonName = (firstName) => { | ||
| return new Promise((resolve, reject) => { | ||
| const fullName = `${firstName} Doe` | ||
| resolve(fullName) | ||
| console.log(fullName) | ||
|
|
||
|
|
||
|
|
||
| reject(new Error("You didn't pass in a first name!")) | ||
| const fullName = `${firstName} Doe`; | ||
| if(firstName) { | ||
| resolve(fullName); | ||
| } else { | ||
| reject(new Error("You didn't pass in a first name!")); | ||
| } | ||
| }); | ||
| }; | ||
| getAnonName('Masood') | ||
| .then(response => { | ||
| console.log(response) | ||
| }) | ||
| .catch(error => { | ||
| console.log(error) | ||
| }) | ||
|
|
||
| }) | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| getAnonName() |
This file contains hidden or 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,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } |
This file contains hidden or 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,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Pokemon-app</title> | ||
| </head> | ||
| <body> | ||
| <!-- <select name="" id=""> | ||
| <option value=""></option> | ||
| </select> --> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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,49 @@ | ||
| window.onload = main; | ||
| function main() { | ||
| const url = 'https://pokeapi.co/api/v2/pokemon/?limit=20&offset=20' | ||
| const btn = document.createElement('button'); | ||
| btn.innerHTML = 'Get Pokemon!' | ||
| document.body.appendChild(btn); | ||
| const select = document.createElement('select'); | ||
| document.body.appendChild(select); | ||
| btn.addEventListener('click', () => [ | ||
| fetchData(url, select) | ||
| ]); | ||
| } | ||
|
|
||
| function addPokemonToDOM(data, select) { | ||
| data.results.forEach(element => { | ||
| const option = document.createElement('option'); | ||
| option.innerHTML = element.name; | ||
| option.value = element.name; | ||
| select.appendChild(option); | ||
|
|
||
| }); | ||
| let image = document.createElement('img'); | ||
| select.addEventListener('input', () => { | ||
| data.results.forEach(element => { | ||
| if(select.value == element.name) { | ||
| const pokUrl = element.url; | ||
| image.src = '' | ||
| fetch(pokUrl) | ||
| .then(response => response.json()) | ||
| .then(data => { | ||
| image.src = data.sprites.front_default; | ||
| document.body.appendChild(image); | ||
| }) | ||
| .catch(error => console.log(error)) | ||
| } | ||
|
|
||
|
|
||
| }) | ||
| } ) | ||
| } | ||
|
|
||
| function fetchData(url, select) { | ||
| fetch(url) | ||
| .then(res => res.json()) | ||
| .then(data => addPokemonToDOM(data, select)) | ||
| .catch(error => console.log(error)); | ||
|
|
||
| } | ||
|
|
||
0
hackyourrepo-app/hyf.png → hackyourrepo-app/AmirHossein/hyf.png
100755 → 100644
File renamed without changes
This file contains hidden or 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,28 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
| /> | ||
| <meta name="theme-color" content="#000000" /> | ||
| <meta name="apple-mobile-web-app-capable" content="yes" /> | ||
| <meta name="mobile-web-app-capable" content="yes" /> | ||
| <meta name="format-detection" content="telephone=no" /> | ||
| <link rel="apple-touch-icon" href="./hyf.png" /> | ||
| <link rel="shortcut icon" type="image/png" href="./hyf.png" /> | ||
| <title>HackYourRepo</title> | ||
| <link | ||
| href="https://fonts.googleapis.com/css?family=Roboto:400,700" | ||
| rel="stylesheet" | ||
| /> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| </head> | ||
| <body> | ||
|
|
||
|
|
||
|
|
||
| <script src="./script.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 hidden or 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,149 @@ | ||
| "use strict"; | ||
|
|
||
| /* | ||
| Write here your JavaScript for HackYourRepo! | ||
| */ | ||
| window.onload = main; | ||
|
|
||
| function main() { | ||
| const url = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; // The repositories API | ||
| const elFactory = (type, attributes, ...children) => { // Function for creating elements | ||
| const el = document.createElement(type); | ||
| let key; | ||
| for (key in attributes) { | ||
| el.setAttribute(key, attributes[key]); | ||
| }; | ||
|
|
||
| children.forEach(child => { | ||
| if (typeof child === 'string') { | ||
| el.appendChild(document.createTextNode(child)); | ||
| } else { | ||
| el.appendChild(child); | ||
| } | ||
| }); | ||
|
|
||
| return el | ||
| }; | ||
|
|
||
| const container = elFactory('div', {class: 'container'}); | ||
| const header = elFactory('section', {id: 'header'}, | ||
| elFactory('p', {}, 'HYF Repositories'), | ||
| elFactory('select', {class: 'selectMenu'} | ||
| )); | ||
| const bottomBox = elFactory('div', {class: 'bottom-box'}); | ||
| const errorBox = elFactory('div', {id: 'error'}); | ||
| const leftSide = elFactory('section', {id: 'left-side'}); | ||
| const card = elFactory('div', {class: 'card'}, // Cards that inserted to the left box. | ||
amirhshad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| elFactory('table', {}, | ||
| elFactory('tr', {}, | ||
| elFactory('td', {class: 'col-left'}, 'Repositories: '), | ||
| elFactory('td', {class: 'col-right rep-text'}, elFactory('a', {href: '#', class: 'repo-link'}, ))), | ||
| elFactory('tr', {}, | ||
| elFactory('td', {class: 'col-left'}, 'Description: '), | ||
| elFactory('td', {class: 'col-right rep-description'}, '')), | ||
| elFactory('tr', {}, | ||
| elFactory('td', {class: 'col-left'}, 'Forks: '), | ||
| elFactory('td', {class: 'col-right rep-fork'}, '')), | ||
| elFactory('tr', {}, | ||
| elFactory('td', {class: 'col-left'}, 'Update: '), | ||
| elFactory('td', {class: 'col-right rep-update'}, '')))); | ||
|
|
||
| const rightSide = elFactory('section', {id: 'right-side'}, | ||
| elFactory('div', {id: 'contributor'}, 'Contributors')); | ||
| const select = header.querySelector('select'); | ||
| const cardName = elFactory('div', {id: 'cardNameBox'}); // Box to add small cards of contributors | ||
| container.appendChild(header); | ||
| container.appendChild(errorBox); | ||
| bottomBox.appendChild(leftSide); | ||
| bottomBox.appendChild(rightSide); | ||
| leftSide.appendChild(card); | ||
| rightSide.appendChild(cardName); | ||
| container.appendChild(bottomBox); | ||
| document.body.appendChild(container) | ||
|
|
||
| // Adding repository names to the select element. | ||
| function addrepoNames(data) { | ||
| data.forEach(element => { | ||
| const option = elFactory('option', {value: ''}) | ||
| option.innerHTML = element.name; | ||
| option.value = element.name; | ||
|
|
||
| select.appendChild(option); | ||
| }); | ||
|
|
||
| // Function to fetch data for items in select elemen. | ||
| select.addEventListener('input', () => { | ||
| document.querySelector('#left-side').style.display = 'block'; | ||
| document.querySelector('#contributor').style.display = 'block'; | ||
| cardName.innerHTML = '' | ||
| // IF the value of option is equal to element name this function will work. | ||
| // Despite showing error this section still works! I don't know how should I fix it. | ||
| data.forEach(element => { | ||
| if(select.value == element.name) { | ||
| // Adding items to description part | ||
| const repoDescription = card.querySelector('.rep-description'); | ||
| const repoName = card.querySelector('.repo-link'); | ||
| const forks = card.querySelector('.rep-fork'); | ||
| const update = card.querySelector('.rep-update'); | ||
| repoDescription.innerHTML = element.description; | ||
| repoName.innerHTML = element.name; | ||
| repoName.href = element.html_url; | ||
| forks.innerHTML = element.forks; | ||
| update.innerHTML = element.updated_at; | ||
|
|
||
| const contributorsUrl = element.contributors_url; // URL of contributors | ||
| fetch(contributorsUrl) | ||
| .then(response => response.json()) | ||
|
|
||
| // Creat and adding contributors name to the right side of the page. | ||
| .then(data2 => { | ||
| data2.forEach(element2 => { | ||
| const smallCard = elFactory('div', {class: 'card small-card'}, | ||
| elFactory('img', {src: '', class: 'userPhoto', width: '50px'}), | ||
| elFactory('a', {href: '', class: 'userName'}, ''), | ||
| elFactory('div', {class: 'badge'}, '')); | ||
| const userName = smallCard.querySelector('.userName'); | ||
| const image = smallCard.querySelector('img'); | ||
| const badge = smallCard.querySelector('.badge'); | ||
| image.src = element2.avatar_url; | ||
| userName.innerHTML = element2.login; | ||
| userName.href = element2.html_url; | ||
| badge.innerHTML = element2.contributions; | ||
| document.getElementById('error').style.display = 'none'; | ||
| cardName.appendChild(smallCard) | ||
| }) | ||
| }) | ||
| .catch(error => { | ||
| errorBox.innerHTML = error; | ||
| document.getElementById('error').style.display = 'block'; | ||
| }) | ||
| console.log(container) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| }; | ||
| function fetchData() { | ||
| fetch(url) | ||
| .then(res => res.json()) | ||
| .then(data => addrepoNames(data)) | ||
| .catch(error => { | ||
| errorBox.innerHTML = error; | ||
| document.getElementById('error').style.display = 'block'; | ||
| }) | ||
| } | ||
| fetchData(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.