GUACAMOLE-310: Use input element select() function when available.

This commit is contained in:
Michael Jumper
2017-09-03 17:07:24 -07:00
parent 47acaf5b41
commit 7e0cdd2adf

View File

@@ -135,6 +135,13 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
*/ */
var selectAll = function selectAll(element) { var selectAll = function selectAll(element) {
// Use the select() function defined for input elements, if available
if (element.select)
element.select();
// Fallback to manual manipulation of the selection
else {
// Generate a range which selects all nodes within the given element // Generate a range which selects all nodes within the given element
var range = document.createRange(); var range = document.createRange();
range.selectNodeContents(element); range.selectNodeContents(element);
@@ -144,6 +151,8 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
selection.removeAllRanges(); selection.removeAllRanges();
selection.addRange(range); selection.addRange(range);
}
}; };
/** /**
@@ -175,6 +184,7 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
} }
// Select all data within the clipboard target // Select all data within the clipboard target
clipboardContent.focus();
selectAll(clipboardContent); selectAll(clipboardContent);
// Attempt to copy data from clipboard element into local clipboard // Attempt to copy data from clipboard element into local clipboard