Skip to content

Commit 484863f

Browse files
authored
Add an image only variation with text=false (#154)
1 parent c30c954 commit 484863f

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ As such, for today's unofficial Watch button, **you must add `v=2` to the parame
5959
{% endcapture %}
6060
{% include example.html content=example %}
6161

62+
## No text variant
63+
64+
{% capture example %}
65+
<iframe src="{{ site.url }}/github-btn.html?user=twbs&repo=bootstrap&type=star&size=large&text=false" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
66+
{% endcapture %}
67+
{% include example.html content=example %}
68+
6269
---
6370

6471
## Available options
@@ -85,6 +92,7 @@ The following URL parameters are **not** required. Add them as you wish.
8592
| ------ | ----------- |
8693
| `count` | Show the optional watchers or forks count: *none* by default or `true` |
8794
| `size` | Optional flag for using a larger button: *none* by default or `large` |
95+
| `text` | Optional flag for hiding the text: *none* by default or `false` |
8896

8997
---
9098

src/js.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
var count = parameters.count;
4141
var size = parameters.size;
4242
var v = parameters.v;
43+
var noText = parameters.text;
4344

4445
// Elements
4546
var button = document.querySelector('.gh-btn');
@@ -155,6 +156,13 @@
155156
}
156157
}
157158

159+
if (noText === 'false') {
160+
button.className += ' no-text';
161+
text.setAttribute('aria-hidden', true);
162+
text.style.display = 'none';
163+
text.textContent = '';
164+
}
165+
158166
button.setAttribute('aria-label', title + LABEL_SUFFIX);
159167
document.title = title + LABEL_SUFFIX;
160168

@@ -165,7 +173,7 @@
165173

166174
// If count is not requested or type is sponsor,
167175
// there's no need to make an API call
168-
if (count !== 'true' || type === 'sponsor') {
176+
if (count !== 'true' || type === 'sponsor' || noText === 'false') {
169177
return;
170178
}
171179

src/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,6 @@ body {
117117
margin-top: -7px;
118118
border-width: 7px 7px 7px 0;
119119
}
120+
.no-text .gh-ico {
121+
margin-right: 0;
122+
}

0 commit comments

Comments
 (0)