Merge branch 'open988' into open-master

This commit is contained in:
Victor Woeltjen
2015-03-25 16:57:05 -07:00
7 changed files with 177 additions and 10 deletions

View File

@ -19,7 +19,7 @@ define(
* @param {DomainObject} domainObject the domain object which
* is represented; this will be passed on drop.
*/
function DragGesture($log, element, domainObject) {
function DragGesture($log, dndService, element, domainObject) {
function startDrag(e) {
var event = (e || {}).originalEvent || e;
@ -45,6 +45,19 @@ define(
domainObject.getId()
);
// Finally, also pass the id object instance via the
// dndService, allowing inspection during drag as well
// as retrieval of the original domain object.
dndService.setData(
GestureConstants.MCT_EXTENDED_DRAG_TYPE,
domainObject
);
dndService.setData(
GestureConstants.MCT_DRAG_TYPE,
domainObject.getId()
);
} catch (err) {
// Exceptions at this point indicate that the browser
// do not fully support drag-and-drop (e.g. if
@ -57,10 +70,17 @@ define(
}
function endDrag() {
// Clear the drag data after the drag is complete
dndService.removeData(GestureConstants.MCT_DRAG_TYPE);
dndService.removeData(GestureConstants.MCT_EXTENDED_DRAG_TYPE);
}
// Mark the element as draggable, and handle the dragstart event
$log.debug("Attaching drag gesture");
element.attr('draggable', 'true');
element.on('dragstart', startDrag);
element.on('dragend', endDrag);
return {
/**

View File

@ -10,6 +10,12 @@ define({
* calls.)
*/
MCT_DRAG_TYPE: 'mct-domain-object-id',
/**
* The string identifier for the data type used for drag-and-drop
* composition of domain objects, by object instance (passed through
* the dndService)
*/
MCT_EXTENDED_DRAG_TYPE: 'mct-domain-object',
/**
* An estimate for the dimensions of a context menu, used for
* positioning.

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;
}
);