Fix #6814 - Notification fadeout
[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      * Writes a string to the clipboard - using the Clipboard API if https, otherwise using text area.
11      * @param {String} text to copy to clipboard
12      */
13     write : function(text) {
14         // navigator clipboard api needs a secure context (https)
15         if (navigator.clipboard && window.isSecureContext) {
16             // navigator clipboard api method'
17             navigator.clipboard.writeText(text);
18             return ;
19         } 
20         // text area method
21         var ta = document.createElement("textarea");
22         ta.value = text;
23         // make the textarea out of viewport
24         ta.style.position = "fixed";
25         ta.style.left = "-999999px";
26         ta.style.top = "-999999px";
27         document.body.appendChild(ta);
28         ta.focus();
29         ta.select();
30         document.execCommand('copy');
31         (function() {
32             ta.remove();
33         }).defer(100);
34         
35     }
36         
37 }
38