GUACAMOLE-55: Prevent clipboard events generated by the clipboardService from disturbing the operations of the guacClipboard directive.

This commit is contained in:
Michael Jumper
2016-06-28 14:00:53 -07:00
parent ea5ee1825b
commit 16637b0732
2 changed files with 19 additions and 3 deletions

View File

@@ -288,9 +288,9 @@ angular.module('clipboard').directive('guacClipboard', ['$injector',
};
// Attempt to read the clipboard if it may have changed
$window.addEventListener('copy', checkClipboard, true);
$window.addEventListener('cut', checkClipboard, true);
$window.addEventListener('focus', checkClipboard, true);
$window.addEventListener('copy', checkClipboard);
$window.addEventListener('cut', checkClipboard);
$window.addEventListener('focus', checkClipboard);
// Clean up on destruction
$scope.$on('$destroy', function destroyClipboard() {

View File

@@ -54,6 +54,22 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
// Add clipboard target to DOM
document.body.appendChild(clipboardContent);
/**
* Stops the propogation of the given event through the DOM tree. This is
* identical to invoking stopPropogation() on the event directly, except
* that this function is usable as an event handler itself.
*
* @param {Event} e
* The event whose propogation through the DOM tree should be stopped.
*/
var stopEventPropagation = function stopEventPropagation(e) {
e.stopPropagation();
};
// Prevent events generated due to execCommand() from disturbing external things
clipboardContent.addEventListener('copy', stopEventPropagation);
clipboardContent.addEventListener('paste', stopEventPropagation);
/**
* A stack of past node selection ranges. A range convering the nodes
* currently selected within the document can be pushed onto this stack