forked from leachim6/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary.html
204 lines (180 loc) · 8.26 KB
/
summary.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>All programming hello world code</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<style type="text/css" media="screen">
#main {
margin-top: 10px;
padding-top: 10px;
min-width: 725px;
min-height: 100px;
border: 1px #eee solid;
border-radius: 4px 4px 0 0;
}
.nav>li>a {
padding: 3px 6px;
}
.tab-content {
margin-top: 4px;
}
</style>
</head>
<body>
<div id="main" class="container">
<div id="helloword">
<!-- Nav tabs -->
<ul id="langgroups" class="nav nav-tabs" role="tablist">
<li class="active"><a href="#aboutTab" role="tab" data-toggle="tab">About</a></li>
</ul>
<!-- Tab panes -->
<div id="langcodegroups" class="tab-content">
<div class="tab-pane fade in active" id="aboutTab">
<ul class="list-group">
<li class="list-group-item">
<h4 id="about-heading" class="list-group-item-heading">Hello world in every programming language.</h4>
<div id="about-text" class="list-group-item-text">
</div>
</li>
</ul>
</div>
</div>
</div>
<p>
© 2014 Powered by <a href="jquery.com">jQuery</a>, <a href="http://getbootstrap.com">Boostrap</a> and <a href="https://developer.github.com/v3/">Github APIs</a>.
</p>
</div>
<script type='text/javascript' src='http://ajax.useso.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<!-- Latest compiled and minified JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
// curl -i https://api.github.com/repos/pingjiang/hello-world/readme
// curl -i https://api.github.com/repos/pingjiang/hello-world/contents/
jQuery(document).ready(function($) {
var REPOS_USER = 'leachim6';// leachim6
var REPOS_NAME = 'hello-world';
var GITHUB_API = 'https://api.github.com/repos/' + REPOS_USER + '/' + REPOS_NAME + '/contents';
$('#about-text').html('<dl class="dl-horizontal"><dt>User</dt><dd><a href="https://github.com/' + REPOS_USER + '">' + REPOS_USER
+ '</a></dd><dt>Repository</dt><dd><a href="https://github.com/' + REPOS_USER + '/' + REPOS_NAME + '">' + REPOS_NAME
+ '</a></dd><dt>Contents API</dt><dd><a href="' + GITHUB_API + '">' + GITHUB_API + '</a></dd></dl>');
function onGithubError(data) {
$('#about-heading').text('Github Error');
$('#about-text').html('<p>'
+ data.message + '</p><p>Documentation reference <a href="'
+ data.documentation_url + '">'
+ data.documentation_url + '</a>.</p><p>Please refresh later.</p>');
}
function htmlEncode(value){
return $('<div/>').text(value).html();
}
function htmlDecode(value){
return $('<div/>').html(value).text();
}
function loadContent(self_url, onSuccess) {
$.ajax({
type: "POST",
url: self_url + '&callback=?',
crossDomain: true,
statusCode: {
403: function(data) {
onGithubError(data);
}
},
success: function (data) {
var result = data.data;
if (result.content == undefined || result.content == null) {
onSuccess('Fetch content of code ' + self_url + ' failed.');
return;
}
var content = atob(result.content);
onSuccess(content);
},
dataType: 'jsonp'
});
}
function loadLanguages(langGroupName, appendToId, langGroup, onSuccess) {
$.ajax({
type: "POST",
url: langGroup + '&callback=?',
crossDomain: true,
statusCode: {
403: function(data) {
onGithubError(data);
}
},
success: function (data) {
var entries = data.data;
if (!(entries instanceof Array)) {
onGithubError(entries);
return;
}
$.each(entries, function(i, entry) {
if (entry.type == 'file') {
var codeCssClass = 'code-' + entry.name.split('.')[0].toLowerCase();
loadContent(entry._links.self, function(content) {
// console.log(content);
$('<li class="list-group-item"><h4 class="list-group-item-heading">' + entry.name
+ '</h4><div class="list-group-item-text"><pre class="code">' + htmlEncode(content) + '</pre><p>Code: <a class="langcode" href="' + entry.html_url + '">'
+ entry.html_url + '</a></p></div></li>').appendTo(appendToId);
});
}
});
if (entries == undefined || entries == null || entries.length == 0) {
$('<li class="list-group-item"><a class="list-group-item langcode" href="#">None</a></li>').appendTo(appendToId);
}
onSuccess();
},
dataType: 'jsonp'
});
}
$.ajax({
type: "POST",
url: GITHUB_API + '?callback=?',
crossDomain: true,
statusCode: {
403: function(data) {
onGithubError(data);
}
},
success: function (data) {
var entryGroups = data.data;
if (!(entryGroups instanceof Array)) {
onGithubError(entryGroups);
return;
}
var entryCache = {};
$.each(entryGroups, function(i, entryGroup) {
entryCache[entryGroup.name] = entryGroup._links.self;
if (entryGroup.name != '#' && entryGroup.type == 'dir') {
$('<li><a class="langgroup" href="#' + entryGroup.name
+ 'Tab" data-loadlink="' + entryGroup._links.self + '" role="tab" data-toggle="tab">'
+ entryGroup.name + '</a></li>').appendTo('#langgroups');
$('<div class="tab-pane fade" id="' + entryGroup.name
+ 'Tab"><ul class="list-group langcodes" class="nav nav-tabs" role="tablist"></ul></div>').appendTo('#langcodegroups');
}
});
$('.langgroup').click(function() {
var entryGroupName = $(this).text();
var tabId = $(this).attr('href');
var tab = $(tabId);
var selected = $(this);
var langcodes = $(tabId + '>ul.langcodes>li');
if (langcodes == undefined || langcodes.length == 0) {
loadLanguages(entryGroupName, tabId + '>ul.langcodes', entryCache[entryGroupName], function() {
selected.tab('show');
});
} else {
selected.tab('show');
}
});
},
dataType: 'jsonp'
});
});
</script>
</body>
</html>