This repository has been archived by the owner on Oct 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mootools-github-badge.js
124 lines (103 loc) · 3.22 KB
/
mootools-github-badge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
SubtleTemplate.GitHubBadge = new Class({
Implements: [Options, Events],
options:{
username: 'subtleGradient',
templateElement: 'github-badge-template',
element: 'github-badge',
filterData: function(data){ return data.user.repositories; }
},
initialize: function(options){
this.setOptions(options);
var self = this;
self.uid = SubtleTemplate.GitHubBadge.badges.length;
SubtleTemplate.GitHubBadge.badges[self.uid] = self;
window.addEvent('domready', self.requestData.bind(this));
},
requestData: function(){
new Element('script', {src: 'http://github.com/api/v1/json/'+ this.options.username +'?callback='+ this.toString() +'.setData' })
.inject(this.toElement(), 'after');
},
toString: function(){
return 'SubtleTemplate.GitHubBadge.badges['+ this.uid +']';
},
toElement: function(){
this.element || (this.element = $(this.options.element));
this.Template = this.Template || new SubtleTemplate($(this.options.templateElement));
return this.element;
},
setData: function(data){
this.toElement().empty().adopt(new this.Template(this.options.filterData(data)));
return this.fireEvent('change');
}
});
SubtleTemplate.GitHubBadge.Fade = new Class({
Extends: SubtleTemplate.GitHubBadge,
options:{
tween:{
speed:'slow'
}
},
setData: function(data){
var el = this.toElement().empty();
var rows = new this.Template(this.options.filterData(data));
rows = rows.reverse();
var self = this;
function addRow(){
if (!rows.length) return self.fireEvent('change');
$(rows.pop())
.fade('hide')
.inject(el, 'top')
.set('tween', $merge(self.options.tween, { onStart:addRowDelayed }))
.fade('in')
;
};
addRowDelayed = addRow.create({ delay:20 });
addRow();
return this;
}
});
SubtleTemplate.GitHubBadge.badges = [];
SubtleTemplate.GitHubBadge.Basic = new Class({
Extends: SubtleTemplate.GitHubBadge.Fade,
options:{
theme:'white',
// list_length:10 // TODO: implement list_length
},
toElement: function(){
if (!this.element){
if (this.options.theme == 'white') this.options.theme = '';
$(this.options.element).set('html','\
<div class="repos">\
<ul id="repo_listing">\
</ul>\
</div>\
<style type="text/css" media="screen">\
@import "http://drnicjavascript.rubyforge.org/github_badge/dist/ext/stylesheets/'+ this.options.theme +'badge.css";\
#github-badge li .description {display:none}\
#github-badge li {cursor:pointer}\
#github-badge li.show-description .description {display:block}\
#github-badge #repo_listing {display:block; height:300px; overflow:auto}\
</style>\
');
this.addEvent('change', function(){
$(this).getElements('li').addEvent('click', this.toggleDescription);
});
}
this.Template = this.Template || new SubtleTemplate({ html:'\
<li title="{description}" class="public">\
<img src="http://github.com/images/icons/public.png" />\
<strong>\
<a href="{url}">\
{name}\
</a>\
</strong>\
<p class="description">{description}</p>\
</li>\
'});
return this.element || (this.element = $('repo_listing'));
},
toggleDescription: function(e){
var c = 'show-description';
this.hasClass(c) ? this.removeClass(c) : this.addClass(c);
}
});