Fix drag and drop on Chrome

This commit is contained in:
Andrio Celos
2023-09-01 09:48:55 +10:00
parent 12ca54db39
commit 61fe24f858
2 changed files with 8 additions and 12 deletions

View File

@@ -174,8 +174,7 @@ function createDeckEditCardButton(cardNumber: number) {
function deckEditCardButton_dragover(e: DragEvent) {
e.preventDefault();
if (e.dataTransfer == null) return;
const indexString = e.dataTransfer.getData('application/tableturf-card-index');
if (indexString != '' && draggingCardButton != null) {
if (draggingCardButton != null) {
e.dataTransfer.dropEffect = 'move';
if (e.currentTarget != draggingCardButton && e.currentTarget != deckCardListEdit) {
// Move the card being dragged into the new position as a preview.
@@ -194,15 +193,14 @@ function deckEditCardButton_dragover(e: DragEvent) {
function deckEditCardButton_drop(e: DragEvent) {
e.preventDefault();
if (e.dataTransfer == null) return;
const indexString = e.dataTransfer.getData('application/tableturf-card-index');
if (indexString) {
const index = parseInt(indexString);
if (draggingCardButton != null) {
const index = deckEditCardButtons.entries.findIndex(el => el.button.buttonElement == draggingCardButton);
let newIndex = 0;
for (let el = deckCardListEdit.firstElementChild; el != null; el = el.nextElementSibling) {
if (el == draggingCardButton) break;
newIndex++;
}
if (newIndex == index) return;
if (index < 0 || newIndex == index) return;
console.log(`Moving card ${index} to ${newIndex}.`);
deckEditCardButtons.move(index, newIndex);

View File

@@ -152,8 +152,7 @@ function createDeckButton(deck: Deck) {
function deckButton_dragover(e: DragEvent) {
e.preventDefault();
if (e.dataTransfer == null) return;
const indexString = e.dataTransfer.getData('application/tableturf-deck-index');
if (indexString != '' && draggingDeckButton != null) {
if (draggingDeckButton != null) {
e.dataTransfer.dropEffect = 'move';
if (e.currentTarget != draggingDeckButton && e.currentTarget != deckList) {
// Move the deck being dragged into the new position as a preview.
@@ -172,15 +171,14 @@ function deckButton_dragover(e: DragEvent) {
function deckButton_drop(e: DragEvent) {
e.preventDefault();
if (e.dataTransfer == null) return;
const indexString = e.dataTransfer.getData('application/tableturf-deck-index');
if (indexString) {
const index = parseInt(indexString);
if (draggingDeckButton != null) {
const index = deckButtons.entries.findIndex(el => el.button.buttonElement == draggingDeckButton);
let newIndex = 0;
for (let el = deckList.firstElementChild; el != null; el = el.nextElementSibling) {
if (el == draggingDeckButton) break;
newIndex++;
}
if (newIndex == index) return;
if (index < 0 || newIndex == index) return;
console.log(`Moving deck ${index} to ${newIndex}.`);
deckButtons.move(index, newIndex);