Drag and drop directive
The sfDragDrop is a directive that adds drag-and-drop functionality to an HTML element. Using this directive you can drag one or several files over a specified HTML element. When a drop event occurs a delegate is called. The sfDragDrop directive is defined in a module with the same name: sfDragDrop.
Attributes
The sfDragDrop directive exposes the following attributes:
| Attribute |
Description |
sf-template-html |
Passes the markup that is included at the beginning of the directive's host element |
sf-data-transfer-callback |
Passes a delegate that is called when a drop occurs. The dataTransferObject is resolved as an argument when calling the delegate. For more information, see DataTransfer Object. |
CSS classes
The sfDragDrop directive adds the following CSS classes to the HTML host element:
| CSS class |
Action |
sf-Drag-start
|
Added when dragging is in progress |
sf-Drag-over
|
Added when dragging is in progress over the element |
Add the drag and drop directive
The following example demonstrates how to add a drag-and-drop directive in a widget designer's view.
To enable AngularJs to link the sfDragDrop directive in your custom designer view, you must load the script of the directive and add a dependency to the module.
Perform the following:
- Sitefinity CMS automatically registers the scripts you need and, if no other designer view with explicitly set priority exists, Sitefinity CMS sets your designer view priority 1. In case you need to have full control over the scripts that are loaded or you want to set custom priority, you can alternatively create your own
DesignerView.YourView.json file. If you have a JSON file that matches the convention (even if empty), this automatic scripts registration will not occur. In your DesignerView.YourView.json file, add a scripts array.
Use the following code:
- In your
designerview-yourview.js file, place the following code snippet:
The code above is called when a drop event occurs. As a result, an alert displays the name of the first file that was dropped in the HTML element hosting the sfDragDrop directive.
- In your
DesignerView.YourView.cshtml file, place the following tag where you want to render the sfDragDrop directive: