-
Notifications
You must be signed in to change notification settings - Fork 154
/
mustache-demo.html
128 lines (123 loc) · 4.86 KB
/
mustache-demo.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head>
<title>Mustache Demo</title>
<link rel="stylesheet" type="text/css"
href="https://bootswatch.com/4/cerulean/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<style type="text/css">
.git-user-avatar {
width: 100px;
height: 100px;
}
.center{
text-align: center;
padding-top: 5px;
}
.space{
margin-top: 10px;
}
.git-stars{
color: goldenrodyellow;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header"><h1>Mustache Demo</h1></div>
<div class="row">
<div class="col-md-offset-3 col-md-6">
<h3>Select user</h3>
<select id="git-users" class="form-control">
<option value=""></option>
<option value="facebook">Facebook</option>
<option value="google">Google</option>
<option value="netflix">Netflix</option>
<option value="flipkart">Flipkart</option>
<option value="amzn">Amazon</option>
<option value="microsoft">Microsoft</option>
</select>
</div>
</div>
<div class="space"></div>
<div class="row">
<div class="col-md-offset-3 col-md-6" id="git-user-detail">
</div>
</div>
<div class="space"></div>
<div class="row">
<div class="col-md-offset-3 col-md-6" id="git-user-repos">
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.min.js"></script>
<script type="text/html" id="loading-template">
<div class="alert alert-info center">
<i class="fa fa-spinner fa-spin"></i> Loading ...
</div>
</script>
<script type="text/html" id="git-user-detail-template">
<div class="center">
<img src="{{avatar_url}}" class="git-user-avatar" />
<div class="space"></div>
Github User <a href="{{html_url}}">{{login}}</a>
<div class="space"></div>
Name <a href="{{blog}}">{{name}}</a>
{{#bio}}
<div class="space"></div>
{{bio}}
{{/bio}}
</div>
</script>
<script type="text/html" id="git-user-repos-template">
<ul class="list-group">
{{#items}}
<li class="list-group-item">
<span class="badge">
<i class="fa fa-star git-stars"></i> {{stargazers_count}}
</span>
<a href="{{html_url}}">{{full_name}}</a>
</li>
{{/items}}
</ul>
</script>
<script type="text/javascript">
$(function() {
$("#git-users").on('change', function(){
var username = $(this).val();
getUserDetail(username);
getMostStarredRepos(username);
});
});
function getUserDetail(username){
loading("#git-user-detail");
if ( !username){
$("#git-user-detail").html('');
return;
}
$.getJSON('https://api.github.com/users/'+username, function(data){
var html = Mustache.to_html($("#git-user-detail-template").html(), data);
$("#git-user-detail").html(html);
});
}
function getMostStarredRepos(username){
loading("#git-user-repos");
if ( !username){
$("#git-user-repos").html('');
return;
}
$.getJSON('https://api.github.com/search/repositories?q=user:'
+username+'&sort=stars&per_page=10', function(data){
$("#git-user-repos").html(Mustache.to_html(
$("#git-user-repos-template").html(), data));
});
}
function loading(target){
$(target).html(Mustache.to_html($("#loading-template").html(), {}));
}
</script>
</body>
</html>