Utilities for interacting with the HTML5 drag/drop APIs.
Methods
-
<static> fromClipboard(clipboard)
-
Read data previously written to the clipboard by a call to
toClipboard
.Parameters:
Name Type Description clipboard
DataTransfer Returns:
promise to be resolved with an
Envelope
instance- Type
- Promise
Example
$('.dropTarget').on('drop', function (e) { dragDropUtils.fromClipboard(e.originalEvent.dataTransfer) .then(function (envelope) { envelope.toValues().then(function (values) { values.forEach(handleValue); }); }); });
-
<static> toClipboard(clipboard, mimeType [, values])
-
Add the given data onto the clipboard.
Parameters:
Name Type Argument Description clipboard
DataTransfer the
DataTransfer
on which to set the datamimeType
String | module:bajaux/dragdrop/Envelope a supported Niagara mime type for the given data, in which case the given
values will be converted to anEnvelope
instance; or anEnvelope
instance directlyvalues
Array <optional>
if a mime type given, the values to convert to an
Envelope
instanceReturns:
promise to be resolved when the
Envelope
instance has been created or received, and has written JSON data onto the
clipboard- Type
- Promise
Example
$('.dragSource').on('dragstart', function (e) { var dataTransfer = e.originalEvent.dataTransfer; dragDropUtils.toClipboard(dataTransfer, 'niagara/strings', [ 'hello', 'world' ]) .then(function () { console.log('clipboard populated with: ' + dataTransfer.getData('Text')); }); });