You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clone_script.tmpl 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <script>
  2. // synchronously set clone button states and urls here to avoid flickering
  3. // on page load. initRepoCloneLink calls this when proto changes.
  4. // this applies the protocol-dependant clone url to all elements with the
  5. // `js-clone-url` and `js-clone-url-vsc` classes.
  6. // TODO: This localStorage setting should be moved to backend user config
  7. // so it's available during rendering, then this inline script can be removed.
  8. (window.updateCloneStates = function() {
  9. const httpsBtn = document.getElementById('repo-clone-https');
  10. const sshBtn = document.getElementById('repo-clone-ssh');
  11. const value = localStorage.getItem('repo-clone-protocol') || 'https';
  12. const isSSH = value === 'ssh' && sshBtn || value !== 'ssh' && !httpsBtn;
  13. if (httpsBtn) {
  14. httpsBtn.textContent = window.origin.split(':')[0].toUpperCase();
  15. httpsBtn.classList.toggle('primary', !isSSH);
  16. httpsBtn.classList.toggle('basic', isSSH);
  17. }
  18. if (sshBtn) {
  19. sshBtn.classList.toggle('primary', isSSH);
  20. sshBtn.classList.toggle('basic', !isSSH);
  21. }
  22. const btn = isSSH ? sshBtn : httpsBtn;
  23. if (!btn) return;
  24. let link = btn.getAttribute('data-link');
  25. if (link.startsWith('http://') || link.startsWith('https://')) {
  26. // use current protocol/host as the clone link
  27. const url = new URL(link);
  28. url.protocol = window.location.protocol;
  29. url.host = window.location.host;
  30. link = url.toString();
  31. }
  32. for (const el of document.getElementsByClassName('js-clone-url')) {
  33. el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
  34. }
  35. for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
  36. el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link);
  37. }
  38. })();
  39. </script>