2 Commits
v1.4 ... v1.4.2

4 changed files with 63 additions and 20 deletions

View File

@@ -26,11 +26,17 @@
* (BoardDragAndDrop.js: css("min-height", parent().height())). In CSS, min-height * (BoardDragAndDrop.js: css("min-height", parent().height())). In CSS, min-height
* beats max-height, so that inline value keeps tall columns from shrinking and our * beats max-height, so that inline value keeps tall columns from shrinking and our
* max-height alone does nothing. A stylesheet !important overrides the inline * max-height alone does nothing. A stylesheet !important overrides the inline
* (non-important) min-height, so we reset it to 0 and let max-height win. * (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
* 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).
*/ */
#board td .board-task-list.board-task-list-compact { #board td .board-task-list.board-task-list-compact {
max-height: calc(100vh - var(--sv-shrink-offset, 240px)) !important; max-height: calc(100vh - var(--sv-shrink-offset, 240px)) !important;
min-height: 0 !important; min-height: 100px !important;
} }
/* /*

View File

@@ -10,6 +10,14 @@
* track + thumb widget: it renders and behaves the same in every browser (Chrome, Firefox, * 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. * 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. * Loaded only when the "Add a top horizontal scrollbar" setting is enabled.
*/ */
(function () { (function () {
@@ -18,14 +26,21 @@
// Keep the thumb wide enough to grab, even on a very wide board. // Keep the thumb wide enough to grab, even on a very wide board.
var MIN_THUMB = 24; var MIN_THUMB = 24;
function getContainer() {
return document.getElementById("board-container");
}
function init() { function init() {
var container = document.getElementById("board-container"); var container = getContainer();
// Only on the board, and never add it twice. // Only on the board, and never add it twice.
if (!container || document.querySelector(".sv-top-scroll")) { if (!container || document.querySelector(".sv-top-scroll")) {
return; return;
} }
// The parent survives the board refresh (only #board-container is replaced).
var boardParent = container.parentNode;
var track = document.createElement("div"); var track = document.createElement("div");
track.className = "sv-top-scroll"; track.className = "sv-top-scroll";
@@ -33,16 +48,21 @@
thumb.className = "sv-top-scroll-thumb"; thumb.className = "sv-top-scroll-thumb";
track.appendChild(thumb); track.appendChild(thumb);
container.parentNode.insertBefore(track, container); boardParent.insertBefore(track, container);
var dragging = false; var dragging = false;
var dragStartX = 0; var dragStartX = 0;
var dragStartScrollLeft = 0; var dragStartScrollLeft = 0;
function metrics() { function metrics() {
var c = getContainer();
if (!c) {
return null;
}
return { return {
viewport: container.clientWidth, c: c,
content: container.scrollWidth, viewport: c.clientWidth,
content: c.scrollWidth,
trackW: track.clientWidth trackW: track.clientWidth
}; };
} }
@@ -50,7 +70,7 @@
function positionThumb(m, thumbW) { function positionThumb(m, thumbW) {
var maxScroll = m.content - m.viewport; var maxScroll = m.content - m.viewport;
var maxThumb = m.trackW - thumbW; 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)"; thumb.style.transform = "translateX(" + Math.round(left) + "px)";
} }
@@ -58,7 +78,7 @@
function layout() { function layout() {
var m = metrics(); var m = metrics();
if (m.content <= m.viewport || m.trackW <= 0) { if (!m || m.content <= m.viewport || m.trackW <= 0) {
track.style.display = "none"; track.style.display = "none";
return; return;
} }
@@ -73,21 +93,33 @@
positionThumb(m, thumbW); positionThumb(m, thumbW);
} }
// Board scrolled by any other means -> keep the thumb in sync. // Keep the track directly before the (current) container after a board refresh.
container.addEventListener("scroll", function () { 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 (dragging) { return; }
if (e.target !== getContainer()) { return; }
var m = metrics(); var m = metrics();
if (m.content <= m.viewport) { return; } if (!m || m.content <= m.viewport) { return; }
positionThumb(m, thumb.offsetWidth); positionThumb(m, thumb.offsetWidth);
}); }, true);
// Drag the thumb (mouse + touch via Pointer Events). // Drag the thumb (mouse + touch via Pointer Events).
thumb.addEventListener("pointerdown", function (e) { thumb.addEventListener("pointerdown", function (e) {
var c = getContainer();
if (!c) { return; }
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
dragging = true; dragging = true;
dragStartX = e.clientX; dragStartX = e.clientX;
dragStartScrollLeft = container.scrollLeft; dragStartScrollLeft = c.scrollLeft;
track.classList.add("sv-dragging"); track.classList.add("sv-dragging");
if (thumb.setPointerCapture) { if (thumb.setPointerCapture) {
thumb.setPointerCapture(e.pointerId); thumb.setPointerCapture(e.pointerId);
@@ -97,10 +129,11 @@
thumb.addEventListener("pointermove", function (e) { thumb.addEventListener("pointermove", function (e) {
if (!dragging) { return; } if (!dragging) { return; }
var m = metrics(); var m = metrics();
if (!m) { return; }
var maxThumb = m.trackW - thumb.offsetWidth; var maxThumb = m.trackW - thumb.offsetWidth;
var maxScroll = m.content - m.viewport; var maxScroll = m.content - m.viewport;
if (maxThumb <= 0) { return; } 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); positionThumb(m, thumb.offsetWidth);
}); });
@@ -120,7 +153,7 @@
track.addEventListener("pointerdown", function (e) { track.addEventListener("pointerdown", function (e) {
if (e.target === thumb || dragging) { return; } if (e.target === thumb || dragging) { return; }
var m = metrics(); var m = metrics();
if (m.content <= m.viewport) { return; } if (!m || m.content <= m.viewport) { return; }
var thumbW = thumb.offsetWidth; var thumbW = thumb.offsetWidth;
var maxThumb = m.trackW - thumbW; var maxThumb = m.trackW - thumbW;
@@ -132,15 +165,19 @@
if (targetLeft < 0) { targetLeft = 0; } if (targetLeft < 0) { targetLeft = 0; }
if (targetLeft > maxThumb) { targetLeft = maxThumb; } if (targetLeft > maxThumb) { targetLeft = maxThumb; }
container.scrollLeft = (targetLeft / maxThumb) * maxScroll; m.c.scrollLeft = (targetLeft / maxThumb) * maxScroll;
positionThumb(m, thumbW); positionThumb(m, thumbW);
}); });
window.addEventListener("resize", layout); 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) { if (window.MutationObserver) {
new MutationObserver(layout).observe(container, { childList: true, subtree: true }); new MutationObserver(function () {
reattachTrack();
layout();
}).observe(boardParent, { childList: true, subtree: true });
} }
layout(); layout();

View File

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

View File

@@ -1 +1 @@
ShrinkVertically v1.4 ShrinkVertically v1.4.2