Tabs on record pages, quick looks, forms, the admin category and tag kinds on a phone and the mail settings fold into More like the list views instead of wrapping onto several lines or scrolling sideways, with More styled as one of the tabs and the open tab and form validation still working

This commit is contained in:
johnnyq
2026-11-20 17:32:26 -05:00
parent 156bc96693
commit 478c8edcc8
7 changed files with 79 additions and 54 deletions

View File

@@ -1,20 +1,27 @@
/*
* ITFlow - view tabs that don't fit fold into More.
* ITFlow - tabs that don't fit fold into More.
*
* The tab bars over the lists (.itflow-asset-tabs, the ones that scroll sideways:
* flex-nowrap overflow-auto) used to run off the edge of the card, with the last
* tabs out of sight behind a scroll nobody noticed. Now the tabs that don't fit
* go, from the end, into a More menu at the end of the bar, and come back as the
* bar gets wider. The tab that is open never goes into it. More wears the alarm
* of a tab in it that has one (Overdue in red, Unassigned in amber), with that
* tab's count.
* Tab rows used to run off the edge with the last tabs out of sight behind a
* scroll nobody noticed, or wrap onto two, three or more lines. Now they keep to
* one line: the tabs that don't fit go, from the end, into a More menu at the
* end of the row, and come back as it gets wider. The tab that is open never
* goes into it. More wears the alarm of a tab in it that has one (Overdue in
* red, Unassigned in amber, "2 open" on a record's Tickets), with that count.
*
* The rows: the view tabs over the lists (.itflow-asset-tabs), the tabs of a
* record page and its quick look (.itflow-asset-pills), a form's tabs
* (.itflow-asset-form-tabs), and any other .nav given .itflow-tabs-foldable.
* Those in a window are set up as it opens. A row laid out as a column (the
* kinds beside Admin > Categories on a wider screen) shows everything.
*
* The tabs themselves stay where they are, only hidden (.itflow-tab-folded), so
* whatever a page does with them still works - the tickets list updating their
* counts (agent/js/tickets_live.js), reconcile's tabs that filter in place.
* More's items are built as the menu opens, from the tabs as they are then: a
* link for a tab that is a link, otherwise a button that clicks the tab. More
* and its items aren't .nav-link, so nothing counting the tabs counts them.
* whatever a page does with them still works - Bootstrap's tabs, the tickets
* list updating their counts (agent/js/tickets_live.js), reconcile's tabs that
* filter in place, a form going to the tab with an empty required field. More's
* items are built as the menu opens, from the tabs as they are then: a link for
* a tab that is a link, otherwise a button that clicks the tab. More is a
* .nav-link.dropdown-toggle, so it looks like the tabs around it and Bootstrap's
* tabs leave it out; its items aren't .nav-link.
*/
(function () {
'use strict';
@@ -25,13 +32,20 @@
window.itflowTabFold = true;
var FOLDED = 'itflow-tab-folded';
var BARS = '.nav.itflow-asset-tabs, .itflow-asset-tabs > .nav, .nav.itflow-asset-pills, .nav.itflow-asset-form-tabs, .nav.itflow-tabs-foldable';
// A tab is a .nav-link of the row, or the .nav-item around one
function tabsOf(bar) {
return Array.prototype.filter.call(bar.children, function (el) {
return el.classList.contains('nav-link');
return !el.classList.contains('itflow-tabs-more')
&& (el.classList.contains('nav-link') || (el.classList.contains('nav-item') && el.querySelector('.nav-link')));
});
}
function linkOf(tab) {
return tab.classList.contains('nav-link') ? tab : tab.querySelector('.nav-link');
}
// A tab the page itself hides isn't ours to show or fold
function pageHidden(el) {
return !el.classList.contains(FOLDED) && getComputedStyle(el).display === 'none';
@@ -40,10 +54,10 @@
function setup(bar) {
bar.classList.add('itflow-tabs-fold');
var more = document.createElement('div');
more.className = 'dropdown itflow-tabs-more ' + FOLDED;
more.innerHTML = '<button type="button" class="itflow-tabs-more-toggle text-nowrap" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">'
+ 'More<span class="badge rounded-pill ms-1 d-none"></span><i class="fas fa-caret-down ms-1" aria-hidden="true"></i></button>'
var more = document.createElement(/^(UL|OL)$/.test(bar.tagName) ? 'li' : 'div');
more.className = 'nav-item dropdown itflow-tabs-more ' + FOLDED;
more.innerHTML = '<button type="button" class="nav-link dropdown-toggle itflow-tabs-more-toggle text-nowrap" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">'
+ 'More<span class="badge rounded-pill ms-1 d-none"></span></button>'
+ '<div class="dropdown-menu dropdown-menu-end"></div>';
bar.appendChild(more);
var badge = more.querySelector('.badge');
@@ -60,9 +74,9 @@
var alarm = null;
['text-bg-danger', 'text-bg-warning'].some(function (cls) {
return folded().some(function (tab) {
var b = tab.querySelector('.badge.' + cls);
var b = linkOf(tab).querySelector('.badge.' + cls);
if (b) {
alarm = [cls, b.textContent.trim(), tab];
alarm = [cls, b.textContent.trim(), linkOf(tab)];
}
return !!b;
});
@@ -73,6 +87,10 @@
}
function fit() {
// Not on screen yet (a window opening, a tab not shown) - it fits when it is
if (!bar.clientWidth) {
return;
}
observer.disconnect();
var tabs = tabsOf(bar);
var rules = Array.prototype.filter.call(bar.children, function (el) {
@@ -83,10 +101,10 @@
});
more.classList.add(FOLDED);
if (bar.scrollWidth > bar.clientWidth + 1) {
if (getComputedStyle(bar).flexDirection.indexOf('row') === 0 && bar.scrollWidth > bar.clientWidth + 1) {
more.classList.remove(FOLDED);
for (var i = tabs.length - 1; i >= 0 && bar.scrollWidth > bar.clientWidth + 1; i--) {
if (!tabs[i].classList.contains('active') && !pageHidden(tabs[i])) {
if (!linkOf(tabs[i]).classList.contains('active') && !pageHidden(tabs[i])) {
tabs[i].classList.add(FOLDED);
}
}
@@ -94,28 +112,31 @@
rules.forEach(function (rule) {
var before = false;
var after = false;
for (var el = rule.previousElementSibling; el; el = el.previousElementSibling) {
before = before || (el.classList.contains('nav-link') && !el.classList.contains(FOLDED) && !pageHidden(el));
}
for (el = rule.nextElementSibling; el; el = el.nextElementSibling) {
after = after || (el.classList.contains('nav-link') && !el.classList.contains(FOLDED) && !pageHidden(el));
}
var shown = tabs.filter(function (tab) {
return !tab.classList.contains(FOLDED) && !pageHidden(tab);
});
shown.forEach(function (tab) {
var at = rule.compareDocumentPosition(tab);
before = before || !!(at & Node.DOCUMENT_POSITION_PRECEDING);
after = after || !!(at & Node.DOCUMENT_POSITION_FOLLOWING);
});
rule.classList.toggle(FOLDED, !(before && after));
});
}
markMore();
observer.observe(bar, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ['class'] });
observer.observe(bar, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ['class', 'style'] });
}
// The menu, from the folded tabs as they are now - a line where a group starts
more.addEventListener('show.bs.dropdown', function () {
menu.textContent = '';
var tabs = folded();
tabs.forEach(function (tab, n) {
var prev = tab.previousElementSibling;
tabs.forEach(function (unit, n) {
var prev = unit.previousElementSibling;
if (n && prev && prev.classList.contains('vr')) {
menu.appendChild(Object.assign(document.createElement('div'), { className: 'dropdown-divider' }));
}
var tab = linkOf(unit);
var href = tab.getAttribute('href') || '';
var item = document.createElement(href && href.charAt(0) !== '#' ? 'a' : 'button');
item.className = 'dropdown-item d-flex align-items-center gap-2';
@@ -133,15 +154,16 @@
Array.prototype.forEach.call(tab.childNodes, function (node) {
item.appendChild(node.cloneNode(true));
});
// The gap spaces them out here, and the count goes to the right
// The gap spaces them out here, and the counts go to the right
item.querySelectorAll('.me-1, .ms-1').forEach(function (el) {
el.classList.remove('me-1', 'ms-1');
});
var count = item.querySelector('.badge');
if (count) {
count.classList.add('ms-auto');
item.querySelectorAll('.badge').forEach(function (count, k) {
if (!k) {
count.classList.add('ms-auto');
}
item.appendChild(count);
}
});
menu.appendChild(item);
});
});
@@ -179,7 +201,7 @@
}
function init() {
document.querySelectorAll('.itflow-asset-tabs.nav.flex-nowrap.overflow-auto, .itflow-asset-tabs > .nav.flex-nowrap.overflow-auto').forEach(function (bar) {
document.querySelectorAll(BARS).forEach(function (bar) {
if (!bar.classList.contains('itflow-tabs-fold') && tabsOf(bar).length > 1) {
setup(bar);
}
@@ -191,4 +213,6 @@
} else {
init();
}
// A window's tabs - a quick look, a form
document.addEventListener('shown.bs.modal', init);
})();