Skip to content

Commit ab097e8

Browse files
committed
Regenerate
1 parent 4252290 commit ab097e8

File tree

2 files changed

+129
-73
lines changed

2 files changed

+129
-73
lines changed

dist/jquery.github.js

Lines changed: 127 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,192 @@
11
/*
2-
* jQuery Github - v0.2.5
2+
* jQuery Github - v0.2.6
33
* A jQuery plugin to display your Github Repositories.
44
* https://github.com/zenorocha/jquery-github/
55
66
* Copyright (c) 2013
77
* MIT License
88
*/
99

10-
// the semi-colon before function invocation is a safety net against concatenated
11-
// scripts and/or other plugins which may not be closed properly.
1210
;(function ( $, window, undefined ) {
13-
14-
// undefined is used here as the undefined global variable in ECMAScript 3 is
15-
// mutable (ie. it can be changed by someone else). undefined isn't really being
16-
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
17-
// can no longer be modified.
18-
19-
// window is passed through as local variable rather than global
20-
// as this (slightly) quickens the resolution process and can be more efficiently
21-
// minified (especially when both are regularly referenced in your plugin).
22-
23-
// Create the defaults once
2411
var pluginName = 'github',
25-
document = window.document,
26-
defaults = {
12+
document = window.document,
13+
defaults = {
2714
propertyName: "value"
2815
};
2916

30-
// The actual plugin constructor
3117
function Plugin( element, options ) {
32-
this.element = element;
33-
this.$container = $(element);
34-
this.repo = this.$container.attr("data-repo");
18+
var self = this;
19+
20+
self.element = element;
21+
self.$container = $(element);
22+
self.repo = self.$container.attr("data-repo");
3523

36-
// jQuery has an extend method which merges the contents of two or
37-
// more objects, storing the result in the first object. The first object
38-
// is generally empty as we don't want to alter the default options for
39-
// future instances of the plugin
40-
this.options = $.extend( {}, defaults, options) ;
24+
self.options = $.extend( {}, defaults, options) ;
4125

42-
this._defaults = defaults;
43-
this._name = pluginName;
26+
self._defaults = defaults;
27+
self._name = pluginName;
4428

45-
this.init();
29+
self.init();
4630
}
4731

32+
/**
33+
* Initializer
34+
*
35+
*/
4836
Plugin.prototype.init = function () {
49-
50-
var self = this;
51-
var cached;
52-
53-
// Attempt to get cached repo data
54-
if (window.sessionStorage) {
55-
cached = sessionStorage.getItem('gh-repos:' + this.repo);
56-
}
37+
var self = this,
38+
cached = self.getCache();
5739

5840
if (cached !== null) {
5941
self.applyTemplate(JSON.parse(cached));
6042
}
6143
else {
44+
self.requestData(repo);
45+
}
46+
};
6247

63-
$.ajax({
64-
url: 'https://api.github.com/repos/' + this.repo,
65-
dataType: 'jsonp',
66-
success: function(results){
48+
/**
49+
* Apply results to HTML template
50+
*
51+
*/
52+
Plugin.prototype.applyTemplate = function (repo) {
53+
var self = this,
54+
$widget = self.parseTemplate(repo);
6755

68-
// Handle API failures
69-
if (results.meta.status >= 400 && results.data.message){
70-
console.warn(results.data.message);
71-
return;
72-
}
73-
else {
56+
$widget.appendTo(self.$container);
57+
};
7458

75-
self.applyTemplate(results.data);
59+
/**
60+
* Stores repostories in sessionStorage if available
61+
*
62+
*/
63+
Plugin.prototype.cacheResults = function (result_data) {
64+
var self = this;
7665

77-
// Cache data
78-
if (window.sessionStorage) {
79-
sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data));
80-
}
66+
// Cache data
67+
if (window.sessionStorage) {
68+
sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(result_data));
69+
}
70+
};
8171

82-
}
83-
}
84-
});
72+
/**
73+
* Grab cached results
74+
*
75+
*/
76+
Plugin.prototype.getCache = function () {
77+
var self = this;
8578

79+
if (window.sessionStorage) {
80+
return sessionStorage.getItem('gh-repos:' + self.repo);
81+
}
82+
else {
83+
return false;
8684
}
85+
};
86+
87+
/**
88+
* Handle Errors requests
89+
*
90+
*/
91+
Plugin.prototype.handlerErrorRequests = function (result_data) {
92+
var self = this;
8793

94+
console.warn(result_data.message);
95+
return;
8896
};
8997

90-
Plugin.prototype.applyTemplate = function (repo) {
98+
/**
99+
* Handle Successful request
100+
*
101+
*/
102+
Plugin.prototype.handlerSuccessfulRequest = function (result_data) {
103+
var self = this;
104+
105+
self.applyTemplate(result_data);
106+
self.cacheResults(result_data);
107+
};
108+
109+
/**
110+
* Parses Pushed date with date format
111+
*
112+
*/
113+
Plugin.prototype.parsePushedDate = function (pushed_at) {
114+
var self = this,
115+
date = new Date(pushed_at);
116+
117+
return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear()
118+
};
91119

120+
/**
121+
* Parses repository URL to be friendly
122+
*
123+
*/
124+
Plugin.prototype.parseRepositoryURL = function (url) {
92125
var self = this;
93-
var date = new Date(repo.pushed_at);
94-
var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();
95126

96-
var $widget = $($.parseHTML(' \
127+
return url.replace('api.','').replace('repos/','');
128+
};
129+
130+
/**
131+
* Parses HTML template
132+
*
133+
*/
134+
Plugin.prototype.parseTemplate = function (repo) {
135+
var self = this,
136+
pushed_at = self.parsePushedDate(repo.pushed_at),
137+
repo_url = self.parseRepositoryURL(repo.url);
138+
139+
return $($.parseHTML(' \
97140
<div class="github-box"> \
98141
<div class="github-box-header"> \
99142
<h3> \
100-
<a href="' + repo.url.replace('api.','').replace('repos/','') + '">' + repo.name + '</a> \
143+
<a href="' + repo_url + '">' + repo.name + '</a> \
101144
</h3> \
102145
<div class="github-stats"> \
103-
<a class="repo-watchers" href="' + repo.url.replace('api.','').replace('repos/','') + '/watchers">' + repo.watchers + '</a> \
104-
<a class="repo-forks" href="' + repo.url.replace('api.','').replace('repos/','') + '/forks">' + repo.forks + '</a> \
146+
<a class="repo-watchers" href="' + repo_url + '/watchers">' + repo.watchers + '</a> \
147+
<a class="repo-forks" href="' + repo_url + '/forks">' + repo.forks + '</a> \
105148
</div> \
106149
</div> \
107150
<div class="github-box-content"> \
108-
<p>' + repo.description + ' &mdash; <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \
151+
<p>' + repo.description + ' &mdash; <a href="' + repo_url + '#readme">Read More</a></p> \
109152
</div> \
110153
<div class="github-box-download"> \
111154
<p class="repo-update">Latest commit to <strong>master</strong> on ' + pushed_at + '</p> \
112-
<a class="repo-download" href="' + repo.url.replace('api.','').replace('repos/','') + '/zipball/master">Download as zip</a> \
155+
<a class="repo-download" href="' + repo_url + '/zipball/master">Download as zip</a> \
113156
</div> \
114157
</div> \
115158
'));
116-
117-
self.appendTemplate($widget);
118-
119159
};
120160

121-
Plugin.prototype.appendTemplate = function ($widget) {
161+
/**
162+
* Request repositories from Github
163+
*
164+
*/
165+
Plugin.prototype.requestData = function (repo) {
122166
var self = this;
123-
$widget.appendTo(self.$container);
167+
168+
$.ajax({
169+
url: 'https://api.github.com/repos/' + repo,
170+
dataType: 'jsonp',
171+
success: function(results) {
172+
var result_data = results.data;
173+
174+
// Handle API failures
175+
if (results.meta.status >= 400 && result_data.message) {
176+
self.handlerErrorRequest();
177+
}
178+
else {
179+
self.handlerSuccessfulRequest(result_data);
180+
}
181+
}
182+
});
124183
};
125184

126-
// A really lightweight plugin wrapper around the constructor,
127-
// preventing against multiple instantiations
128185
$.fn[pluginName] = function ( options ) {
129186
return this.each(function () {
130187
if (!$.data(this, 'plugin_' + pluginName)) {
131188
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
132189
}
133190
});
134191
};
135-
136192
}(jQuery, window));

dist/jquery.github.min.js

Lines changed: 2 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)