mirror of
https://github.com/nasa/openmct.git
synced 2025-04-07 11:26:49 +00:00
[Layout] Add mct-drag directive
Add an mct-drag directive to support various draggable things, including frames in a layout. WTD-535.
This commit is contained in:
parent
8956be1209
commit
479aaa09fb
@ -49,6 +49,11 @@
|
||||
"key": "mctContainer",
|
||||
"implementation": "MCTContainer.js",
|
||||
"depends": [ "containers[]" ]
|
||||
},
|
||||
{
|
||||
"key": "mctDrag",
|
||||
"implementation": "MCTDrag.js",
|
||||
"depends": [ "$document" ]
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
|
61
platform/commonUI/general/src/MCTDrag.js
Normal file
61
platform/commonUI/general/src/MCTDrag.js
Normal file
@ -0,0 +1,61 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function MCTDrag($document) {
|
||||
var body = $document.find('body');
|
||||
|
||||
function link(scope, element, attrs) {
|
||||
var initialPosition,
|
||||
currentPosition,
|
||||
delta;
|
||||
|
||||
function fireListener(name) {
|
||||
scope.$eval(attrs[name], { delta: delta });
|
||||
}
|
||||
|
||||
function updatePosition(event) {
|
||||
currentPosition = [ event.pageX, event.pageY ];
|
||||
initialPosition = initialPosition || currentPosition;
|
||||
delta = currentPosition.map(function (v, i) {
|
||||
return v - initialPosition[i];
|
||||
});
|
||||
}
|
||||
|
||||
function continueDrag(event) {
|
||||
updatePosition(event);
|
||||
fireListener("mctDrag");
|
||||
}
|
||||
|
||||
function endDrag(event) {
|
||||
body.off("mouseup", endDrag);
|
||||
body.off("mousemove", continueDrag);
|
||||
|
||||
continueDrag(event);
|
||||
|
||||
fireListener("mctDragUp");
|
||||
}
|
||||
|
||||
function startDrag(event) {
|
||||
body.on("mouseup", endDrag);
|
||||
body.on("mousemove", continueDrag);
|
||||
updatePosition(event);
|
||||
fireListener("mctDragDown");
|
||||
fireListener("mctDrag");
|
||||
}
|
||||
|
||||
element.on("mousedown", startDrag);
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: "A",
|
||||
link: link
|
||||
};
|
||||
}
|
||||
|
||||
return MCTDrag;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user