|
11 | 11 | var pluginName = "github",
|
12 | 12 | document = window.document,
|
13 | 13 | defaults = {
|
14 |
| - propertyName: "value" |
| 14 | + propertyName: "value", |
| 15 | + username: null, |
| 16 | + elClass: "github-box-wrap" |
15 | 17 | };
|
16 | 18 |
|
17 | 19 | function Plugin( element, options ) {
|
|
45 | 47 | // Apply results to HTML template
|
46 | 48 | Plugin.prototype.applyTemplate = function ( repo ) {
|
47 | 49 | var self = this,
|
48 |
| - $widget = self.parseTemplate( repo ); |
49 |
| - |
50 |
| - $widget.appendTo( self.$container ); |
| 50 | + $widget; |
| 51 | + |
| 52 | + if ( Array.isArray( repo ) === true ) { |
| 53 | + repo.forEach( function(r) { |
| 54 | + var $repo = $( $.parseHTML( "<div data-repo='" + self.options.username + "/" + r.name + "' class='" + self.options.elClass + "'></div>" ) ); |
| 55 | + $repo.appendTo( self.$container ); |
| 56 | + $widget = self.parseTemplate( r ); |
| 57 | + $widget.appendTo( $repo ); |
| 58 | + }); |
| 59 | + } else { |
| 60 | + $widget = self.parseTemplate( repo ); |
| 61 | + $widget.appendTo( self.$container ); |
| 62 | + } |
51 | 63 | };
|
52 | 64 |
|
53 | 65 | // Stores repostories in sessionStorage if available
|
|
133 | 145 |
|
134 | 146 | // Request repositories from Github
|
135 | 147 | Plugin.prototype.requestData = function ( repo ) {
|
136 |
| - var self = this; |
| 148 | + var self = this, |
| 149 | + url = "https://api.github.com/repos/" + repo; |
| 150 | + |
| 151 | + if ( self.options.username !== null ) { |
| 152 | + url = "https://api.github.com/users/" + self.options.username + "/repos"; |
| 153 | + } |
137 | 154 |
|
138 | 155 | $.ajax({
|
139 |
| - url: "https://api.github.com/repos/" + repo, |
| 156 | + url: url, |
140 | 157 | dataType: "jsonp",
|
141 | 158 | success: function( results ) {
|
142 | 159 | var result_data = results.data;
|
|
0 commit comments