|
3 | 3 | var pluginName = "github",
|
4 | 4 | document = window.document,
|
5 | 5 | defaults = {
|
6 |
| - propertyName: "value" |
| 6 | + propertyName: "value", |
| 7 | + username: null, |
| 8 | + elClass: "github-box-wrap" |
7 | 9 | };
|
8 | 10 |
|
9 | 11 | function Plugin( element, options ) {
|
|
37 | 39 | // Apply results to HTML template
|
38 | 40 | Plugin.prototype.applyTemplate = function ( repo ) {
|
39 | 41 | 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 | + } |
43 | 55 | };
|
44 | 56 |
|
45 | 57 | // Stores repostories in sessionStorage if available
|
|
125 | 137 |
|
126 | 138 | // Request repositories from Github
|
127 | 139 | 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 | + } |
129 | 146 |
|
130 | 147 | $.ajax({
|
131 |
| - url: "https://api.github.com/repos/" + repo, |
| 148 | + url: url, |
132 | 149 | dataType: "jsonp",
|
133 | 150 | success: function( results ) {
|
134 | 151 | var result_data = results.data;
|
|
0 commit comments