mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-26 01:36:18 -04:00
Feature Request: Send text instead of files
This commit is contained in:
parent
ce61dc7c60
commit
0e008a5f31
9 changed files with 288 additions and 111 deletions
36
app/elements/text-sharing/clipboard-behavior.html
Normal file
36
app/elements/text-sharing/clipboard-behavior.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<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>
|
Loading…
Add table
Add a link
Reference in a new issue