123456789101112131415161718192021222324252627282930313233343536 |
- <script>
- 'use strict';
- (function(document) {
- var copyTextarea = document.createElement('textarea');
- copyTextarea.setAttribute('id', 'clipboard-textarea');
- var style = copyTextarea.style;
- style.position = 'absolute';
- style.top = '-10000px';
- document.body.appendChild(copyTextarea);
- window.Chat.ClipboardBehavior = {
- copyToClipboard: function(content) {
- copyTextarea.value = content;
- var range = document.createRange();
- range.selectNode(copyTextarea);
- window.getSelection().addRange(range);
- try {
- // Now that we've selected the anchor text, execute the copy command
- var successful = document.execCommand('copy');
- if (successful) {
- app.displayToast('Copied text to clipboard. Paste it where you want!');
- } else {
- console.log('failed to copy to clipboard', successful);
- }
- } catch (err) {
- console.log('Oops, unable to copy', err);
- }
- // Remove the selections - NOTE: Should use
- // removeRange(range) when it is supported
- window.getSelection().removeAllRanges();
- }
- };
- }(document));
- </script>
|