Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const wallClass = 'CollidableWall';
const walls = document.querySelectorAll(`.${wallClass}`);
if (containers.length === 0) {
return false;
}
const droppable = new Droppable(containers, {
draggable: '.Block--isDraggable',
dropzone: '.BlockWrapper--isDropzone',
collidables: '.CollidableObstacle',
mirror: {
appendTo: containerSelector,
constrainDimensions: true,
},
plugins: [Plugins.Collidable],
});
// --- Draggable events --- //
droppable.on('collidable:in', ({collidingElement}) => {
if (collidingElement.classList.contains(wallClass)) {
walls.forEach((wall) => wall.classList.add('isColliding'));
} else {
collidingElement.classList.add('isColliding');
}
});
droppable.on('collidable:out', ({collidingElement}) => {
if (collidingElement.classList.contains(wallClass)) {
walls.forEach((wall) => wall.classList.remove('isColliding'));
} else {
collidingElement.classList.remove('isColliding');