Skip to content

Commit

Permalink
feat(dragdrop): restored dragdrop target behaviour
Browse files Browse the repository at this point in the history
- it's now again added always
  • Loading branch information
vandres committed Dec 9, 2024
1 parent 7162ead commit 1f7f0b9
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions static/src/js/matrixExtended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,53 +147,46 @@
}

const $fields = $('.matrix-field');
const $blocks = $fields.find('.matrixblock');

$('.matrix-extended-drop-target').remove();
this.itemDrag.removeAllItems();
for (const block of $blocks) {
const $block = $(block);

for (const field of $fields) {
const $field = $(field);
const $blocks = $field.find('.matrixblock');
let $entryTypeId = null;
const entry = $block.data('entry');
if (!entry) {
return;
}
const matrix = entry.matrix;
if (!matrix) {
return;
}

for (const block of $blocks) {
const $block = $(block);
$entryTypeId = matrix.settings.fieldId;

let $entryTypeId = null;
const entry = $block.data('entry');
if (!entry) {
return;
}
const matrix = entry.matrix;
if (!matrix) {
return;
}
const $dropTargetBefore = $(`<div class="matrix-extended-drop-target" data-position="block"><div></div></div>`);
$dropTargetBefore.data($block.data());
$dropTargetBefore.data('entryTypeId', $entryTypeId);
$block.before($dropTargetBefore);
}

$entryTypeId = matrix.settings.fieldId;
const $buttons = $fields.find('> .buttons');
for (const button of $buttons) {
const $button = $(button);

const $dropTargetBefore = $(`<div class="matrix-extended-drop-target" data-position="block"><div></div></div>`);
$dropTargetBefore.data($block.data());
$dropTargetBefore.data('entryTypeId', $entryTypeId);
$block.before($dropTargetBefore);
const matrix = $button.closest('.matrix-field').data('matrix');
if (!matrix) {
continue;
}

if ($blocks.length) {
this.itemDrag.addItems($blocks);

const $buttons = $field.find('> .buttons');
for (const button of $buttons) {
const $button = $(button);
const matrix = $field.closest('.matrix-field').data('matrix');
if (!matrix) {
continue;
}

const $dropTargetButton = $(`<div class="matrix-extended-drop-target" data-position="button"><div></div></div>`);
$dropTargetButton.data('entryTypeId', matrix.settings.fieldId);
$dropTargetButton.insertBefore($button);
}
}
const $dropTargetButton = $(`<div class="matrix-extended-drop-target" data-position="button"><div></div></div>`);
$dropTargetButton.data('entryTypeId', matrix.settings.fieldId);
$dropTargetButton.insertBefore($button);
}

this.itemDrag.removeAllItems();
this.itemDrag.addItems($blocks);
Garnish.$bod.addClass('matrix-extended-drag-drop');
},

Expand Down

0 comments on commit 1f7f0b9

Please sign in to comment.