forked from mdo/github-buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-btn.html
More file actions
188 lines (179 loc) · 5.26 KB
/
github-btn.html
File metadata and controls
188 lines (179 loc) · 5.26 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<html><body><style type="text/css">
body {
padding: 0;
margin: 0;
font: bold 11px/14px "Helvetica Neue", Helvetica, Arial, sans-serif;
text-rendering: optimizeLegibility;
overflow: hidden;
}
.github-btn {
height: 20px;
overflow: hidden;
}
.gh-btn,
.gh-count,
.gh-ico {
float: left;
}
.gh-btn,
.gh-count {
padding: 2px 5px 2px 4px;
color: #666;
text-decoration: none;
text-shadow: 0 1px 0 #fff;
white-space: nowrap;
cursor: pointer;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.gh-btn {
background-color: #e6e6e6;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), color-stop(25%, #ffffff), to(#e6e6e6));
background-image: -webkit-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
background-image: -moz-linear-gradient(top, #ffffff, #ffffff 25%, #e6e6e6);
background-image: -ms-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
background-image: -o-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
background-image: linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
background-repeat: no-repeat;
border: 1px solid #ccc;
border-bottom-color: #bbb;
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
-moz-box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
}
.gh-btn:hover,
.gh-btn:focus {
color: #333;
text-decoration: none;
background-position: 0 -10px;
}
.gh-btn:active {
-webkit-box-shadow: inset 0 2px 4px rgba(0,0,0,.15);
-moz-box-shadow: inset 0 2px 4px rgba(0,0,0,.15);
box-shadow: inset 0 2px 4px rgba(0,0,0,.15);
}
.gh-ico {
width: 14px;
height: 14px;
margin-right: 4px;
vertical-align: middle;
background: url(github-icons.png) no-repeat 0 0;
opacity: .65;
}
.gh-btn:hover .gh-ico,
.gh-btn:focus .gh-ico {
opacity: .75;
}
.gh-count {
display: none; /* hidden to start */
margin-left: 2px;
background-color: #fff;
border: 1px solid #ddd;
}
.gh-count:hover,
.gh-count:focus {
color: #333;
background-color: #f5f5f5;
border-color: #d5d5d5;
}
.github-btn-large {
height: 30px;
}
.github-btn-large .gh-btn,
.github-btn-large .gh-count {
padding: 3px 10px 3px 8px;
font-size: 16px;
line-height: 22px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.github-btn-large .gh-ico {
width: 22px;
height: 22px;
background-position: 0 -20px;
}
.github-btn-large .gh-count {
margin-left: 4px;
}
</style>
<span id="github-btn" class="github-btn">
<a id="gh-btn" href="#" target="_blank" class="gh-btn">
<span class="gh-ico"></span>
<span id="gh-text" class="gh-text"></span>
</a>
<a id="gh-count" href="#" target="_blank" class="gh-count"></a>
</span>
<script type="text/javascript">
// Read a page's GET URL variables and return them as an associative array.
// Source: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
var params = function () {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}()
var user = params.user,
repo = params.repo,
type = params.type,
count = params.count,
size = params.size,
head = document.getElementsByTagName('head')[0],
button = document.getElementById('gh-btn'),
mainButton = document.getElementById('github-btn'),
text = document.getElementById('gh-text'),
counter = document.getElementById('gh-count');
// Add commas to numbers
function addCommas(n) {
return n.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,')
}
function jsonp(path) {
var el = document.createElement('script');
el.src = path + '?callback=callback';
head.insertBefore(el, head.firstChild);
}
function callback(obj) {
if (type == 'watch') {
counter.innerHTML = addCommas(obj.data.watchers);
} else if (type == 'fork') {
counter.innerHTML = addCommas(obj.data.forks);
} else if (type == 'follow') {
counter.innerHTML = addCommas(obj.data.followers);
}
// Show the count if asked
if (count == 'true') {
counter.style.display = 'block'
}
}
// Set href to be URL for repo
button.href = 'https://github.com/' + user + '/' + repo + '/';
// Add the class, change the text label, set count link href
if (type == 'watch') {
mainButton.className += ' github-watchers';
text.innerHTML = 'Watch';
counter.href = 'https://github.com/' + user + '/' + repo + '/watchers';
} else if (type == 'fork') {
mainButton.className += ' github-forks';
text.innerHTML = 'Fork';
counter.href = 'https://github.com/' + user + '/' + repo + '/network';
} else if (type == 'follow') {
mainButton.className += ' github-me';
text.innerHTML = 'Follow @' + user;
button.href = 'https://github.com/' + user;
counter.href = 'https://github.com/' + user + '/followers';
}
// Change the size
if (size == 'large') {
mainButton.className += ' github-btn-large';
}
if (type == 'follow') {
jsonp('https://api.github.com/users/' + user);
} else {
jsonp('https://api.github.com/repos/' + user + '/' + repo);
}
</script></body></html>