GUACAMOLE-724: Add per-tile visual indication of drag/drop.

This commit is contained in:
Michael Jumper
2021-06-28 11:51:09 -07:00
parent 68e856987e
commit 6b296374d5
3 changed files with 64 additions and 17 deletions

View File

@@ -534,25 +534,61 @@ angular.module('client').directive('guacClient', [function guacClient() {
});
/**
* Ignores the given event.
* Whether a drag/drop operation is currently in progress (the user has
* dragged a file over the Guacamole connection but has not yet
* dropped it).
*
* @param {Event} e The event to ignore.
* @type boolean
*/
function ignoreEvent(e) {
e.preventDefault();
e.stopPropagation();
}
$scope.dropPending = false;
// Handle and ignore dragenter/dragover
displayContainer.addEventListener("dragenter", ignoreEvent, false);
displayContainer.addEventListener("dragover", ignoreEvent, false);
// File drop event handler
displayContainer.addEventListener("drop", function(e) {
/**
* Displays a visual indication that dropping the file currently
* being dragged is possible. Further propogation and default behavior
* of the given event is automatically prevented.
*
* @param {Event} e
* The event related to the in-progress drag/drop operation.
*/
var notifyDragStart = function notifyDragStart(e) {
e.preventDefault();
e.stopPropagation();
$scope.$apply(() => {
$scope.dropPending = true;
});
};
/**
* Removes the visual indication that dropping the file currently
* being dragged is possible. Further propogation and default behavior
* of the given event is automatically prevented.
*
* @param {Event} e
* The event related to the end of the former drag/drop operation.
*/
var notifyDragEnd = function notifyDragEnd(e) {
e.preventDefault();
e.stopPropagation();
$scope.$apply(() => {
$scope.dropPending = false;
});
};
main.addEventListener('dragenter', notifyDragStart, false);
main.addEventListener('dragover', notifyDragStart, false);
main.addEventListener('dragleave', notifyDragEnd, false);
// File drop event handler
main.addEventListener('drop', function(e) {
notifyDragEnd(e);
// Ignore file drops if no attached client
if (!$scope.client)
return;

View File

@@ -127,3 +127,11 @@ body.client {
padding-left: 2.5em;
background-image: url('images/x.svg');
}
.client .drop-pending .display {
background: #3161a9;
}
.client .drop-pending .display > *{
opacity: 0.5;
}

View File

@@ -1,5 +1,8 @@
<div class="main" guac-resize="mainElementResized"
guac-touch-drag="clientDrag" guac-touch-pinch="clientPinch">
<div class="main"
ng-class="{ 'drop-pending': dropPending }"
guac-resize="mainElementResized"
guac-touch-drag="clientDrag"
guac-touch-pinch="clientPinch">
<!-- Display -->
<div class="displayOuter">