mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-559: Add support for reading/writing clipboard contents using the Asynchronous Clipboard API.
This commit is contained in:
@@ -179,6 +179,23 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Attempt to read the clipboard using the Asynchronous Clipboard
|
||||||
|
// API, if it's available
|
||||||
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||||
|
if (data.type === 'text/plain') {
|
||||||
|
navigator.clipboard.writeText(data.data).then(deferred.resolve, deferred.reject);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore any hard failures to use Asynchronous Clipboard API, falling
|
||||||
|
// back to traditional document.execCommand()
|
||||||
|
catch (ignore) {}
|
||||||
|
|
||||||
// Track the originally-focused element prior to changing focus
|
// Track the originally-focused element prior to changing focus
|
||||||
var originalElement = document.activeElement;
|
var originalElement = document.activeElement;
|
||||||
pushSelection();
|
pushSelection();
|
||||||
@@ -415,6 +432,29 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Attempt to read the clipboard using the Asynchronous Clipboard
|
||||||
|
// API, if it's available
|
||||||
|
if (navigator.clipboard && navigator.clipboard.readText) {
|
||||||
|
|
||||||
|
navigator.clipboard.readText().then(function textRead(text) {
|
||||||
|
deferred.resolve(new ClipboardData({
|
||||||
|
type : 'text/plain',
|
||||||
|
data : text
|
||||||
|
}));
|
||||||
|
}, deferred.reject);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore any hard failures to use Asynchronous Clipboard API, falling
|
||||||
|
// back to traditional document.execCommand()
|
||||||
|
catch (ignore) {}
|
||||||
|
|
||||||
// Track the originally-focused element prior to changing focus
|
// Track the originally-focused element prior to changing focus
|
||||||
var originalElement = document.activeElement;
|
var originalElement = document.activeElement;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user