forked from codebar/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (32 loc) · 1.05 KB
/
Copy pathscript.js
File metadata and controls
37 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function getGithubInfo(user) {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","https://api.github.com/users/"+user,false);
xmlhttp.send();
return xmlhttp;
}
function showUser(user) {
$('#profile .information').show();
$('#profile .avatar').show();
$('#profile h2').html(user.login + " is GitHub user #" + user.id);
$('#profile .information').html("<a class='profile' href='"+user.html_url+"'> Go to "+ user.name+"'s profile</a>");
$('#profile .avatar').html("<img src=https://gravatar.com/avatar/"+ user.gravatar_id+"?s=220/>");
}
function noSuchUser(username) {
$('#profile h2').html("No user " + username);
$('#profile .information').hide();
$('#profile .avatar').hide();
}
$(document).ready(function(){
$(document).on('keypress', '#username', function(e){
if (e.which == 13) {
username = $(this).val();
$(this).val("");
response = getGithubInfo(username);
if (response.status == 200) {
showUser(JSON.parse(response.responseText));
} else {
noSuchUser(username);
}
}
})
});