Skip to content

Commit 64df00f

Browse files
committed
added support for single repo and specific row highlighting.
1 parent af7cb81 commit 64df00f

File tree

4 files changed

+65
-36
lines changed

4 files changed

+65
-36
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
In no particular order...
44

5-
* allow single repo.
65
* cache same repo reqs.
7-
* highlight specific row.
86
* show only certain columns.
97
* dark/light/color themes.

demo/index.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
width:70%;
1616
font-size:11px;
1717
}
18-
/* custom CSS override for Dark theme*/
19-
#gvg-ring-1 td, #gvg-ring-1 td a
18+
/* custom CSS override for Dark theme */
19+
#gvg-ring-2 td, #gvg-ring-2 td a
2020
{
2121
background-color:#3E3F41;
2222
color:#F7F7F7;
2323
}
24-
#gvg-ring-1 thead th, #gvg-ring-1 tfoot th, #gvg-ring-1 tfoot th a
24+
#gvg-ring-2 thead th, #gvg-ring-2 tfoot th, #gvg-ring-2 tfoot th a
2525
{
2626
background-color:#030000;
2727
color:#F7F7F7;
2828
}
29-
#gvg-ring-1 thead th
29+
#gvg-ring-2 thead th
3030
{
3131
background-image:-moz-linear-gradient(#030000,#2C2918);
3232
}
@@ -45,12 +45,21 @@ <h2>Quick Start:</h2>
4545
</ol>
4646

4747
<h2>Demo:</h2>
48+
Feel free to inspect the table source to see the generated output to tweak.
49+
4850
<h4>Default Style:</h4>
4951
<div class="gvg" data-repos="angular/angular.js,jashkenas/backbone,emberjs/ember.js,knockout/knockout"></div>
5052
<br /><textarea readonly>&lt;div class="gvg" data-repos="angular/angular.js,jashkenas/backbone,emberjs/ember.js,knockout/knockout">&lt;/div></textarea>
5153
<br /><br />
54+
55+
<h4>With row highlighting:</h4>
56+
Add attribute "data-highlight" with the repo full name. Seperate with commas to highlight more rows.
57+
<div class="gvg" data-repos="angular/angular.js,emberjs/ember.js,knockout/knockout" data-highlight="angular/angular.js,knockout/knockout"></div>
58+
<br /><textarea readonly>&lt;div class="gvg" data-repos="angular/angular.js,emberjs/ember.js,knockout/knockout" data-highlight="angular/angular.js,knockout/knockout">&lt;/div></textarea>
59+
<br /><br />
60+
5261
<h4>Customized "Dark" Style:</h4>
53-
Generated CSS is prepended to &lt;head> so overwriting the styles is possible.
62+
Generated CSS is prepended to &lt;head> so overwriting the styles is possible. Table ID has default format of "gvg-ring-<em>#</em>". "#" starts from 0 and increments for each generated table.
5463
<div class="gvg" data-repos="dojo/dojo,jquery/jquery,mootools/mootools-core,sstephenson/prototype,yui/yui3" style="width:800px; background-color:#3E3F41;"></div>
5564
<br /><textarea readonly>&lt;div class="gvg" data-repos="dojo/dojo,jquery/jquery,mootools/mootools-core,sstephenson/prototype,yui/yui3" style="background-color:#3E3F41;">&lt;/div></textarea>
5665

@@ -60,7 +69,7 @@ <h2>Requires:</h2>
6069
<li>Major browsers, but IE 9+</li>
6170
</ul>
6271

63-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
72+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
6473
<script type="text/javascript" src="../js/jquery.gvg.min.js"></script>
6574
</body>
6675
</html>

js/jquery.gvg.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// gitvsgit jquery widget v 0.1.1 (http://git.io/XIauew)
1+
// gitvsgit jquery widget v 0.1.2 (http://git.io/XIauew)
22
// by @fatbattk
33

4-
(function($){
4+
;(function($){
55
var $gvgs = $('div.gvg');
66
if($gvgs.length)
77
{
@@ -13,55 +13,77 @@
1313
+'div.gvg{background-color:#EEE;border-radius:3px;padding:3px;width:500px;}'
1414
+'table.'+ gvg_table_class +'{border:1px solid #CCC;font:13px Helvetica,arial,sans-serif;width:100%;}'
1515
+'.'+ gvg_table_class +' td{background-color:#FFF;font-size:12px;padding:6px;}'
16+
+'.'+ gvg_table_class +' .hilite td{background-color:#E6F1F6;}'
1617
+'.'+ gvg_table_class +' thead th,.'+ gvg_table_class +' tfoot th{background-color:#FAFAFA;color:#555;}'
17-
+'.'+ gvg_table_class +' thead th{background-image:-moz-linear-gradient(#FAFAFA,#EAEAEA);background-repeat:repeat-x;border-bottom:1px solid #D8D8D8;font-size:13px;padding:4px;}'
18+
+'.'+ gvg_table_class +' thead th{background-image:-moz-linear-gradient(top,#FAFAFA,#EAEAEA);background-image:-webkit-linear-gradient(top,#FAFAFA,#EAEAEA);background-image:-ms-linear-gradient(top,#FAFAFA,#EAEAEA);background-image:linear-gradient(top,#FAFAFA,#EAEAEA);background-repeat:repeat-x;border-bottom:1px solid #D8D8D8;font-size:13px;padding:4px;}'
1819
+'.'+ gvg_table_class +' tfoot th{font-size:10px;padding:2px 4px;text-align:right;}'
1920
+'</style>');
2021

2122
$gvgs.each(function(idx){
2223
var $gvg = $(this),
2324
$repos = $gvg.data('repos');
25+
2426
if($repos.length>7)
2527
{
2628
var repo = $repos.split(','),
27-
repo_count = repo.length;
28-
if(repo_count>1)
29+
repo_count = repo.length,
30+
repo_highlights = [],
31+
gvgaj =[];
32+
33+
if($gvg.data('highlight'))
2934
{
30-
var gvgaj =[];
35+
repo_highlights = $gvg.data('highlight').split(',');
36+
}
3137

32-
for(i=0; i<repo_count; i++)
38+
for(i=0; i<repo_count; i++)
39+
{
40+
if(repo[i].length>3)
3341
{
34-
if(repo[i].length>3)
35-
{
36-
gvgaj[i] = $.getJSON('https://api.github.com/repos/'+ repo[i] +'?callback=?');
37-
}
42+
gvgaj[i] = $.getJSON('https://api.github.com/repos/'+ repo[i] +'?callback=?');
3843
}
44+
}
3945

40-
$.when.apply(this,gvgaj).done(function(){
41-
var gvgtbl = '<table class="'+ gvg_table_class +'" id="'+ gvg_table_class +'-'+ idx +'" border="0" cellspacing="1" cellpadding="2">'
42-
+'<thead><tr><th>Repos</th><th>Created</th><th>Updated</th><th>Stars</th><th>Forks</th><th>Open Issues</th></tr></thead>'
43-
+'<tfoot><tr><th colspan="6">'+ footer +'</th></tr></tfoot><tbody>';
46+
$.when.apply(this,gvgaj).done(function(){
47+
var gvgtbl = '<table class="'+ gvg_table_class +'" id="'+ gvg_table_class +'-'+ idx +'" border="0" cellspacing="1" cellpadding="2"><thead><tr><th>Repos</th><th>Created</th><th>Updated</th><th>Stars</th><th>Forks</th><th>Open Issues</th></tr></thead>';
48+
if(footer.length)
49+
{
50+
gvgtbl += '<tfoot><tr><th colspan="6">'+ footer +'</th></tr></tfoot>';
51+
}
52+
gvgtbl += '<tbody>';
4453

45-
var gvga,gvgd;
46-
for(i=0; i<arguments.length; i++)
54+
var gvga,gvgd;
55+
for(i=0; i<repo_count; i++)
56+
{
57+
if(repo_count>1)
4758
{
4859
gvga = arguments[i][0];
49-
if(gvga && (gvga.meta.status===200 || gvga.meta.status===304))
60+
}
61+
else
62+
{
63+
gvga = arguments[0];
64+
}
65+
if(gvga)
66+
{
67+
gvgd = gvga.data;
68+
if(gvga.meta.status===200 || gvga.meta.status===304)
5069
{
51-
gvgd = gvga.data;
52-
53-
gvgtbl += '<tr><td title="'+ gvgd.description +'"><a href="'+ gvgd.html_url +'" target="_blank">'+ gvgd.full_name +'</a></td><td>'+ new Date(gvgd.created_at).toDateString().replace(/[a-z]+ (.*?)/i,'') +'</td><td>'+ new Date(gvgd.updated_at).toDateString().replace(/[a-z]+ (.*?)/i,'') +'</td><td align="right">'+ gvgd.watchers_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td><td align="right">'+ gvgd.forks_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td><td align="right">'+ gvgd.open_issues_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td></tr>';
70+
gvgtbl += '<tr';
71+
if(repo_highlights.length>0 && $.inArray(gvgd.full_name,repo_highlights)>-1)
72+
{
73+
gvgtbl += ' class="hilite"';
74+
}
75+
gvgtbl += '><td title="'+ gvgd.description +'"><a href="'+ gvgd.html_url +'" target="_blank">'+ gvgd.full_name +'</a></td><td>'+ new Date(gvgd.created_at).toDateString().replace(/[a-z]+ (.*?)/i,'') +'</td><td>'+ new Date(gvgd.updated_at).toDateString().replace(/[a-z]+ (.*?)/i,'') +'</td><td align="right">'+ gvgd.watchers_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td><td align="right">'+ gvgd.forks_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td><td align="right">'+ gvgd.open_issues_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',') +'</td></tr>';
5476
}
55-
else if(gvga && gvga.meta.status===403)
77+
else if(gvga.meta.status===403)
5678
{
57-
gvgtbl += '<tr><td colspan="6" align="center">'+ gvga.data.message +'</td></tr>';
79+
gvgtbl += '<tr><td colspan="6" align="center">'+ gvgd.message +'</td></tr>';
5880
break;
5981
}
6082
}
83+
}
6184

62-
$gvg.html(gvgtbl +'</tbody></table>');
63-
});
64-
}
85+
$gvg.html(gvgtbl +'</tbody></table>');
86+
});
6587
}
6688
});
6789
}

js/jquery.gvg.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)