Skip to content

Commit 0646d33

Browse files
committed
Add For me on GitHub ribbon - Fix
1 parent dab240b commit 0646d33

1 file changed

Lines changed: 20 additions & 85 deletions

File tree

_includes/head-custom.html

Lines changed: 20 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -180,34 +180,35 @@
180180
{% if page.fork_ribbon != false %}
181181
<!-- Fork ribbon styles + injector -->
182182
<style>
183-
/* Ribbon container positioned near top-left or top-right to avoid colliding with the site menu */
184183
.fork-ribbon {
185184
position: fixed;
186-
top: 12px;
185+
top: 0;
186+
left: 0;
187187
z-index: 10000;
188-
pointer-events: none; /* let underlying controls receive clicks except the link */
189-
overflow: visible;
188+
pointer-events: none;
190189
}
191190

192191
.fork-ribbon a {
193192
pointer-events: auto;
194193
display: block;
195-
width: 160px; /* width tuned for visibility */
196-
background: #151513; /* GitHub-like dark ribbon */
194+
background: #151513;
197195
color: #fff;
198196
text-decoration: none;
199197
font-weight: 700;
200-
font-size: 13px;
201-
line-height: 1.4;
202-
padding: 6px 0;
203-
text-align: center;
204-
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
205-
border-radius: 2px;
198+
font-size: 12px;
199+
line-height: 1;
200+
padding: 8px 48px;
201+
transform: translate(-34px, 18px) rotate(-45deg);
202+
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
206203
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
207-
transform-origin: 0 0;
204+
white-space: nowrap;
205+
}
206+
207+
.fork-ribbon a:hover,
208+
.fork-ribbon a:focus {
209+
background: #0b0b0b;
208210
}
209211

210-
/* Hide ribbon on small screens where it can obstruct content */
211212
@media (max-width: 640px) {
212213
.fork-ribbon { display: none; }
213214
}
@@ -216,96 +217,30 @@
216217
<script>
217218
(function () {
218219
function injectForkRibbon() {
219-
// Avoid inserting multiple times
220220
if (document.querySelector('.fork-ribbon')) return;
221221

222-
// Prefer site.social.github (format: owner/repo), fall back to site.github if present
223222
var repo = "{{ site.social.github | default: site.github | escape }}";
224223
if (!repo) return;
225224

226-
var url = 'https://github.com/' + repo;
227-
228225
var container = document.createElement('div');
229226
container.className = 'fork-ribbon';
230227

231228
var anchor = document.createElement('a');
232-
anchor.href = url;
229+
anchor.href = 'https://github.com/' + repo;
233230
anchor.target = '_blank';
234231
anchor.rel = 'noopener noreferrer';
235232
anchor.setAttribute('aria-label', 'Fork me on GitHub');
236-
237-
// Detect floating site menu to avoid collision
238-
var hasSiteMenu = !!document.querySelector('[data-site-menu]');
239-
240-
// Build the inner HTML (SVG icon + text)
241233
anchor.textContent = 'Fork me';
242-
// Ensure visuals match the ribbon CSS and prevent clipping
243-
anchor.style.display = 'inline-block';
244-
anchor.style.width = '140px';
245-
anchor.style.textAlign = 'center';
246-
anchor.style.color = '#fff';
247-
anchor.style.textDecoration = 'none';
248-
anchor.style.fontWeight = '700';
249-
anchor.style.fontSize = '13px';
250-
anchor.style.padding = '6px 0';
251-
anchor.style.background = '#151513';
252-
anchor.style.boxShadow = '0 6px 14px rgba(0, 0, 0, 0.2)';
253-
anchor.style.borderRadius = '2px';
254-
anchor.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
255-
256-
if (hasSiteMenu) {
257-
// Place on left and rotate -45deg
258-
container.style.left = '-44px';
259-
anchor.style.transform = 'rotate(-45deg)';
260-
anchor.style.transformOrigin = '0 0';
261-
} else {
262-
// Place on right and rotate 45deg
263-
container.style.right = '-44px';
264-
anchor.style.transform = 'rotate(45deg)';
265-
anchor.style.transformOrigin = '100% 0';
266-
}
267234

268235
container.appendChild(anchor);
269-
270-
// If body exists, append normally
271-
if (document.body) {
272-
document.body.appendChild(container);
273-
return;
274-
}
275-
276-
// If document isn't parsed yet, attempt document.write as a fallback so the element ends up in the document
277-
try {
278-
if (typeof document.write === 'function' && document.readyState === 'loading') {
279-
var posAttr = hasSiteMenu ? 'left:-44px' : 'right:-44px';
280-
var rotation = hasSiteMenu ? 'transform:rotate(-45deg);transform-origin:0 0;' : 'transform:rotate(45deg);transform-origin:100% 0;';
281-
var html = '<div class="fork-ribbon" style="top:12px;' + posAttr + '"><a style="display:block;width:140px;' + rotation + 'background:#151513;color:#fff;text-align:center;" href="' + url + '" target="_blank" rel="noopener noreferrer">Fork me</a></div>';
282-
document.write(html);
283-
return;
284-
}
285-
} catch (e) {
286-
// ignore and continue to last-resort append below
287-
}
288-
289-
// As a last resort, append to documentElement
290-
(document.documentElement || document).appendChild(container);
236+
document.body.appendChild(container);
291237
}
292238

293-
// Run immediately if DOM is already available, otherwise wait for DOMContentLoaded.
294239
if (document.readyState === 'loading') {
295-
document.addEventListener('DOMContentLoaded', function () {
296-
injectForkRibbon();
297-
});
298-
// Also run on window.load to catch pages that defer document modifications
299-
window.addEventListener('load', function () { injectForkRibbon(); });
300-
// Fallback in case DOMContentLoaded doesn't fire for some reason in certain pages
301-
setTimeout(function () { injectForkRibbon(); }, 3000);
240+
document.addEventListener('DOMContentLoaded', injectForkRibbon);
241+
window.addEventListener('load', injectForkRibbon);
302242
} else {
303-
try {
304-
injectForkRibbon();
305-
} catch (e) {
306-
// If anything goes wrong, try again shortly
307-
setTimeout(injectForkRibbon, 3000);
308-
}
243+
injectForkRibbon();
309244
}
310245
})();
311246
</script>

0 commit comments

Comments
 (0)