92aef21a6026f63a3152c5f7d247fd37795f7886
[roojs1] / Roo / util / Clipboard.js
1 /**
2  * @class Roo.util.Clipboard
3  * @static
4  * 
5  * Clipboard UTILS
6  * 
7  **/
8 Roo.util.Clipboard = {
9     
10     copy : function(textToCopy) {
11         // navigator clipboard api needs a secure context (https)
12         if (navigator.clipboard && window.isSecureContext) {
13             // navigator clipboard api method'
14             navigator.clipboard.writeText(textToCopy);
15             return ;
16         } 
17         // text area method
18         var ta = document.createElement("textarea");
19         ta.value = textToCopy;
20         // make the textarea out of viewport
21         ta.style.position = "fixed";
22         ta.style.left = "-999999px";
23         ta.style.top = "-999999px";
24         document.body.appendChild(ta);
25         ta.focus();
26         ta.select();
27         document.execCommand('copy');
28         (function() {
29             ta.remove();
30         }).defer(100);
31         
32     }
33         
34 }
35