UIWindowRefer.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import UIWindow from './UIWindow.js'
  20. import UIPopover from './UIPopover.js'
  21. async function UIWindowRefer(options){
  22. let h = '';
  23. let copy_btn_text = 'Copy Link';
  24. let copied_btn_text = 'Copied!';
  25. const url = `${gui_origin}/?r=${user.referral_code}`;
  26. h += `<div>`;
  27. h += `<div class="qr-code-window-close-btn generic-close-window-button disable-user-select"> &times; </div>`;
  28. h += `<img src="${window.icons['present.svg']}" style="width: 70px; margin: 20px auto 20px; display: block; margin-bottom: 20px;">`;
  29. h += `<p style="text-align: center; font-size: 16px; padding: 20px; font-weight: 400; margin: -10px 10px 20px 10px; -webkit-font-smoothing: antialiased; color: #5f626d;">Get 1 GB for every friend who creates and confirms an account on Puter. Your friend will get 1 GB too!</p>`;
  30. h += `<label style="font-weight: bold;">Invite link</label>`;
  31. h += `<input type="text" style="margin-bottom:10px;" class="downloadable-link" readonly />`;
  32. h += `<button class="button button-primary copy-downloadable-link" style="width:130px;">${copy_btn_text}</button>`
  33. h += `<img class="share-copy-link-on-social" src="${window.icons['share-outline.svg']}">`;
  34. h += `</div>`;
  35. const el_window = await UIWindow({
  36. title: `Refer a friend!`,
  37. icon: null,
  38. uid: null,
  39. is_dir: false,
  40. body_content: h,
  41. has_head: false,
  42. selectable_body: false,
  43. draggable_body: true,
  44. allow_context_menu: false,
  45. is_draggable: true,
  46. is_resizable: false,
  47. is_droppable: false,
  48. init_center: true,
  49. allow_native_ctxmenu: true,
  50. allow_user_select: true,
  51. onAppend: function(el_window){
  52. },
  53. width: 500,
  54. dominant: true,
  55. window_css: {
  56. height: 'initial',
  57. },
  58. body_css: {
  59. width: 'initial',
  60. 'max-height': 'calc(100vh - 200px)',
  61. 'background-color': 'rgb(241 246 251)',
  62. 'backdrop-filter': 'blur(3px)',
  63. 'padding': '10px 20px 20px 20px',
  64. 'height': 'initial',
  65. }
  66. });
  67. $(el_window).find('.window-body .downloadable-link').val(url);
  68. $(el_window).find('.window-body .share-copy-link-on-social').on('click', function(e){
  69. const social_links = socialLink({url: url, title: `Get 1 GB of free storage on Puter.com!`, description: `Get 1 GB of free storage on Puter.com!`});
  70. let social_links_html = ``;
  71. social_links_html += `<div style="padding: 10px;">`;
  72. social_links_html += `<p style="margin: 0; text-align: center; margin-bottom: 6px; color: #484a57; font-weight: bold; font-size: 14px;">Share to</p>`
  73. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links.twitter}" style=""><svg viewBox="0 0 24 24" aria-hidden="true" style="opacity: 0.7;"><g><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path></g></svg></a>`
  74. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links.whatsapp}" style=""><img src="${window.icons['logo-whatsapp.svg']}"></a>`
  75. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links.facebook}" style=""><img src="${window.icons['logo-facebook.svg']}"></a>`
  76. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links.linkedin}" style=""><img src="${window.icons['logo-linkedin.svg']}"></a>`
  77. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links.reddit}" style=""><img src="${window.icons['logo-reddit.svg']}"></a>`
  78. social_links_html += `<a class="copy-link-social-btn" target="_blank" href="${social_links['telegram.me']}" style=""><img src="${window.icons['logo-telegram.svg']}"></a>`
  79. social_links_html += '</div>';
  80. UIPopover({
  81. content: social_links_html,
  82. snapToElement: this,
  83. parent_element: this,
  84. // width: 300,
  85. height: 100,
  86. position: 'bottom',
  87. });
  88. })
  89. $(el_window).find('.window-body .copy-downloadable-link').on('click', async function(e){
  90. var copy_btn = this;
  91. if (navigator.clipboard) {
  92. // Get link text
  93. const selected_text = $(el_window).find('.window-body .downloadable-link').val();
  94. // copy selected text to clipboard
  95. await navigator.clipboard.writeText(selected_text);
  96. }
  97. else{
  98. // Get the text field
  99. $(el_window).find('.window-body .downloadable-link').select();
  100. // Copy the text inside the text field
  101. document.execCommand('copy');
  102. }
  103. $(this).html(copied_btn_text);
  104. setTimeout(function(){
  105. $(copy_btn).html(copy_btn_text);
  106. }, 1000);
  107. });
  108. }
  109. export default UIWindowRefer