Skip to content

Commit

Permalink
IBX-1318: Prevented dragging on child elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dew326 committed Jan 17, 2022
1 parent bce53cd commit ddc3af9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
selectorItem: '.ibexa-collapse--field-definition',
timeoutRemovePlaceholders: TIMEOUT_REMOVE_PLACEHOLDERS,
selectorPlaceholder: '.ibexa-field-definitions-placeholder',
selectorPreventDrag: '.ibexa-collapse__body',
});

draggable.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
(event) => {
const { nodes } = event.detail;

nodes.forEach(initField);
nodes.forEach((node) => {
if (node.querySelector(SELECTOR_OPTIONS_LIST)) {
initField(node);
}
});
},
false
);
Expand Down
14 changes: 13 additions & 1 deletion src/bundle/Resources/public/js/scripts/core/draggable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function (global, doc, ibexa) {
(function(global, doc, ibexa) {
const SELECTOR_PLACEHOLDER = '.ibexa-draggable__placeholder';
const SELECTOR_PREVENT_DRAG = '.ibexa-draggable__prevent-drag';
const TIMEOUT_REMOVE_PLACEHOLDERS = 500;

class Draggable {
Expand All @@ -10,6 +11,7 @@
this.itemsContainer = config.itemsContainer;
this.selectorItem = config.selectorItem;
this.selectorPlaceholder = config.selectorPlaceholder || SELECTOR_PLACEHOLDER;
this.selectorPreventDrag = config.selectorPreventDrag || SELECTOR_PREVENT_DRAG;
this.timeoutRemovePlaceholders = config.timeoutRemovePlaceholders || TIMEOUT_REMOVE_PLACEHOLDERS;

this.onDragStart = this.onDragStart.bind(this);
Expand All @@ -26,6 +28,16 @@
item.ondragstart = this.onDragStart;
item.ondragend = this.onDragEnd;
item.ondrag = this.removePlaceholderAfterTimeout;

const preventedNode = item.querySelector(this.selectorPreventDrag);

if (preventedNode) {
preventedNode.draggable = true;
preventedNode.ondragstart = (event) => {
event.preventDefault();
event.stopPropagation();
};
}
}

onDragStart(event) {
Expand Down

0 comments on commit ddc3af9

Please sign in to comment.