| ... | ... |
@@ -1,43 +1,39 @@ |
| 1 |
-github = (function(){
|
|
| 2 |
- function render(target, repos){
|
|
| 3 |
- var i = 0, fragment = '', t = $(target)[0]; |
|
| 1 |
+var github = (function(){
|
|
| 2 |
+ function render(target, repos){
|
|
| 3 |
+ var i = 0, fragment = '', t = $(target)[0]; |
|
| 4 | 4 |
|
| 5 |
- for(i = 0; i < repos.length; i++) |
|
| 6 |
- fragment += '<li><a href="'+repos[i].url+'">'+repos[i].name+'</a><p>'+repos[i].description+'</p></li>'; |
|
| 7 |
- |
|
| 8 |
- t.innerHTML = fragment; |
|
| 5 |
+ for(i = 0; i < repos.length; i++) {
|
|
| 6 |
+ fragment += '<li><a href="'+repos[i].url+'">'+repos[i].name+'</a><p>'+repos[i].description+'</p></li>'; |
|
| 9 | 7 |
} |
| 10 |
- return {
|
|
| 11 |
- showRepos: function(options){
|
|
| 12 |
- var feed = new jXHR(); |
|
| 13 |
- feed.onerror = function (msg,url) {
|
|
| 14 |
- $(options.target + ' li.loading').addClass('error').text("Error loading feed");
|
|
| 15 |
- } |
|
| 16 |
- feed.onreadystatechange = function(data){
|
|
| 17 |
- if (feed.readyState === 4) {
|
|
| 18 |
- var repos = []; |
|
| 19 |
- var i; |
|
| 20 |
- for (i = 0; i < data.repositories.length; i++){
|
|
| 21 |
- if (options.skip_forks && data.repositories[i].fork) |
|
| 22 |
- continue; |
|
| 23 |
- repos.push(data.repositories[i]); |
|
| 24 |
- } |
|
| 25 |
- repos.sort(function(a, b){
|
|
| 26 |
- var a = new Date(a.pushed_at), |
|
| 27 |
- b = new Date(b.pushed_at); |
|
| 28 |
- |
|
| 29 |
- if (a.valueOf() == b.valueOf()) return 0; |
|
| 30 |
- return a.valueOf() > b.valueOf() ? -1 : 1; |
|
| 31 |
- }); |
|
| 8 |
+ t.innerHTML = fragment; |
|
| 9 |
+ } |
|
| 10 |
+ return {
|
|
| 11 |
+ showRepos: function(options){
|
|
| 12 |
+ var feed = new jXHR(); |
|
| 13 |
+ feed.onerror = function (msg,url) {
|
|
| 14 |
+ $(options.target + ' li.loading').addClass('error').text("Error loading feed");
|
|
| 15 |
+ }; |
|
| 16 |
+ feed.onreadystatechange = function(data) {
|
|
| 17 |
+ if (feed.readyState === 4) {
|
|
| 18 |
+ var repos = []; |
|
| 19 |
+ for (var i = 0; i < data.repositories.length; i++){
|
|
| 20 |
+ if (options.skip_forks && data.repositories[i].fork) { continue; }
|
|
| 21 |
+ repos.push(data.repositories[i]); |
|
| 22 |
+ } |
|
| 23 |
+ repos.sort(function(a, b) {
|
|
| 24 |
+ var aDate = new Date(a.pushed_at).valueOf(), |
|
| 25 |
+ bDate = new Date(b.pushed_at).valueOf(); |
|
| 32 | 26 |
|
| 33 |
- if (options.count) |
|
| 34 |
- repos.splice(options.count); |
|
| 27 |
+ if (aDate === bDate) { return 0; }
|
|
| 28 |
+ return aDate > bDate ? -1 : 1; |
|
| 29 |
+ }); |
|
| 35 | 30 |
|
| 36 |
- render(options.target, repos) |
|
| 37 |
- } |
|
| 38 |
- }; |
|
| 39 |
- feed.open("GET","http://github.com/api/v2/json/repos/show/"+options.user+"?callback=?");
|
|
| 40 |
- feed.send(); |
|
| 31 |
+ if (options.count) { repos.splice(options.count); }
|
|
| 32 |
+ render(options.target, repos); |
|
| 41 | 33 |
} |
| 42 |
- }; |
|
| 34 |
+ }; |
|
| 35 |
+ feed.open("GET","http://github.com/api/v2/json/repos/show/"+options.user+"?callback=?");
|
|
| 36 |
+ feed.send(); |
|
| 37 |
+ } |
|
| 38 |
+ }; |
|
| 43 | 39 |
})(); |
| 44 | 40 |
\ No newline at end of file |