Skip to content

Commit

Permalink
rearrangeChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Jun 21, 2021
1 parent c87b04a commit 9d8db69
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@
$parentsStr = '';
}
?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>" item-id="<?php echo $item->id ?>" parents="<?php echo $parentsStr ?>" level="<?php echo $item->level ?>">
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>"
data-item-id="<?php echo $item->id ?>" data-parents="<?php echo $parentsStr ?>"
data-level="<?php echo $item->level ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/tmpl/items/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
}
?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>"
item-id="<?php echo $item->id; ?>" parents="<?php echo $parentsStr; ?>"
level="<?php echo $item->level; ?>">
data-item-id="<?php echo $item->id; ?>" data-parents="<?php echo $parentsStr; ?>"
data-level="<?php echo $item->level; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
Expand Down
4 changes: 3 additions & 1 deletion administrator/components/com_tags/tmpl/tags/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@
$parentsStr = '';
}
?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>" item-id="<?php echo $item->id; ?>" parents="<?php echo $parentsStr; ?>" level="<?php echo $item->level; ?>">
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>"
data-item-id="<?php echo $item->id; ?>" data-parents="<?php echo $parentsStr; ?>"
data-level="<?php echo $item->level; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
Expand Down
16 changes: 16 additions & 0 deletions build/media_source/system/js/draggable.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,29 @@ if (container) {
}
}

// Update positions for a children of the moved item
rearrangeChildren(el);

// Reset data order attribute for initial ordering
const elements = container.querySelectorAll('[name="order[]"]');
for (let i = 0, l = elements.length; l > i; i += 1) {
elements[i].dataset.order = i + 1;
}
};

const rearrangeChildren = ($parent) => {
if (!$parent.dataset.itemId) {
return;
}
const parentId = $parent.dataset.itemId;
// Get children list. Each child row should have an attribute data-parents=" 1 2 3" where the number is id of parent
const $children = container.querySelectorAll(`tr[data-parents~="${parentId}"]`);

if ($children.length) {
$parent.after(...$children);
}
};

// eslint-disable-next-line no-undef
dragula([container], {
// Y axis is considered when determining where an element would be dropped
Expand Down

0 comments on commit 9d8db69

Please sign in to comment.