Browse code

allow limiting the amount of repos to display

by setting github_repo_count to someething that's not 0, you can limit
the amount of repositories to render

Philip Hofstetter authored on 04/08/2011 at 19:15:50
Showing 3 changed files
... ...
@@ -13,7 +13,12 @@
13 13
             var s = document.getElementsByTagName('script')[0];
14 14
             s.parentNode.insertBefore(jxhr, s);
15 15
         }
16
-        github.showRepos('{{site.github_user}}', '#gh_repos');
16
+
17
+        github.showRepos({
18
+            user: '{{site.github_user}}',
19
+            count: {{site.github_repo_count}},
20
+            target: '#gh_repos'
21
+        });
17 22
     });
18 23
   </script>
19 24
   <script src="{{ root_url }}/javascripts/github.js" type="text/javascript"> </script>
... ...
@@ -8,10 +8,10 @@ github = (function(){
8 8
         t.innerHTML =  fragment;
9 9
     }
10 10
     return {
11
-        showRepos: function(user, target){
11
+        showRepos: function(options){
12 12
             var feed = new jXHR();
13 13
             feed.onerror = function (msg,url) {
14
-              $(target + ' li.loading').addClass('error').text("Error loading feed");
14
+              $(options.target + ' li.loading').addClass('error').text("Error loading feed");
15 15
             }
16 16
             feed.onreadystatechange = function(data){
17 17
               if (feed.readyState === 4) {
... ...
@@ -27,11 +27,15 @@ github = (function(){
27 27
 
28 28
                     if (a.valueOf() == b.valueOf()) return 0;
29 29
                     return a.valueOf() > b.valueOf() ? -1 : 1;
30
-                })
31
-                render(target, repos)
30
+                });
31
+
32
+                if (options.count)
33
+                    repos.splice(options.count);
34
+
35
+                render(options.target, repos)
32 36
               }
33 37
             };
34
-            feed.open("GET","http://github.com/api/v2/json/repos/show/"+user+"?callback=?");
38
+            feed.open("GET","http://github.com/api/v2/json/repos/show/"+options.user+"?callback=?");
35 39
             feed.send();
36 40
         }
37 41
     };
... ...
@@ -57,6 +57,7 @@ twitter_tweet_button: true
57 57
 
58 58
 # github repositories
59 59
 github_user:
60
+github_repo_count: 0
60 61
 
61 62
 # Google Plus
62 63
 google_plus_one: true