Skip to content

Commit ef6585f

Browse files
author
tim
committed
added functionality to automatically fetch all repos for a git user
1 parent 35b0177 commit ef6585f

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

demo/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>jQuery Github</title>
77

88
<!-- Plugin CSS -->
9-
<link rel="stylesheet" href="../assets/base.css">
9+
<link rel="stylesheet" href="/assets/base.css">
1010

1111
<!-- Demo CSS -->
1212
<link rel="stylesheet" href="css/style.css">
@@ -30,15 +30,19 @@ <h1>jQuery Github</h1>
3030
<div data-repo="zenorocha/hub.me" class="github-box-wrap"></div>
3131
</div>
3232

33+
<div class="projects" id="tim-projects"></div>
34+
3335
<p class="credits">Made with love by <a href="http://zenorocha.com">Zeno Rocha</a>.</p>
3436

3537
<img id="github-logo" src="img/github-cat.png" alt="Github Cat" />
3638

3739
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
38-
<script src="../dist/jquery.github.min.js"></script>
40+
<!-- // <script src="../dist/jquery.github.min.js"></script> -->
41+
<script src="/src/jquery.github.js"></script>
3942

4043
<script>
4144
$('[data-repo]').github();
45+
$("#tim-projects").github( { username: "timdouglas" } );
4246
</script>
4347

4448
</body>

src/jquery.github.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
var pluginName = "github",
44
document = window.document,
55
defaults = {
6-
propertyName: "value"
6+
propertyName: "value",
7+
username: null,
8+
elClass: "github-box-wrap"
79
};
810

911
function Plugin( element, options ) {
@@ -37,9 +39,19 @@
3739
// Apply results to HTML template
3840
Plugin.prototype.applyTemplate = function ( repo ) {
3941
var self = this,
40-
$widget = self.parseTemplate( repo );
41-
42-
$widget.appendTo( self.$container );
42+
$widget;
43+
44+
if ( Array.isArray( repo ) === true ) {
45+
repo.forEach( function(r) {
46+
var $repo = $( $.parseHTML( "<div data-repo='" + self.options.username + "/" + r.name + "' class='" + self.options.elClass + "'></div>" ) );
47+
$repo.appendTo( self.$container );
48+
$widget = self.parseTemplate( r );
49+
$widget.appendTo( $repo );
50+
});
51+
} else {
52+
$widget = self.parseTemplate( repo );
53+
$widget.appendTo( self.$container );
54+
}
4355
};
4456

4557
// Stores repostories in sessionStorage if available
@@ -125,10 +137,15 @@
125137

126138
// Request repositories from Github
127139
Plugin.prototype.requestData = function ( repo ) {
128-
var self = this;
140+
var self = this,
141+
url = "https://api.github.com/repos/" + repo;
142+
143+
if ( self.options.username !== null ) {
144+
url = "https://api.github.com/users/" + self.options.username + "/repos";
145+
}
129146

130147
$.ajax({
131-
url: "https://api.github.com/repos/" + repo,
148+
url: url,
132149
dataType: "jsonp",
133150
success: function( results ) {
134151
var result_data = results.data;

0 commit comments

Comments
 (0)