Skip to content

Commit 93f0fd9

Browse files
author
Zeno Rocha
committed
Release v0.3.4
1 parent c457a2e commit 93f0fd9

File tree

3 files changed

+46
-62
lines changed

3 files changed

+46
-62
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-github",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"homepage": "https://github.com/zenorocha/jquery-github",
55
"authors": [
66
"Zeno Rocha <hi@zenorocha.com>"

dist/jquery.github.js

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* jQuery Github - v0.3.2
2+
* jquery-github - v0.3.4
33
* A jQuery plugin to display your Github Repositories.
4-
* https://github.com/zenorocha/jquery-github/
4+
* https://github.com/zenorocha/jquery-github
55
*
66
* Copyright (c) 2014
77
* MIT License
@@ -10,91 +10,84 @@
1010

1111
function GithubRepo( repo ) {
1212
this.description = repo.description;
13-
this.forks = repo.forks;
13+
this.forks = repo.forks_count;
1414
this.name = repo.name;
1515
this.open_issues = repo.open_issues;
1616
this.pushed_at = repo.pushed_at;
1717
this.url = repo.url;
18-
this.watchers = repo.watchers;
18+
this.stargazers = repo.stargazers_count;
1919
}
2020

2121
// Parses HTML template
2222
GithubRepo.prototype.toHTML = function () {
23-
var self = this;
24-
25-
self.pushed_at = self._parsePushedDate( self.pushed_at ),
26-
self.url = self._parseURL( self.url );
23+
this.pushed_at = this._parsePushedDate( this.pushed_at ),
24+
this.url = this._parseURL( this.url );
2725

2826
return $(
2927
"<div class='github-box'>" +
3028
"<div class='github-box-header'>" +
3129
"<h3>" +
32-
"<a href='" + self.url + "'>" + self.name + "</a>" +
30+
"<a href='" + this.url + "'>" + this.name + "</a>" +
3331
"</h3>" +
3432
"<div class='github-stats'>" +
35-
"<a class='repo-stars' title='Stars' data-icon='7' href='" + self.url + "/watchers'>" + self.watchers + "</a>" +
36-
"<a class='repo-forks' title='Forks' data-icon='f' href='" + self.url + "/network'>" + self.forks + "</a>" +
37-
"<a class='repo-issues' title='Issues' data-icon='i' href='" + self.url + "/issues'>" + self.open_issues + "</a>" +
33+
"<a class='repo-stars' title='Stars' data-icon='7' href='" + this.url + "/stargazers'>" + this.stargazers + "</a>" +
34+
"<a class='repo-forks' title='Forks' data-icon='f' href='" + this.url + "/network'>" + this.forks + "</a>" +
35+
"<a class='repo-issues' title='Issues' data-icon='i' href='" + this.url + "/issues'>" + this.open_issues + "</a>" +
3836
"</div>" +
3937
"</div>" +
4038
"<div class='github-box-content'>" +
41-
"<p>" + self.description + " &mdash; <a href='" + self.url + "#readme'>Read More</a></p>" +
39+
"<p>" + this.description + " &mdash; <a href='" + this.url + "#readme'>Read More</a></p>" +
4240
"</div>" +
4341
"<div class='github-box-download'>" +
44-
"<p class='repo-update'>Latest commit to <strong>master</strong> on " + self.pushed_at + "</p>" +
45-
"<a class='repo-download' title='Download as zip' data-icon='w' href='" + self.url + "/zipball/master'></a>" +
42+
"<p class='repo-update'>Latest commit to <strong>master</strong> on " + this.pushed_at + "</p>" +
43+
"<a class='repo-download' title='Download as zip' data-icon='w' href='" + this.url + "/zipball/master'></a>" +
4644
"</div>" +
4745
"</div>");
4846
};
4947

5048
// Parses pushed_at with date format
5149
GithubRepo.prototype._parsePushedDate = function ( pushed_at ) {
52-
var self = this,
53-
date = new Date( pushed_at );
50+
var date = new Date( pushed_at );
5451

5552
return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear();
5653
};
5754

5855
// Parses URL to be friendly
5956
GithubRepo.prototype._parseURL = function ( url ) {
60-
var self = this;
61-
6257
return url.replace( "api.", "" ).replace( "repos/", "" );
6358
};
6459

6560
// -- Github Plugin ------------------------------------------------------------
6661

6762
function Github( element, options ) {
68-
var self = this,
69-
defaults = {
63+
var defaults = {
7064
iconStars: true,
7165
iconForks: true,
7266
iconIssues: false
7367
};
7468

75-
self.element = element;
76-
self.$container = $( element );
77-
self.repo = self.$container.attr( "data-repo" );
69+
this.element = element;
70+
this.$container = $( element );
71+
this.repo = this.$container.attr( "data-repo" );
7872

79-
self.options = $.extend( {}, defaults, options ) ;
73+
this.options = $.extend( {}, defaults, options ) ;
8074

81-
self._defaults = defaults;
75+
this._defaults = defaults;
8276

83-
self.init();
84-
self.displayIcons();
77+
this.init();
78+
this.displayIcons();
8579
}
8680

8781
// Initializer
8882
Github.prototype.init = function () {
89-
var self = this,
90-
cached = self.getCache();
83+
var cached = this.getCache();
9184

9285
if ( cached !== null ) {
93-
self.applyTemplate( JSON.parse( cached ) );
94-
}
95-
else {
96-
self.requestData( self.repo );
86+
this.applyTemplate( JSON.parse( cached ) );
87+
return;
9788
}
89+
90+
this.requestData( this.repo );
9891
};
9992

10093
// Display or hide icons
@@ -111,57 +104,49 @@ Github.prototype.displayIcons = function () {
111104

112105
// Request repositories from Github
113106
Github.prototype.requestData = function ( repo ) {
114-
var self = this;
107+
var that = this;
115108

116109
$.ajax({
117110
url: "https://api.github.com/repos/" + repo,
118111
dataType: "jsonp",
119112
success: function( results ) {
120-
var result_data = results.data;
113+
var result_data = results.data,
114+
isFailling = results.meta.status >= 400 && result_data.message;
121115

122-
// Handle API failures
123-
if ( results.meta.status >= 400 && result_data.message ) {
124-
self.handleErrorRequest( result_data );
125-
}
126-
else {
127-
self.handleSuccessfulRequest( result_data );
116+
if ( isFailling ) {
117+
that.handleErrorRequest( result_data );
118+
return;
128119
}
120+
121+
that.handleSuccessfulRequest( result_data );
129122
}
130123
});
131124
};
132125

133126
// Handle Errors requests
134127
Github.prototype.handleErrorRequest = function ( result_data ) {
135-
var self = this;
136-
137128
console.warn( result_data.message );
138129
return;
139130
};
140131

141132
// Handle Successful request
142133
Github.prototype.handleSuccessfulRequest = function ( result_data ) {
143-
var self = this;
144-
145-
self.applyTemplate( result_data );
146-
self.setCache( result_data );
134+
this.applyTemplate( result_data );
135+
this.setCache( result_data );
147136
};
148137

149138
// Stores repostories in sessionStorage if available
150139
Github.prototype.setCache = function ( result_data ) {
151-
var self = this;
152-
153140
// Cache data
154141
if ( window.sessionStorage ) {
155-
window.sessionStorage.setItem( "gh-repos:" + self.repo, JSON.stringify( result_data ) );
142+
window.sessionStorage.setItem( "gh-repos:" + this.repo, JSON.stringify( result_data ) );
156143
}
157144
};
158145

159146
// Grab cached results
160147
Github.prototype.getCache = function() {
161-
var self = this;
162-
163148
if ( window.sessionStorage ) {
164-
return window.sessionStorage.getItem( "gh-repos:" + self.repo );
149+
return window.sessionStorage.getItem( "gh-repos:" + this.repo );
165150
}
166151
else {
167152
return false;
@@ -170,11 +155,10 @@ Github.prototype.getCache = function() {
170155

171156
// Apply results to HTML template
172157
Github.prototype.applyTemplate = function ( repo ) {
173-
var self = this,
174-
githubRepo = new GithubRepo( repo ),
175-
$widget = githubRepo.toHTML();
158+
var githubRepo = new GithubRepo( repo ),
159+
$widget = githubRepo.toHTML();
176160

177-
$widget.appendTo( self.$container );
161+
$widget.appendTo( this.$container );
178162
};
179163

180164
// -- Attach plugin to jQuery's prototype --------------------------------------

dist/jquery.github.min.js

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

0 commit comments

Comments
 (0)