PairDrop/app/elements/invitation-link/invitation-link-behavior.html

46 lines
1.3 KiB
HTML
Raw Normal View History

<script>
'use strict';
window.Chat = window.Chat || {};
Chat.InvitationLinkBehavior = {
properties: {
contact: {
type: String
}
},
_copy: function(e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
Polymer.Base.create('textarea');
var copyTextarea = this.textarea;
copyTextarea.value = this.link;
copyTextarea.select();
try {
var successful = document.execCommand('copy');
if (successful) {
app.displayToast('Copied invitation link to clipboard. Share it to send files to friends!');
}
} catch (err) {
console.log('Oops, unable to copy', err);
}
copyTextarea.blur();
},
get link() {
return 'http://' + window.location.host + '/' + this.contact;
},
get textarea() {
var textarea = document.querySelector('#copytextarea');
if (!textarea) {
textarea = Polymer.Base.create('textarea');
textarea.id = 'copytextarea';
var style = textarea.style;
style.position = 'absolute';
style.top = '-10000px';
document.body.appendChild(textarea);
}
return textarea;
}
};
</script>