Skip to content

Commit e0b6edd

Browse files
authored
add single line and animation options to banner (#205)
* feat(banner.js): add "minimal" size for banner all text on a single line without pulsing animation * feat(banner.js): split minimal to animation & size * docs(banner.md): update table with new params add animation: on/off & size: minimal * docs(banner.md): add minimal & animation example
1 parent e483712 commit e0b6edd

2 files changed

Lines changed: 51 additions & 8 deletions

File tree

public/banner.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
* lang=fr Override the browser language (default: auto-detected)
1414
* id=myDiv Insert the banner inside the element with this id
1515
* (default: prepend to <body>)
16-
* size=normal Banner size: "normal" (default) or "mini"
16+
* size=normal Banner size: "normal" (default), "mini" or "minimal"
1717
* link=URL Make the banner text a link (default: https://keepandroidopen.org)
1818
* Set link=none to disable the link
1919
* hidebutton=on Show an X close button (default: on)
2020
* Set hidebutton=off to hide the close button
21+
* animation=on Add animation to border of banner (default: on)
22+
* Set animation=off to disable
2123
*/
2224
(function () {
2325
"use strict";
@@ -101,7 +103,10 @@
101103
);
102104

103105
// ── Size variant ──────────────────────────────────────────────────────
104-
var size = params.size === "mini" ? "mini" : "normal";
106+
var size = params.size === "mini" ? "mini"
107+
: params.size === "minimal"
108+
? "minimal"
109+
: "normal";
105110

106111
// ── Link ────────────────────────────────────────────────────────────
107112
var linkParam = params.link;
@@ -133,7 +138,6 @@
133138
"0px 3px 0px #751111," +
134139
"0px 4px 0px #5e0d0d," +
135140
"0px 6px 10px rgba(0,0,0,0.5);" +
136-
"animation:kao-pulse 2s infinite;" +
137141
"padding:0.5rem 2.5rem;" +
138142
"line-height:1.6;" +
139143
"box-sizing:border-box;" +
@@ -156,12 +160,33 @@
156160
"0px 1px 0px #9e1a1a," +
157161
"0px 2px 0px #8a1515," +
158162
"0px 3px 5px rgba(0,0,0,0.4);" +
159-
"animation:kao-pulse 2s infinite;" +
160163
"padding:0.25rem 1.5rem;" +
161164
"line-height:1.4;" +
162165
"box-sizing:border-box;" +
163166
"}";
164167

168+
var cssMinimal =
169+
".kao-banner{" +
170+
"position:relative;" +
171+
"font-variant-numeric:tabular-nums;" +
172+
"background:linear-gradient(180deg,#d32f2f 0%,#b71c1c 100%);" +
173+
"border-bottom:2px solid #801313;" +
174+
"color:#fff;" +
175+
"font-family:'Arial Black',sans-serif;" +
176+
"font-weight:900;" +
177+
"text-transform:uppercase;" +
178+
"letter-spacing:1px;" +
179+
"font-size:0.75rem;" +
180+
"text-align:center;" +
181+
"text-shadow:" +
182+
"0px 1px 0px #9e1a1a," +
183+
"0px 2px 0px #8a1515," +
184+
"0px 3px 5px rgba(0,0,0,0.4);" +
185+
"padding:0.25rem 1.5rem;" +
186+
"line-height:1.4;" +
187+
"box-sizing:border-box;" +
188+
"}";
189+
165190
var cssCommon =
166191
".kao-banner a{color:#fff;text-decoration:none;}" +
167192
".kao-banner a:hover{text-decoration:underline;}" +
@@ -180,15 +205,20 @@
180205
"line-height:1;" +
181206
"text-shadow:none;" +
182207
"}" +
183-
".kao-banner-close:hover{opacity:1;}" +
208+
".kao-banner-close:hover{opacity:1;}";
209+
210+
var cssKaoPulse =
211+
".kao-banner { animation:kao-pulse 2s infinite; }" +
184212
"@keyframes kao-pulse{" +
185213
"0%{box-shadow:0 0 0 0 rgba(211,47,47,0.7)}" +
186214
"70%{box-shadow:0 0 0 15px rgba(211,47,47,0)}" +
187215
"100%{box-shadow:0 0 0 0 rgba(211,47,47,0)}" +
188216
"}";
189217

190218
var style = document.createElement("style");
191-
style.textContent = (size === "mini" ? cssMini : cssNormal) + cssCommon;
219+
style.textContent = (size === "mini" ? cssMini : size === "minimal" ? cssMinimal : cssNormal)
220+
+ (params.animation === "off" ? "" : cssKaoPulse)
221+
+ cssCommon;
192222
document.head.appendChild(style);
193223

194224
// ── Check if previously dismissed (reappears after dismissDays) ─────
@@ -220,7 +250,11 @@
220250
banner.appendChild(document.createTextNode(messageText));
221251
}
222252

223-
banner.appendChild(document.createElement("br"));
253+
if (params.size === "minimal") {
254+
banner.appendChild(document.createTextNode("\u00A0"));
255+
} else {
256+
banner.appendChild(document.createElement("br"));
257+
}
224258

225259
var countdownSpan = document.createElement("span");
226260
countdownSpan.textContent = "\u00A0";

src/content/pages/banner.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Customize the banner by appending query parameters to the script URL:
2323
|-----------|--------|---------|-------------|
2424
| `lang` | `en`, `fr`, `de`, `es`, … | Browser language | Override the display language |
2525
| `id` | Any element id | _(prepend to body)_ | Insert the banner inside the element with this id |
26-
| `size` | `normal`, `mini` | `normal` | Banner size variant |
26+
| `size` | `normal`, `mini`, `minimal` | `normal` | Banner size variant |
2727
| `link` | Any URL, or `none` | `https://keepandroidopen.org` | Make the banner text a clickable link; set to `none` to disable |
2828
| `hidebutton` | `on`, `off` | `on` | Show or hide the X close button (dismissed state is remembered per-site via localStorage) |
29+
| `animation` | `on`, `off` | `on` | Enable or disable the banner's pulsing animation |
2930

3031
## Examples
3132

@@ -49,6 +50,14 @@ Link to a custom page, no close button:
4950
<div id="my-banner-custom"></div>
5051
<script src="/banner.js?link=https://example.com/android&hidebutton=off&size=mini&id=my-banner-custom"></script>
5152

53+
Minimal size without animations.
54+
55+
```html
56+
<script src="/banner.js?size=minimal&animation=off&id=my-banner-minimal"></script>
57+
```
58+
<div id="my-banner-minimal"></div>
59+
<script src="/banner.js?size=minimal&animation=off&id=my-banner-minimal"></script>
60+
5261
## Source
5362

5463
The source for the banner can be found at [https://github.com/keepandroidopen/keepandroidopen.github.io/blob/main/public/banner.js](https://github.com/keepandroidopen/keepandroidopen.github.io/blob/main/public/banner.js). Suggestions for improvement are welcome!

0 commit comments

Comments
 (0)