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