Skip to content

armgit / brag

Public Imported from GitHub
0

You built it. Now brag. Turn the project you just created into a short, shareable launch video with one command.

Improve mobile hero + install block

shunithaviv9b5a758fb1c0
diff --git a/docs/main.js b/docs/main.js
index 9f5fd08..e768a35 100644
--- a/docs/main.js
+++ b/docs/main.js
@@ -19,11 +19,39 @@
// Gallery videos use the native <video controls> player. No custom JS.
// Copy buttons
+ // navigator.clipboard only exists in secure contexts (https / localhost), so on a
+ // phone hitting the dev server over http:// we fall back to execCommand('copy').
+ const legacyCopy = (text) => {
+ const ta = document.createElement('textarea');
+ ta.value = text;
+ ta.setAttribute('readonly', '');
+ ta.style.position = 'fixed';
+ ta.style.top = '0';
+ ta.style.left = '0';
+ ta.style.opacity = '0';
+ document.body.appendChild(ta);
+ ta.focus();
+ ta.select();
+ ta.setSelectionRange(0, text.length); // iOS Safari needs an explicit range
+ let ok = false;
+ try { ok = document.execCommand('copy'); } catch { ok = false; }
+ document.body.removeChild(ta);
+ return ok;
+ };
+
document.querySelectorAll('.copy[data-copy]').forEach((btn) => {
btn.addEventListener('click', async () => {
const text = btn.dataset.copy || '';
- try {
- await navigator.clipboard.writeText(text);
+ let ok = false;
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ try {
+ await navigator.clipboard.writeText(text);
+ ok = true;
+ } catch { /* fall through to legacy path */ }
+ }
+ if (!ok) ok = legacyCopy(text);
+
+ if (ok) {
btn.dataset.state = 'copied';
const orig = btn.textContent;
btn.textContent = 'copied';
@@ -31,8 +59,8 @@
btn.dataset.state = '';
btn.textContent = orig;
}, 1600);
- } catch {
- // fallback: select inside the <pre>
+ } else {
+ // last resort: select the command so the user can copy it manually
const pre = btn.closest('.install');
if (pre) {
const range = document.createRange();
diff --git a/docs/styles.css b/docs/styles.css
index 9462c51..e81e8ce 100644
--- a/docs/styles.css
+++ b/docs/styles.css
@@ -159,6 +159,12 @@ button { font: inherit; cursor: pointer; }
margin: 0;
position: relative;
max-width: 100%;
+ grid-template-columns: minmax(0, 1fr);
+}
+/* The <code> scrolls, not the <pre> — so the copy button stays glued to the frame. */
+.install code {
+ display: block;
+ min-width: 0;
overflow-x: auto;
}
.install .prompt { color: oklch(72% 0.18 var(--hue)); }
@@ -356,8 +362,8 @@ button { font: inherit; cursor: pointer; }
@media (max-width: 900px) {
.hero-video {
width: clamp(180px, 48vw, 240px);
- justify-self: start;
- transform: rotate(-2deg);
+ justify-self: center;
+ transform: none;
}
}