2 Commits

Author SHA1 Message Date
3beaa88fe9 drag-scroll checkbox 2026-06-28 17:19:04 -03:00
dcb672777d drag-scroll behavior new feature 2026-06-28 17:18:53 -03:00
6 changed files with 120 additions and 5 deletions

View File

@@ -48,3 +48,24 @@
.sv-top-scroll-inner {
height: 1px;
}
/*
* Click-and-drag horizontal scrolling (added by Asset/js/drag-scroll.js when the
* "Drag the board background to scroll" setting is enabled). The .sv-drag-scroll class
* is set on #board-container by the script, so these rules are inert when disabled.
* A grab cursor advertises the empty background; cards keep the normal cursor since
* pressing them does a card drag, not a pan.
*/
#board-container.sv-drag-scroll {
cursor: grab;
}
#board-container.sv-drag-scroll .task-board {
cursor: default;
}
.sv-grabbing,
.sv-grabbing * {
cursor: grabbing !important;
user-select: none !important;
}

75
Asset/js/drag-scroll.js Normal file
View File

@@ -0,0 +1,75 @@
/*
* ShrinkVertically -- optional click-and-drag horizontal scrolling of the board.
*
* Like the Trello board canvas: press the empty board background and drag left/right
* to scroll #board-container horizontally. The pan only starts on empty background --
* pressing a task card, a drag handle, or any interactive control is ignored, so this
* never interferes with Kanboard's own card and column drag-and-drop.
*
* Loaded only when the "Drag the board background to scroll" setting is enabled.
*/
(function () {
"use strict";
// Pressing any of these (or their descendants) must NOT start a background pan.
var IGNORE = "a, button, input, textarea, select, label, " +
".task-board, [data-task-id], .task-board-sort-handle, " +
".draggable-row-handle, .dropdown, .ui-sortable-handle";
function isIgnored(el) {
return !!(el && el.closest && el.closest(IGNORE));
}
function init() {
var container = document.getElementById("board-container");
if (!container || container.getAttribute("data-sv-drag") === "1") {
return;
}
container.setAttribute("data-sv-drag", "1");
container.classList.add("sv-drag-scroll");
var dragging = false;
var startX = 0;
var startScrollLeft = 0;
container.addEventListener("mousedown", function (e) {
// Left button only, and only on empty board background.
if (e.button !== 0 || isIgnored(e.target)) {
return;
}
dragging = true;
startX = e.clientX;
startScrollLeft = container.scrollLeft;
container.classList.add("sv-grabbing");
e.preventDefault();
});
document.addEventListener("mousemove", function (e) {
if (!dragging) {
return;
}
container.scrollLeft = startScrollLeft - (e.clientX - startX);
e.preventDefault();
});
function stop() {
if (!dragging) {
return;
}
dragging = false;
container.classList.remove("sv-grabbing");
}
document.addEventListener("mouseup", stop);
document.addEventListener("mouseleave", stop);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();

View File

@@ -18,12 +18,14 @@ class ConfigController extends BaseController
{
$offset = (int) $this->configModel->get('shrink_vertically_offset', self::DEFAULT_OFFSET);
$topScrollbar = (int) $this->configModel->get('shrink_vertically_top_scrollbar', 0);
$dragScroll = (int) $this->configModel->get('shrink_vertically_drag_scroll', 0);
$this->response->html($this->helper->layout->config('shrinkVertically:config/show', array(
'title' => t('Settings').' > '.t('Shrink Vertically'),
'values' => array(
'shrink_vertically_offset' => $offset,
'shrink_vertically_top_scrollbar' => $topScrollbar,
'shrink_vertically_drag_scroll' => $dragScroll,
),
'errors' => array(),
)));
@@ -37,10 +39,12 @@ class ConfigController extends BaseController
$offset = max(self::MIN_OFFSET, min(self::MAX_OFFSET, $offset));
$topScrollbar = isset($values['shrink_vertically_top_scrollbar']) ? 1 : 0;
$dragScroll = isset($values['shrink_vertically_drag_scroll']) ? 1 : 0;
if ($this->configModel->save(array(
'shrink_vertically_offset' => $offset,
'shrink_vertically_top_scrollbar' => $topScrollbar,
'shrink_vertically_drag_scroll' => $dragScroll,
))) {
$this->flash->success(t('Settings saved successfully.'));
} else {

View File

@@ -32,6 +32,13 @@ class Plugin extends Base
'template' => 'plugins/ShrinkVertically/Asset/js/top-scrollbar.js',
));
}
// Optional: click-and-drag the board background to scroll horizontally.
if ((int) $this->configModel->get('shrink_vertically_drag_scroll', 0) === 1) {
$this->hook->on('template:layout:js', array(
'template' => 'plugins/ShrinkVertically/Asset/js/drag-scroll.js',
));
}
}
public function getPluginName()
@@ -51,7 +58,7 @@ class Plugin extends Base
public function getPluginVersion()
{
return '1.0.0';
return '1.1.0';
}
public function getPluginHomepage()

View File

@@ -1,9 +1,10 @@
# ShrinkVertically -- keep the board horizontal scrollbar visible
A small Kanboard plugin focused on the board's horizontal scrollbar. It fixes the
vertically-collapsed board view so the bottom scrollbar stays on screen, and can
optionally add a second, mirrored horizontal scrollbar above the columns. Both are
configurable under "Settings -> Shrink Vertically".
A small Kanboard plugin focused on getting around the board horizontally. It fixes the
vertically-collapsed board view so the bottom scrollbar stays on screen, can optionally
add a second mirrored scrollbar above the columns, and can optionally let you drag the
board background to scroll (like Trello). Everything is configurable under
"Settings -> Shrink Vertically".
## The problem

View File

@@ -20,6 +20,13 @@
</p>
</fieldset>
<fieldset>
<?= $this->form->checkbox('shrink_vertically_drag_scroll', t('Drag the board background to scroll horizontally'), 1, isset($values['shrink_vertically_drag_scroll']) && $values['shrink_vertically_drag_scroll'] == 1) ?>
<p class="form-help">
<?= t('Like Trello: click and drag on the empty board background to scroll the columns sideways. Dragging a task card or a handle still works as usual.') ?>
</p>
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
</div>