forge
Explore
Log in

Don't you dare go Hollow

Opening one branch rule while another is open no longer bounces the page: the browser shut the open sibling of the exclusive group at once while the new one slid open

Browse files at this commit

2525121a1b7c2440e6053e9a03c6858412cf2c53Ahmet Kaan GümüşParent: dba5a1e
  • fix
    • opening one branch rule while another is open no longer bounces the page: the browser shut the open sibling of the exclusive group at once while the new one slid open
    • now the opened rule leaves the group for the slide, the open one slides shut alongside, and the group comes back once both have finished
Show full message
🐛 fix: opening one branch rule while another is open no longer bounces the page: the browser shut the open sibling of the exclusive group at once while the new one slid open; now the opened rule leaves the group for the slide, the open one slides shut alongside, and the group comes back once both have finished
crates/forge-web/assets/nav.jsmodified+37 -53
@@ -731,6 +731,17 @@
731 731
732 function slideDetails(d) {732 function slideDetails(d) {
733 var opening = d.__closing || !d.open;733 var opening = d.__closing || !d.open;
734+ // An exclusive group (details[name]): the browser would shut the open sibling at once while this
735+ // one slides, so the page jumps. This one leaves the group for the slide, the sibling slides shut
736+ // alongside, and the name comes back once both have finished.
737+ var group = opening ? d.getAttribute('name') : null;
738+ var others = [];
739+ if (group) {
740+ document.querySelectorAll('details[name]').forEach(function (o) {
741+ if (o !== d && o.getAttribute('name') === group && o.open && !o.__closing) { others.push(o); }
742+ });
743+ if (others.length) { d.removeAttribute('name'); } else { group = null; }
744+ }
734 var from = d.getBoundingClientRect().height;745 var from = d.getBoundingClientRect().height;
735 if (d.__slide) { d.__slide.cancel(); }746 if (d.__slide) { d.__slide.cancel(); }
736 d.open = false;747 d.open = false;
@@ -746,6 +757,19 @@
746 d.style.overflow = '';757 d.style.overflow = '';
747 if (d.__closing) { d.__closing = false; d.open = false; }758 if (d.__closing) { d.__closing = false; d.open = false; }
748 };759 };
760+ if (group) {
761+ others.forEach(slideDetails);
762+ var slides = others.map(function (o) { return o.__slide.finished; }).concat(slide.finished);
763+ // `finished` settles before onfinish shuts a closing sibling, and the name must come back only
764+ // once they are shut, or the browser would shut this one instead. A sibling the reader opened
765+ // again meanwhile keeps this one out of the group.
766+ Promise.allSettled(slides).then(function () {
767+ others.forEach(function (o) {
768+ if (o.__closing) { o.__closing = false; o.open = false; }
769+ });
770+ if (others.every(function (o) { return !o.open; })) { d.setAttribute('name', group); }
771+ });
772+ }
749 }773 }
750 774
751 document.addEventListener('click', function (e) {775 document.addEventListener('click', function (e) {
@@ -1289,7 +1313,7 @@
1289 refreshActivity();1313 refreshActivity();
1290 }1314 }
1291 1315
1292- // The live activity: the profile corner (heat ring, chips, waiting list) and the live strip after1316+ // The live activity: the profile corner (heat ring, chips) and the live strip after
1293 // the path bar. The server's activity JSON (GET /-/activity) is the source. An `activity` event of1317 // the path bar. The server's activity JSON (GET /-/activity) is the source. An `activity` event of
1294 // the shell stream, and every `unread` event, fetches it again and redraws whatever is on the page.1318 // the shell stream, and every `unread` event, fetches it again and redraws whatever is on the page.
1295 // Nothing changes before the JSON says so. A finished run leaves the strip when the server's window1319 // Nothing changes before the JSON says so. A finished run leaves the strip when the server's window
@@ -1422,7 +1446,7 @@
1422 });1446 });
1423 }1447 }
1424 1448
1425- // The heat ring: a full ember ring while any of the viewer's runs is going, a plain ring otherwise.1449+ // The heat ring: an accent ring while any of the viewer's runs is going, none otherwise.
1426 function drawRing(ring, running) {1450 function drawRing(ring, running) {
1427 if (running.length) { ring.classList.add('hot'); } else { ring.classList.remove('hot'); }1451 if (running.length) { ring.classList.add('hot'); } else { ring.classList.remove('hot'); }
1428 }1452 }
@@ -1430,18 +1454,24 @@
1430 // The chips: one per non-zero count. The titles come from the chip box's templates, with `{n}`1454 // The chips: one per non-zero count. The titles come from the chip box's templates, with `{n}`
1431 // standing for the count; the singular template is used for one.1455 // standing for the count; the singular template is used for one.
1432 function drawChips(box, json) {1456 function drawChips(box, json) {
1457+ // Each chip links to the newest thing it counts, or to the inbox when that is not listed.
1458+ var newest = function (kind) {
1459+ var item = (json.waiting || []).filter(function (w) { return w.kind === kind; })[0];
1460+ return item ? item.href : '/notifications';
1461+ };
1433 var chips = [1462 var chips = [
1434- { kind: 'review', cls: 'chip chip-review', n: json.reviews, tpl: 'data-review' },1463+ { kind: 'review', cls: 'chip chip-review', n: json.reviews, tpl: 'data-review', href: newest('review') },
1435- { kind: 'mention', cls: 'chip chip-mention', n: json.mentions, tpl: 'data-mention' },1464+ { kind: 'mention', cls: 'chip chip-mention', n: json.mentions, tpl: 'data-mention', href: newest('mention') },
1436- { kind: 'failing', cls: 'chip chip-failing', n: json.failing, tpl: 'data-failing' }1465+ { kind: 'failing', cls: 'chip chip-failing', n: json.failing, tpl: 'data-failing', href: json.failing_href || '/notifications' }
1437 ];1466 ];
1438 box.textContent = '';1467 box.textContent = '';
1439 chips.forEach(function (c) {1468 chips.forEach(function (c) {
1440 var n = Number(c.n) || 0;1469 var n = Number(c.n) || 0;
1441 if (n <= 0) { return; }1470 if (n <= 0) { return; }
1442 var tpl = box.getAttribute(c.tpl + (n === 1 ? '-one' : '')) || '';1471 var tpl = box.getAttribute(c.tpl + (n === 1 ? '-one' : '')) || '';
1443- var chip = document.createElement('span');1472+ var chip = document.createElement('a');
1444 chip.className = c.cls;1473 chip.className = c.cls;
1474+ chip.setAttribute('href', c.href);
1445 chip.setAttribute('title', tpl.split('{n}').join(String(n)));1475 chip.setAttribute('title', tpl.split('{n}').join(String(n)));
1446 chip.appendChild(chipIcon(c.kind));1476 chip.appendChild(chipIcon(c.kind));
1447 chip.appendChild(document.createTextNode(String(n)));1477 chip.appendChild(document.createTextNode(String(n)));
@@ -1449,51 +1479,7 @@
1449 });1479 });
1450 }1480 }
1451 1481
1452- // The waiting list and its caption: built from the server's items, and removed when there are none.1482+ // Redraws every strip, ring and chip box on the page from one activity JSON. The
1453- // They sit before the menu's first link (All notifications).
1454- function drawWaiting(menu, waiting) {
1455- var cap = menu.querySelector('.corner-cap');
1456- var list = menu.querySelector('.corner-waiting');
1457- if (!waiting.length) {
1458- if (cap) { cap.remove(); }
1459- if (list) { list.remove(); }
1460- return;
1461- }
1462- var anchor = menu.querySelector('.corner-link');
1463- if (!cap) {
1464- cap = document.createElement('p');
1465- cap.className = 'corner-cap';
1466- cap.textContent = menu.getAttribute('data-cap') || '';
1467- menu.insertBefore(cap, anchor);
1468- }
1469- if (!list) {
1470- list = document.createElement('ul');
1471- list.className = 'corner-waiting';
1472- menu.insertBefore(list, anchor);
1473- }
1474- list.textContent = '';
1475- waiting.forEach(function (item) {
1476- var li = document.createElement('li');
1477- var a = document.createElement('a');
1478- a.setAttribute('href', localHref(item.href));
1479- var dot = document.createElement('span');
1480- dot.className = 'corner-dot ' + (item.kind === 'review' ? 'review' : 'mention');
1481- var text = document.createElement('span');
1482- text.className = 'corner-item';
1483- var title = document.createElement('span');
1484- title.textContent = String(item.title || '');
1485- var where = document.createElement('small');
1486- where.textContent = String(item.where || '');
1487- text.appendChild(title);
1488- text.appendChild(where);
1489- a.appendChild(dot);
1490- a.appendChild(text);
1491- li.appendChild(a);
1492- list.appendChild(li);
1493- });
1494- }
1495-
1496- // Redraws every strip, ring, chip box and waiting menu on the page from one activity JSON. The
1497 // elements are looked up here each time, since a swap may have replaced them.1483 // elements are looked up here each time, since a swap may have replaced them.
1498 function drawActivity(json) {1484 function drawActivity(json) {
1499 var strips = document.querySelectorAll('.live-strip[data-activity]');1485 var strips = document.querySelectorAll('.live-strip[data-activity]');
@@ -1503,8 +1489,6 @@
1503 for (var r = 0; r < rings.length; r++) { drawRing(rings[r], running); }1489 for (var r = 0; r < rings.length; r++) { drawRing(rings[r], running); }
1504 var boxes = document.querySelectorAll('.corner-chips');1490 var boxes = document.querySelectorAll('.corner-chips');
1505 for (var b = 0; b < boxes.length; b++) { drawChips(boxes[b], json); }1491 for (var b = 0; b < boxes.length; b++) { drawChips(boxes[b], json); }
1506- var menus = document.querySelectorAll('.corner-menu');
1507- for (var m = 0; m < menus.length; m++) { drawWaiting(menus[m], json.waiting || []); }
1508 // Finished runs leave the strip when the server's window ends, so the JSON is asked for again.1492 // Finished runs leave the strip when the server's window ends, so the JSON is asked for again.
1509 clearTimeout(activityTimer);1493 clearTimeout(activityTimer);
1510 activityTimer = null;1494 activityTimer = null;