invitation-link-behavior.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <script>
  2. 'use strict';
  3. window.Chat = window.Chat || {};
  4. Chat.InvitationLinkBehavior = {
  5. properties: {
  6. contact: {
  7. type: String
  8. }
  9. },
  10. _copy: function(e) {
  11. if (e) {
  12. e.preventDefault();
  13. e.stopPropagation();
  14. }
  15. Polymer.Base.create('textarea');
  16. var copyTextarea = this.textarea;
  17. copyTextarea.value = this.link;
  18. copyTextarea.select();
  19. try {
  20. var successful = document.execCommand('copy');
  21. if (successful) {
  22. app.displayToast('Copied invitation link to clipboard. Share it to send files to friends!');
  23. }
  24. } catch (err) {
  25. console.log('Oops, unable to copy', err);
  26. }
  27. copyTextarea.blur();
  28. },
  29. get link() {
  30. return 'http://' + window.location.host + '/' + this.contact;
  31. },
  32. get textarea() {
  33. var textarea = document.querySelector('#copytextarea');
  34. if (!textarea) {
  35. textarea = Polymer.Base.create('textarea');
  36. textarea.id = 'copytextarea';
  37. var style = textarea.style;
  38. style.position = 'absolute';
  39. style.top = '-10000px';
  40. document.body.appendChild(textarea);
  41. }
  42. return textarea;
  43. }
  44. };
  45. </script>