Drag & Drop

dizmoViewer supports drag and drop. If a dizmo is moved across the viewer, dragStart and dragEnd Events are generated. Your dizmo can listen and react to those.

dizmo.onDragStart(function() {
// the dizmo has started to be dragged by the user
});

dizmo.onDragEnd(function() {
// the dizmo has stopped being dragged by the user
});

Note: While the onDragEnd is called directly when the drag ends, the dizmo could still be moving over the screen (e.g when flicked). If you want to check for a new parent after the user has dragged the dizmo, you’ll want to subscribe to onParentChanged instead, as the parent will only be updated after the dizmo has stopped moving.

dizmo.onParentChanged(function(){
// check the new position of the dizmo
});

What if you want to limit which other dizmo your dizmo can be dragged to and undo the dragging if it was not the correct one?

First, save the current absolute position of the dizmo when the drag operation starts

Then, when the dizmo has a new parent, check if it’s not the workspace and then, if the bundleid attribute of the parent dizmo is the Pad. If not, set the Parent of the dizmo to the workspace and then move it back to the original position.