+

Search Tips   |   Advanced Search

Create a drag-and-drop source


We can extend the default framework for custom behaviors or we can create sources. Sources determine the behavior of drag-and-drop operations. The easiest way to create a source with customized behaviors is to extend one of the default source implementations. There are two default source implementations:

The following example extends the LayoutColumnSource and adds some custom behavior. A skeleton of the custom class would look like this code:

dojo.provide("customDndSource");
dojo.require("com.ibm.pb.dnd.layout.LayoutColumnSource");
dojo.declare("customDndSource", [com.ibm.pb.dnd.layout.LayoutColumnSource], {
 ghostClass: "someCssClass",  constructor: function() {
 },  onDndStart: function(source, nodes, copy){
  // called when a drag operation starts
 },  onDrop: function(source, nodes, copy){
  // called for a drop operation on a target  },  onDndCancel: function(){
  // called when a drag operation is canceled  },  onOverEvent: function(){
  // called when dragging over a source  },  onOutEvent: function(){
  // called when dragging out of a source  
 }
});
customDndSource.withHandles = true;

The declare method extends the implementation of LayoutColumnSource and there are stub events set up for the drag-and-drop operations:

After created the source and customize the behaviors, configure the source definitions object and apply it to the layout.


Parent: Drag-and-drop
Related:
Drag-and-drop avatars