bajaux/dragdrop/dragDropUtils

Utilities for interacting with the HTML5 drag/drop APIs.

Description:
  • Utilities for interacting with the HTML5 drag/drop APIs.

Source:

Methods

(static) fromClipboard(clipboard) → {Promise}

Description:
  • Read data previously written to the clipboard by a call to toClipboard.

Source:
Example
$('.dropTarget').on('drop', function (e) {
    dragDropUtils.fromClipboard(e.originalEvent.dataTransfer)
      .then(function (envelope) {
        envelope.toValues().then(function (values) {
          values.forEach(handleValue);
        });
      });
  });
Parameters:
Name Type Description
clipboard DataTransfer
Returns:

promise to be resolved with an Envelope
instance

Type
Promise

(static) toClipboard(clipboard, mimeType, valuesopt) → {Promise}

Description:
  • Add the given data onto the clipboard.

Source:
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'));
      });
  });
Parameters:
Name Type Attributes Description
clipboard DataTransfer

the DataTransfer on which to set the data

mimeType String | module:bajaux/dragdrop/Envelope

a supported Niagara mime type for the given data, in which case the given
values will be converted to an Envelope instance; or an Envelope
instance directly

values Array <optional>

if a mime type given, the values to convert to an
Envelope instance

Returns:

promise to be resolved when the Envelope
instance has been created or received, and has written JSON data onto the
clipboard

Type
Promise