Skip to content

Commit b718368

Browse files
committed
feat(admin): highlight element by URL hash with smooth scroll
• Added a focus-pulse animation and JS logic to highlight form elements referenced by the URL hash and scroll them into view smoothly. Includes reduced motion fallback. • Bumped csk-common version to `1.3.17`.
1 parent 892a9f0 commit b718368

5 files changed

Lines changed: 57 additions & 6 deletions

File tree

css/admin.css

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ body.csk-clean .footer .skeleton-footer-logo {
25022502
background-image: var(--bs-form-select-bg-img), var(--bs-form-select-bg-icon, none);
25032503
background-repeat: no-repeat;
25042504
background-position: left .75rem center;
2505-
background-size: 16px 12px;
2505+
background-size: 1rem .75rem;
25062506
border: var(--bs-border-width) solid var(--bs-border-color);
25072507
border-radius: var(--bs-border-radius);
25082508
block-size: calc(1.5em + .75rem + 2px);
@@ -2656,3 +2656,31 @@ caption,
26562656
.scroll-to-top i {
26572657
font-weight: 800;
26582658
}
2659+
2660+
@keyframes focus-pulse {
2661+
0% {
2662+
box-shadow: 0 0 0 0 rgba(var(--bs-danger-rgb), .35);
2663+
background-color: rgba(var(--bs-warning-rgb), 0);
2664+
}
2665+
2666+
50% {
2667+
box-shadow: 0 0 0 .188rem rgba(var(--bs-danger-rgb), .2);
2668+
background-color: rgba(var(--bs-warning-rgb), .1);
2669+
}
2670+
2671+
100% {
2672+
box-shadow: 0 0 0 0 rgba(var(--bs-warning-rgb), .35);
2673+
background-color: rgba(var(--bs-warning-rgb), 0);
2674+
}
2675+
}
2676+
2677+
.highlight-focus {
2678+
animation: focus-pulse .6s ease-in-out 3;
2679+
box-shadow: 0 0 0 0 rgba(var(--bs-danger-rgb), .35);
2680+
background-color: rgba(var(--bs-warning-rgb), 0);
2681+
}
2682+
2683+
.highlight-focus:prefers-reduced-motion {
2684+
animation: none;
2685+
outline: .188rem solid rgba(var(--bs-danger-rgb), .5);
2686+
}

css/admin.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/admin.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,36 @@
338338
}]
339339
};
340340
return $(selector).DataTable($.extend(true, {}, defaults, options));
341+
},
342+
/**
343+
* Highlights and element referenced by the URL hash (element ID).
344+
* Smooth scroll included. Silently bails if no match.
345+
* @since 3.10.0
346+
*/
347+
highlightByHash: function() {
348+
const hash = window.location.hash;
349+
if (!hash) return;
350+
351+
const el = document.getElementById(hash.substring(1));
352+
if (!el) return;
353+
354+
// Look for best ancestor wrapper
355+
const group = el.closest('.form-group, .mb-3, .form-check');
356+
357+
const target = group || el;
358+
target.classList.add('highlight-focus');
359+
target.scrollIntoView({behavior: 'smooth', block: 'start', inline: 'nearest'});
360+
361+
// Remove the class after blink sequence
362+
setTimeout(() => target.classList.remove('highlight-focus'), 4000);
341363
}
342364
};
343365

344366
/**
345367
* Register our custom Lazy Load function.
346368
* @since 2.0
347369
*/
370+
csk.ui.highlightByHash();
348371
csk.ui.addListener("mousedown", csk.ui.selectOff)
349372
csk.ui.addListener("mouseup", csk.ui.selectOn)
350373
csk.ui.addListener("load", csk.ui.lazyLoad);
@@ -353,7 +376,7 @@
353376
csk.ui.addListener('click', function(e) {
354377
if (e.target.closest('.scroll-to-top')) {
355378
e.preventDefault();
356-
window.scrollTo({ top: 0, behavior: 'smooth' });
379+
window.scrollTo({top: 0, behavior: 'smooth'});
357380
}
358381
});
359382

@@ -1148,7 +1171,7 @@
11481171
url.searchParams.delete(key);
11491172
}
11501173
}
1151-
window.history.pushState({ href: url.href }, "", url.href);
1174+
window.history.pushState({href: url.href}, "", url.href);
11521175
$(this).remove();
11531176
});
11541177

js/admin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.16
1+
1.3.17

0 commit comments

Comments
 (0)