Skip to content

Commit 16c4567

Browse files
committed
Regenerated v2.2.2
1 parent 2473af7 commit 16c4567

File tree

3 files changed

+80
-38
lines changed

3 files changed

+80
-38
lines changed

index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ <h1>jQuery Github Repos</h1>
2424
</div>
2525

2626
<div class="projects">
27-
<div class="github-repos" data-repo="jquery-boilerplate/boilerplate"></div>
28-
<div class="github-repos" data-repo="zenorocha/diveintohtml5"></div>
29-
<div class="github-repos" data-repo="zenorocha/jquery-github-repos"></div>
30-
<div class="github-repos" data-repo="zenorocha/hub.me"></div>
27+
<div data-repo="jquery-boilerplate/boilerplate"></div>
28+
<div data-repo="zenorocha/diveintohtml5"></div>
29+
<div data-repo="zenorocha/jquery-github-repos"></div>
30+
<div data-repo="zenorocha/hub.me"></div>
3131
</div>
3232

3333
<p class="credits">Made with love by <a href="http://zenorocha.com">Zeno Rocha</a>.</p>
@@ -38,7 +38,7 @@ <h1>jQuery Github Repos</h1>
3838
<script src="js/jquery.github.repos.min.js"></script>
3939

4040
<script>
41-
$('.github-repos').githubRepos();
41+
$('[data-repo]').githubRepos();
4242
</script>
4343

4444
</body>

js/jquery.github.repos.js

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*
2-
* Project: jQuery Github Repos
3-
* Description: A jQuery plugin to display your Github Repositories.
4-
* Author: Zeno Rocha
5-
* License: MIT
2+
* jQuery Github Repos v0.2.2
3+
* A jQuery plugin to display your Github Repositories.
4+
* http://git.io/3A1RMg
5+
*
6+
* Zeno Rocha
7+
* MIT License
68
*/
79

810
// the semi-colon before function invocation is a safety net against concatenated
@@ -30,6 +32,7 @@
3032
this.element = element;
3133
this.$container = $(element);
3234
this.repo = this.$container.attr("data-repo");
35+
this.cached;
3336

3437
// jQuery has an extend method which merges the contents of two or
3538
// more objects, storing the result in the first object. The first object
@@ -45,42 +48,80 @@
4548

4649
Plugin.prototype.init = function () {
4750

48-
var self = this;
51+
var self = this;
52+
var cached;
53+
54+
// Attempt to get cached repo data
55+
if (window.sessionStorage) {
56+
cached = sessionStorage.getItem('gh-repos:' + this.repo);
57+
}
58+
59+
if (cached != null) {
60+
self.applyTemplate(JSON.parse(cached));
61+
}
62+
else {
4963

5064
$.ajax({
5165
url: 'https://api.github.com/repos/' + this.repo,
5266
dataType: 'jsonp',
5367
success: function(results){
5468

55-
var repo = results.data;
56-
var date = new Date(repo.pushed_at);
57-
var pushed_at = date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear();
58-
var $widget = $(' \
59-
<div class="github-box"> \
60-
<div class="github-box-header"> \
61-
<h3> \
62-
<a href="' + repo.url.replace('api.','').replace('repos/','') + '">' + repo.name + '</a> \
63-
</h3> \
64-
<div class="github-stats"> \
65-
<a class="repo-watchers" href="' + repo.url.replace('api.','').replace('repos/','') + '/watchers">' + repo.watchers + '</a> \
66-
<a class="repo-forks" href="' + repo.url.replace('api.','').replace('repos/','') + '/forks">' + repo.forks + '</a> \
67-
</div> \
68-
</div> \
69-
<div class="github-box-content"> \
70-
<p>' + repo.description + ' &mdash; <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \
71-
</div> \
72-
<div class="github-box-download"> \
73-
<p class="repo-update">Latest commit to <strong>master</strong> on ' + pushed_at + '</p> \
74-
<a class="repo-download" href="' + repo.url.replace('api.','').replace('repos/','') + '/zipball/master">Download as zip</a> \
75-
</div> \
76-
</div> \
77-
');
78-
79-
$widget.appendTo(self.$container);
69+
// Handle API failures
70+
if (results.meta.status >= 400 && results.data.message){
71+
console.warn(results.data.message);
72+
return;
73+
}
74+
else {
8075

81-
}
76+
self.applyTemplate(results.data);
8277

78+
// Cache data
79+
if (window.sessionStorage) {
80+
sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data));
81+
}
82+
83+
}
84+
}
8385
});
86+
87+
}
88+
89+
};
90+
91+
Plugin.prototype.applyTemplate = function (repo) {
92+
93+
var self = this;
94+
var date = new Date(repo.pushed_at);
95+
var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();
96+
97+
var $widget = $(' \
98+
<div class="github-box"> \
99+
<div class="github-box-header"> \
100+
<h3> \
101+
<a href="' + repo.url.replace('api.','').replace('repos/','') + '">' + repo.name + '</a> \
102+
</h3> \
103+
<div class="github-stats"> \
104+
<a class="repo-watchers" href="' + repo.url.replace('api.','').replace('repos/','') + '/watchers">' + repo.watchers + '</a> \
105+
<a class="repo-forks" href="' + repo.url.replace('api.','').replace('repos/','') + '/forks">' + repo.forks + '</a> \
106+
</div> \
107+
</div> \
108+
<div class="github-box-content"> \
109+
<p>' + repo.description + ' &mdash; <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \
110+
</div> \
111+
<div class="github-box-download"> \
112+
<p class="repo-update">Latest commit to <strong>master</strong> on ' + pushed_at + '</p> \
113+
<a class="repo-download" href="' + repo.url.replace('api.','').replace('repos/','') + '/zipball/master">Download as zip</a> \
114+
</div> \
115+
</div> \
116+
');
117+
118+
self.appendTemplate($widget);
119+
120+
};
121+
122+
Plugin.prototype.appendTemplate = function ($widget) {
123+
var self = this;
124+
$widget.appendTo(self.$container);
84125
};
85126

86127
// A really lightweight plugin wrapper around the constructor,

js/jquery.github.repos.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)