Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 82cdbad

Browse files
committed
Solve the homework of the first week of javascript
1 parent 1c03673 commit 82cdbad

File tree

3 files changed

+231
-0
lines changed

3 files changed

+231
-0
lines changed

Week1/assets/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="description" content="Form in HTML & CSS">
7+
<title>HYF Repositories</title>
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
10+
11+
12+
13+
14+
</head>
15+
<body>
16+
17+
18+
<div class="header">
19+
<h3 class="headerH3">HYF Repositories </h3>
20+
<select name="repo" id='reposs'></select>
21+
</div>
22+
23+
24+
25+
<div class="container">
26+
<div id="users"></div>
27+
<div id="users2"></div>
28+
</div>
29+
30+
31+
32+
33+
34+
35+
<div class="footer">
36+
Copyright &copy; 2018 All Right Reserved To Ayham &reg; Team
37+
</div>
38+
39+
40+
41+
<script src="js.js"></script>
42+
43+
44+
45+
</body>
46+
</html>

Week1/assets/js.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'use strict';
2+
3+
4+
var xhr = new XMLHttpRequest();
5+
xhr.open( 'GET' , 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100%27' );
6+
xhr.onload = function() {
7+
if(this.status == 200){
8+
var repos = JSON.parse( this.responseText);
9+
var output = '';
10+
for(var i in repos){
11+
output += '<option value="' + repos[i].name +'">' + repos[i].name + '</option>';
12+
}
13+
document.getElementById('reposs').innerHTML = output;
14+
15+
}
16+
}
17+
18+
xhr.send();
19+
20+
21+
22+
23+
document.getElementById('reposs').addEventListener("change" , loadUsers);
24+
25+
document.getElementById('reposs').addEventListener("change" , loadUsers2);
26+
27+
28+
29+
30+
function loadUsers() {
31+
var option = this.options[this.selectedIndex].value;
32+
33+
34+
35+
var xhr = new XMLHttpRequest();
36+
xhr.open( 'GET' , 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100%27' );
37+
xhr.onload = function() {
38+
if(this.status == 200){
39+
var repos = JSON.parse( this.responseText);
40+
var output = '';
41+
for(var i in repos){
42+
if(option == repos[i].name) {
43+
output = '<div class="user">' +
44+
'<ul>' +
45+
'<li><span>Repository:</span> ' + repos[i].name +'</li>' +
46+
'<li><span>Description:</span> ' + repos[i].description +'</li>' +
47+
'<li><span>Forks:</span> ' + repos[i].forks +'</li>' +
48+
'<li><span>Updated:</span> ' + repos[i].updated_at +'</li>' +
49+
'</ul>' +
50+
'</div>';
51+
}
52+
}
53+
54+
document.getElementById('users').innerHTML = output;
55+
}
56+
else {
57+
document.getElementById('users').classList.add('NetwrkError');
58+
document.getElementById('users').innerHTML = "Netwrk error:" + this.status +' - '+ this.statusText;
59+
}
60+
}
61+
62+
xhr.send();
63+
64+
}
65+
66+
67+
68+
function loadUsers2(){
69+
70+
var option = this.options[this.selectedIndex].value;
71+
var url = `https://api.github.com/repos/HackYourFuture/${option}/contributors`;
72+
73+
74+
75+
var xhr = new XMLHttpRequest();
76+
xhr.open( 'GET' , url );
77+
xhr.onload = function() {
78+
if(this.status == 200){
79+
var repos = JSON.parse( this.responseText);
80+
var output = '';
81+
for(var i in repos){
82+
output += '<div class="user">' +
83+
'<img src="' + repos[i].avatar_url + '" width="70" height="70">' +
84+
'<ul>' +
85+
'<li><span>name:</span> ' + repos[i].login +'</li>' +
86+
'<li><span>contributions:</span> ' + repos[i].contributions +'</li>' +
87+
'</ul>' +
88+
'</div>';
89+
90+
}
91+
92+
document.getElementById('users2').innerHTML = output;
93+
94+
95+
}
96+
else {//.classList.add("hide-me");
97+
document.getElementById('users2').classList.add('NetwrkError');
98+
document.getElementById('users2').innerHTML = "Netwrk error:" + this.status +' - '+ this.statusText;
99+
}
100+
}
101+
102+
xhr.send();
103+
}
104+
105+
106+

Week1/assets/style.css

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
.footer{
3+
background: #333;
4+
color: #FFF;
5+
text-align: center;
6+
padding: 10px 0;
7+
}
8+
.container{
9+
background-color: #fff;
10+
width: 40%;
11+
min-height: 50em;
12+
display: flex;
13+
flex-direction: row;
14+
flex-wrap: wrap;
15+
margin: 0 auto;
16+
text-align: left;
17+
padding: 20px 0;
18+
}
19+
20+
21+
span{
22+
color:black;
23+
font-style: italic;
24+
font-weight:bold;
25+
font-size: 18px;
26+
}
27+
#users{
28+
background-color: #fff;
29+
width: 40%;
30+
height: 75%;
31+
display: flex;
32+
flex-direction: column;
33+
margin: 0% 0% 0% 0%;
34+
box-shadow: 0 1px 8px 0 rgba(0, 0, 0, .2), 0 3px 4px 0 rgba(0, 0, 0, .14), 0 3px 3px -2px rgba(0, 0, 0, .12);
35+
}
36+
#users2{
37+
background-color: #fff;
38+
width: 40%;
39+
height: 1075%;
40+
display: flex;
41+
flex-direction: column;
42+
margin: 1% 1% 1% 1%;
43+
box-shadow: 0 1px 8px 0 rgba(0, 0, 0, .2), 0 3px 4px 0 rgba(0, 0, 0, .14), 0 3px 3px -2px rgba(0, 0, 0, .12);
44+
}
45+
46+
.header{
47+
48+
background: #333;
49+
color: #FFF;
50+
font-size: 20px;
51+
text-align: left;
52+
padding: 20px 0;
53+
54+
55+
}
56+
.headerH3{
57+
58+
display: inline;
59+
}
60+
61+
62+
body{
63+
margin: 0;
64+
padding: 0;
65+
font-family: Arial, Tahoma;
66+
}
67+
.user{
68+
display: flex;
69+
padding: 5px;
70+
border-bottom: 2px solid #efefef;
71+
72+
}
73+
.user ul {
74+
list-style: none;
75+
}
76+
77+
.NetwrkError{
78+
background-color: rgb(255, 23, 23) !important;
79+
}

0 commit comments

Comments
 (0)