Skip to content

Commit

Permalink
Reattach event listeners after #board-container is lost
Browse files Browse the repository at this point in the history
  • Loading branch information
psy-q committed Mar 4, 2021
1 parent 9527b56 commit 47ffec7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
76 changes: 42 additions & 34 deletions Assets/scroll.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
KB.on('dom.ready', function () {
function attachHorizontalScrollListeners() {
var boardContainer = $('#board-container');
let isDown = false;
let startX;
let scrollLeftPixels;
function attachHorizontalScrollListeners() {
var boardContainer = $('#board-container');
let isDown = false;
let startX;
let scrollLeftPixels;

boardContainer.on('mousedown', (e) => {
isDown = true;
boardContainer.addClass('horizontally-dragged');
startX = e.pageX - boardContainer.offset().left;
scrollLeftPixels = boardContainer.scrollLeft();
});
boardContainer.on('mousedown', (e) => {
isDown = true;
startX = e.pageX - boardContainer.offset().left;
scrollLeftPixels = boardContainer.scrollLeft();
});

boardContainer.on('mouseleave', () => {
isDown = false;
boardContainer.removeClass('horizontally-dragged');
});
boardContainer.on('mouseleave', (e) => {
isDown = false;
});

boardContainer.on('mouseup', () => {
isDown = false;
boardContainer.removeClass('horizontally-dragged');
});
boardContainer.on('mouseup', (e) => {
isDown = false;
});

boardContainer.on('mousemove', (e) => {
if (!isDown) return;
// This is a draggable card, we don't want to also drag the background while
// dragging a card.
if ($(e.target).parents('div.task-board.draggable-item').length != 0) return;
e.preventDefault();
const x = e.pageX - boardContainer.offset().left;
const walk = (x - startX) * 2; // Scroll speed
boardContainer.scrollLeft(scrollLeftPixels - walk);
});
}
boardContainer.on('mousemove', (e) => {
console.log("mousemove");
if (!isDown) return;
// This is a draggable card, we don't want to also drag the background while
// dragging a card.
if ($(e.target).parents('div.task-board.draggable-item').length != 0) return;
e.preventDefault();
const x = e.pageX - boardContainer.offset().left;
const walk = (x - startX) * 2; // Scroll speed
boardContainer.scrollLeft(scrollLeftPixels - walk);
});
}

if (KB.exists('#board-container')) {
attachHorizontalScrollListeners();
}
// Only attach if we're on a page that shows the board
if (KB.exists('#board-container')) {
KB.on('dom.ready', function () {
attachHorizontalScrollListeners();
});
}

// #board-container disappears after an AJAX drag/drop event, so
// we have to reattach the listeners
$(document).ajaxStop(function(){
if (KB.exists('#board-container')) {
attachHorizontalScrollListeners();
}
});

2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '0.2.2';
return '0.2.3';
}

public function getPluginHomepage()
Expand Down

0 comments on commit 47ffec7

Please sign in to comment.