mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-11 07:27:42 +00:00
GUACAMOLE-55: Only the guacClipboard directive should fire guacClipboard events.
This commit is contained in:
@@ -24,8 +24,7 @@ angular.module('client').factory('clipboardService', ['$injector',
|
||||
function clipboardService($injector) {
|
||||
|
||||
// Get required services
|
||||
var $q = $injector.get('$q');
|
||||
var $rootScope = $injector.get('$rootScope');
|
||||
var $q = $injector.get('$q');
|
||||
|
||||
var service = {};
|
||||
|
||||
@@ -44,14 +43,6 @@ angular.module('client').factory('clipboardService', ['$injector',
|
||||
*/
|
||||
var clipboardContent = document.createElement('textarea');
|
||||
|
||||
/**
|
||||
* The contents of the last clipboard event broadcast by this service when
|
||||
* the clipboard contents changed.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
var lastClipboardEvent = '';
|
||||
|
||||
// Ensure textarea is selectable but not visible
|
||||
clipElement.appendChild(clipboardContent);
|
||||
clipElement.style.position = 'absolute';
|
||||
@@ -129,34 +120,6 @@ angular.module('client').factory('clipboardService', ['$injector',
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the clipboard data has changed, firing a new
|
||||
* "guacClipboard" event if it has.
|
||||
*/
|
||||
var checkClipboard = function checkClipboard() {
|
||||
service.getLocalClipboard().then(function clipboardRead(data) {
|
||||
|
||||
// Fire clipboard event if the data has changed
|
||||
if (data !== lastClipboardEvent) {
|
||||
$rootScope.$broadcast('guacClipboard', 'text/plain', data);
|
||||
lastClipboardEvent = data;
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// Attempt to read the clipboard if it may have changed
|
||||
window.addEventListener('load', checkClipboard, true);
|
||||
window.addEventListener('copy', checkClipboard, true);
|
||||
window.addEventListener('cut', checkClipboard, true);
|
||||
window.addEventListener('focus', function focusGained(e) {
|
||||
|
||||
// Only recheck clipboard if it's the window itself that gained focus
|
||||
if (e.target === window)
|
||||
checkClipboard();
|
||||
|
||||
}, true);
|
||||
|
||||
return service;
|
||||
|
||||
}]);
|
||||
|
Reference in New Issue
Block a user