Use input element select() function when available.
@@ -135,6 +135,13 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
*/
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
var range = document.createRange();
range.selectNodeContents(element);
@@ -144,6 +151,8 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
selection.removeAllRanges();
selection.addRange(range);
+ }
+
};
/**
@@ -175,6 +184,7 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
}
// Select all data within the clipboard target
+ clipboardContent.focus();
selectAll(clipboardContent);
// Attempt to copy data from clipboard element into local clipboard
