-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reattach event listeners after #board-container is lost
- Loading branch information
Showing
2 changed files
with
43 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters