Show at most 4 categories, the rest behind a '+N' tag
- New partial/tag_list: first 4 categories, then a '+N' tag that opens the remaining ones (hover/keyboard on desktop, tap on touch screens; short close delay so the mouse can reach the list) - Used on the homepage, the article page and the news overview / tag pages (the latter now use the same pills instead of text links) - Article page: tag row grows when the tags wrap (was a fixed height) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7b1dbac8f
commit
df8c8a9c4f
10 files changed
+325
-32
No files matched your search
Vendored
+65
@@ -325,3 +325,68 @@ $(function () {
|
||||
$(this).tabs($(this).data('tabs') ?? {});
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* "+N" tag with the remaining categories of a news item
|
||||
* (partial/tag_list.blade.php). On desktop the list opens on hover / keyboard
|
||||
* focus (CSS); on touch screens a tap on "+N" toggles it. A tap or click
|
||||
* elsewhere, or Escape, closes it.
|
||||
*/
|
||||
(function () {
|
||||
// The list normally extends to the left from "+N". When there isn't enough
|
||||
// room for that (e.g. "+N" on the left of a second line on mobile), let it
|
||||
// extend to the right instead.
|
||||
function place(more) {
|
||||
var list = more.querySelector('.tags_more_list');
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
more.classList.remove('tags_more--left');
|
||||
var boundary = more.closest('.post, .box');
|
||||
var minLeft = Math.max(boundary ? boundary.getBoundingClientRect().left : 0, 0);
|
||||
if (list.getBoundingClientRect().left < minLeft) {
|
||||
more.classList.add('tags_more--left');
|
||||
}
|
||||
}
|
||||
|
||||
function placeFromEvent(event) {
|
||||
var more = event.target.closest ? event.target.closest('.tags_more') : null;
|
||||
if (more && !more.contains(event.relatedTarget)) {
|
||||
place(more);
|
||||
}
|
||||
}
|
||||
document.addEventListener('mouseover', placeFromEvent);
|
||||
document.addEventListener('focusin', placeFromEvent);
|
||||
|
||||
function closeAll(except) {
|
||||
var open = document.querySelectorAll('.tags_more.open');
|
||||
for (var i = 0; i < open.length; i++) {
|
||||
if (open[i] !== except) {
|
||||
open[i].classList.remove('open');
|
||||
open[i].querySelector('.tags_more_toggle').setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var toggle = event.target.closest ? event.target.closest('.tags_more_toggle') : null;
|
||||
if (toggle) {
|
||||
event.preventDefault();
|
||||
var more = toggle.closest('.tags_more');
|
||||
place(more);
|
||||
var isOpen = more.classList.toggle('open');
|
||||
toggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
||||
closeAll(more);
|
||||
return;
|
||||
}
|
||||
if (!(event.target.closest && event.target.closest('.tags_more_list'))) {
|
||||
closeAll(null);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape') {
|
||||
closeAll(null);
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user