mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
simplified selection algorithm
This commit is contained in:
@@ -676,7 +676,7 @@ $(function () {
|
||||
var $table = $toggle.closest("table");
|
||||
var $rows = $table.find("tbody tr");
|
||||
var $checkboxes = $rows.find("td:first-child input[type=checkbox]");
|
||||
var firstIndex, lastIndex, currentIndex, selectionChecked, onChangeSelectionHappened = false;
|
||||
var firstIndex, lastIndex, selectionChecked, onChangeSelectionHappened = false;
|
||||
var updateSelection = function(a, b, checked) {
|
||||
if (a > b) {
|
||||
//[a, b] = [b, a];// ES6 not ready yet for pretix
|
||||
@@ -695,29 +695,21 @@ $(function () {
|
||||
onChangeSelectionHappened = true;
|
||||
|
||||
var row = ev.target.closest("tr");
|
||||
currentIndex = 0;
|
||||
var currentIndex = 0;
|
||||
while(row = row.previousSibling) {
|
||||
if (row.tagName) currentIndex++;
|
||||
}
|
||||
|
||||
if (currentIndex > firstIndex && currentIndex > lastIndex) {
|
||||
// special case: selection direction changed
|
||||
if (lastIndex < firstIndex) {
|
||||
// reset all selected checkboxes before setting new lastIndex
|
||||
updateSelection(lastIndex, firstIndex);
|
||||
}
|
||||
lastIndex = currentIndex;
|
||||
|
||||
} else if (currentIndex < firstIndex && currentIndex < lastIndex) {
|
||||
// special case: selection direction changed
|
||||
if (lastIndex > firstIndex) {
|
||||
// reset all selected checkboxes before setting new lastIndex
|
||||
updateSelection(firstIndex, lastIndex);
|
||||
}
|
||||
lastIndex = currentIndex;
|
||||
var dCurrent = currentIndex - firstIndex;
|
||||
var dLast = lastIndex - firstIndex;
|
||||
if (dCurrent*dLast < 0) {
|
||||
// direction of selection changed => reset all previously selected
|
||||
updateSelection(lastIndex, firstIndex);
|
||||
}
|
||||
|
||||
if (currentIndex != lastIndex) updateSelection(currentIndex, lastIndex);
|
||||
else if (Math.abs(dCurrent) < Math.abs(dLast)) {
|
||||
// selection distance decreased => reset unselected
|
||||
updateSelection(currentIndex, lastIndex);
|
||||
}
|
||||
lastIndex = currentIndex;
|
||||
updateSelection(firstIndex, currentIndex, selectionChecked);
|
||||
|
||||
ev.preventDefault();
|
||||
@@ -731,7 +723,7 @@ $(function () {
|
||||
while(row = row.previousSibling) {
|
||||
if (row.tagName) firstIndex++;
|
||||
}
|
||||
lastIndex = currentIndex = firstIndex;
|
||||
lastIndex = firstIndex;
|
||||
|
||||
ev.preventDefault();
|
||||
$rows.on("pointerenter", onChangeSelection);
|
||||
|
||||
Reference in New Issue
Block a user