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.3KB

12345678910111213141516171819202122232425262728
  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) httpsBtn.classList[!isSSH ? 'add' : 'remove']('primary');
  14. if (sshBtn) sshBtn.classList[isSSH ? 'add' : 'remove']('primary');
  15. const btn = isSSH ? sshBtn : httpsBtn;
  16. if (!btn) return;
  17. const link = btn.getAttribute('data-link');
  18. for (const el of document.getElementsByClassName('js-clone-url')) {
  19. el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
  20. }
  21. for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
  22. el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link);
  23. }
  24. })();
  25. </script>