2 Commits
v1.4.1 ... v1.5

4 changed files with 62 additions and 23 deletions

View File

@@ -28,15 +28,17 @@
* max-height alone does nothing. A stylesheet !important overrides the inline
* (non-important) min-height so max-height can win.
*
* We override it to a small NON-ZERO value, not 0: Kanboard relies on that same inline
* We override it to a NON-ZERO value, not 0: Kanboard relies on that same inline
* min-height to keep EMPTY columns tall enough to be a drop target, so zeroing it makes
* you unable to drop a card into an empty collapsed column. 100px clears Kanboard's 70px
* drag placeholder (.draggable-placeholder) with margin, and stays well below max-height
* so tall columns still shrink; non-empty columns are unaffected (their content is taller).
* you unable to drop a card into an empty collapsed column. 250px gives a comfortable drop
* target (well above Kanboard's 70px .draggable-placeholder) while staying below the
* collapsed max-height, so the board never overflows the viewport (which would re-hide the
* horizontal scrollbar). Non-empty columns are unaffected -- their content is taller -- and
* short columns simply get this min-height, which is only cosmetic (no scrollbar).
*/
#board td .board-task-list.board-task-list-compact {
max-height: calc(100vh - var(--sv-shrink-offset, 240px)) !important;
min-height: 100px !important;
min-height: 250px !important;
}
/*

View File

@@ -10,6 +10,14 @@
* track + thumb widget: it renders and behaves the same in every browser (Chrome, Firefox,
* Safari) and on touch, and its thickness follows the --sv-bar-size setting.
*
* Resilience note: after a card drag Kanboard rebuilds the board with
* `$("#board-container").replaceWith(data)` (BoardDragAndDrop.refresh), so the element we
* started with is destroyed and replaced. We therefore never cache the container: we
* re-resolve it on every use, listen for its scroll on `document` in the capture phase (so
* the listener survives the swap), and observe the STABLE parent (which is not replaced) so
* the widget keeps working -- previously the observer and scroll listener died with the old
* element, which froze the bar and lost sync after each move.
*
* Loaded only when the "Add a top horizontal scrollbar" setting is enabled.
*/
(function () {
@@ -18,14 +26,21 @@
// Keep the thumb wide enough to grab, even on a very wide board.
var MIN_THUMB = 24;
function getContainer() {
return document.getElementById("board-container");
}
function init() {
var container = document.getElementById("board-container");
var container = getContainer();
// Only on the board, and never add it twice.
if (!container || document.querySelector(".sv-top-scroll")) {
return;
}
// The parent survives the board refresh (only #board-container is replaced).
var boardParent = container.parentNode;
var track = document.createElement("div");
track.className = "sv-top-scroll";
@@ -33,16 +48,21 @@
thumb.className = "sv-top-scroll-thumb";
track.appendChild(thumb);
container.parentNode.insertBefore(track, container);
boardParent.insertBefore(track, container);
var dragging = false;
var dragStartX = 0;
var dragStartScrollLeft = 0;
function metrics() {
var c = getContainer();
if (!c) {
return null;
}
return {
viewport: container.clientWidth,
content: container.scrollWidth,
c: c,
viewport: c.clientWidth,
content: c.scrollWidth,
trackW: track.clientWidth
};
}
@@ -50,7 +70,7 @@
function positionThumb(m, thumbW) {
var maxScroll = m.content - m.viewport;
var maxThumb = m.trackW - thumbW;
var left = maxScroll > 0 ? (container.scrollLeft / maxScroll) * maxThumb : 0;
var left = maxScroll > 0 ? (m.c.scrollLeft / maxScroll) * maxThumb : 0;
thumb.style.transform = "translateX(" + Math.round(left) + "px)";
}
@@ -58,7 +78,7 @@
function layout() {
var m = metrics();
if (m.content <= m.viewport || m.trackW <= 0) {
if (!m || m.content <= m.viewport || m.trackW <= 0) {
track.style.display = "none";
return;
}
@@ -73,21 +93,33 @@
positionThumb(m, thumbW);
}
// Board scrolled by any other means -> keep the thumb in sync.
container.addEventListener("scroll", function () {
// Keep the track directly before the (current) container after a board refresh.
function reattachTrack() {
var c = getContainer();
if (c && c.parentNode && track.nextSibling !== c) {
c.parentNode.insertBefore(track, c);
}
}
// Board scrolled by any other means -> keep the thumb in sync. Capture-phase on
// document catches #board-container's (non-bubbling) scroll and survives the swap.
document.addEventListener("scroll", function (e) {
if (dragging) { return; }
if (e.target !== getContainer()) { return; }
var m = metrics();
if (m.content <= m.viewport) { return; }
if (!m || m.content <= m.viewport) { return; }
positionThumb(m, thumb.offsetWidth);
});
}, true);
// Drag the thumb (mouse + touch via Pointer Events).
thumb.addEventListener("pointerdown", function (e) {
var c = getContainer();
if (!c) { return; }
e.preventDefault();
e.stopPropagation();
dragging = true;
dragStartX = e.clientX;
dragStartScrollLeft = container.scrollLeft;
dragStartScrollLeft = c.scrollLeft;
track.classList.add("sv-dragging");
if (thumb.setPointerCapture) {
thumb.setPointerCapture(e.pointerId);
@@ -97,10 +129,11 @@
thumb.addEventListener("pointermove", function (e) {
if (!dragging) { return; }
var m = metrics();
if (!m) { return; }
var maxThumb = m.trackW - thumb.offsetWidth;
var maxScroll = m.content - m.viewport;
if (maxThumb <= 0) { return; }
container.scrollLeft = dragStartScrollLeft + (e.clientX - dragStartX) * (maxScroll / maxThumb);
m.c.scrollLeft = dragStartScrollLeft + (e.clientX - dragStartX) * (maxScroll / maxThumb);
positionThumb(m, thumb.offsetWidth);
});
@@ -120,7 +153,7 @@
track.addEventListener("pointerdown", function (e) {
if (e.target === thumb || dragging) { return; }
var m = metrics();
if (m.content <= m.viewport) { return; }
if (!m || m.content <= m.viewport) { return; }
var thumbW = thumb.offsetWidth;
var maxThumb = m.trackW - thumbW;
@@ -132,15 +165,19 @@
if (targetLeft < 0) { targetLeft = 0; }
if (targetLeft > maxThumb) { targetLeft = maxThumb; }
container.scrollLeft = (targetLeft / maxThumb) * maxScroll;
m.c.scrollLeft = (targetLeft / maxThumb) * maxScroll;
positionThumb(m, thumbW);
});
window.addEventListener("resize", layout);
// The board can be redrawn by AJAX polling / drag-and-drop; keep sizes current.
// Observe the STABLE parent so we keep working after #board-container is replaced by
// a card move / AJAX polling; re-seat the track and recompute sizes on any change.
if (window.MutationObserver) {
new MutationObserver(layout).observe(container, { childList: true, subtree: true });
new MutationObserver(function () {
reattachTrack();
layout();
}).observe(boardParent, { childList: true, subtree: true });
}
layout();

View File

@@ -51,7 +51,7 @@ class Plugin extends Base
public function getPluginVersion()
{
return '1.4.1';
return '1.5.0';
}
public function getPluginHomepage()

View File

@@ -1 +1 @@
ShrinkVertically v1.4.1
ShrinkVertically v1.5