[Representation] Add DnD service

Add service to communicate data after/during a drag-and-drop, to allow
drag contents to be checked during dragover, and to allow full JavaScript
objects to be passed during drags (within the same window.) WTD-988.
This commit is contained in:
Victor Woeltjen
2015-03-19 12:34:52 -07:00
parent d814c0fc18
commit 818510da14
6 changed files with 155 additions and 10 deletions

View File

@ -0,0 +1,50 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Drag-and-drop service.
* Supplements HTML5 drag-and-drop support by:
* * Storing arbitrary JavaScript objects (not just strings.)
* * Allowing inspection of dragged objects during `dragover` events,
* etc. (which cannot be done in Chrome for security reasons)
* @constructor
* @param $log Angular's $log service
*/
function DndService($log) {
var data = {};
return {
/**
* Set drag data associated with a given type.
* @param {string} key the type's identiifer
* @param {*} value the data being dragged
*/
setData: function (key, value) {
$log.debug("Setting drag data for " + key);
data[key] = value;
},
/**
* Get drag data associated with a given type.
* @returns {*} the data being dragged
*/
getData: function (key) {
return data[key];
},
/**
* Remove data associated with active drags.
* @param {string} key the type to remove
*/
removeData: function (key) {
$log.debug("Clearing drag data for " + key);
delete data[key];
}
};
}
return DndService;
}
);