Skip to content

Commit c8b6779

Browse files
committed
removing old header
1 parent 16f0f61 commit c8b6779

File tree

4 files changed

+146
-10
lines changed

4 files changed

+146
-10
lines changed

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h1>jQuery Github</h1>
3535
<img id="github-logo" src="img/github-cat.png" alt="Github Cat" />
3636

3737
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
38-
<script src="../jquery.github.min.js"></script>
38+
<script src="../dist/jquery.github.min.js"></script>
3939

4040
<script>
4141
$('[data-repo]').github();

dist/jquery.github.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* jQuery Github - v0.2.4
3+
* A jQuery plugin to display your Github Repositories.
4+
* https://github.com/zenorocha/jquery-github/
5+
6+
* Copyright (c) 2013
7+
* MIT License
8+
*/
9+
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.
12+
;(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
24+
var pluginName = 'github',
25+
document = window.document,
26+
defaults = {
27+
propertyName: "value"
28+
};
29+
30+
// The actual plugin constructor
31+
function Plugin( element, options ) {
32+
this.element = element;
33+
this.$container = $(element);
34+
this.repo = this.$container.attr("data-repo");
35+
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) ;
41+
42+
this._defaults = defaults;
43+
this._name = pluginName;
44+
45+
this.init();
46+
}
47+
48+
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+
}
57+
58+
if (cached !== null) {
59+
self.applyTemplate(JSON.parse(cached));
60+
}
61+
else {
62+
63+
$.ajax({
64+
url: 'https://api.github.com/repos/' + this.repo,
65+
dataType: 'jsonp',
66+
success: function(results){
67+
68+
// Handle API failures
69+
if (results.meta.status >= 400 && results.data.message){
70+
console.warn(results.data.message);
71+
return;
72+
}
73+
else {
74+
75+
self.applyTemplate(results.data);
76+
77+
// Cache data
78+
if (window.sessionStorage) {
79+
sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data));
80+
}
81+
82+
}
83+
}
84+
});
85+
86+
}
87+
88+
};
89+
90+
Plugin.prototype.applyTemplate = function (repo) {
91+
92+
var self = this;
93+
var date = new Date(repo.pushed_at);
94+
var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();
95+
96+
var $widget = $($.parseHTML(' \
97+
<div class="github-box"> \
98+
<div class="github-box-header"> \
99+
<h3> \
100+
<a href="' + repo.url.replace('api.','').replace('repos/','') + '">' + repo.name + '</a> \
101+
</h3> \
102+
<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> \
105+
</div> \
106+
</div> \
107+
<div class="github-box-content"> \
108+
<p>' + repo.description + ' &mdash; <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \
109+
</div> \
110+
<div class="github-box-download"> \
111+
<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> \
113+
</div> \
114+
</div> \
115+
'));
116+
117+
self.appendTemplate($widget);
118+
119+
};
120+
121+
Plugin.prototype.appendTemplate = function ($widget) {
122+
var self = this;
123+
$widget.appendTo(self.$container);
124+
};
125+
126+
// A really lightweight plugin wrapper around the constructor,
127+
// preventing against multiple instantiations
128+
$.fn[pluginName] = function ( options ) {
129+
return this.each(function () {
130+
if (!$.data(this, 'plugin_' + pluginName)) {
131+
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
132+
}
133+
});
134+
};
135+
136+
}(jQuery, window));

dist/jquery.github.min.js

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

src/jquery.github.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* jQuery Github v0.2.2
3-
* A jQuery plugin to display your Github Repositories.
4-
* http://git.io/WUV4_Q
5-
*
6-
* Zeno Rocha
7-
* MIT License
8-
*/
9-
101
// the semi-colon before function invocation is a safety net against concatenated
112
// scripts and/or other plugins which may not be closed properly.
123
;(function ( $, window, undefined ) {

0 commit comments

Comments
 (0)