2022-09-23 04:10:26 +00:00
|
|
|
{{/*Golang's template has a bug with string interpolation containing slashes,
|
|
|
|
the double slash will be treated as a comment there.
|
|
|
|
But there are also JS lint rules for template that require to use string interpolation in 1.17*/}}
|
2022-08-02 04:31:38 +00:00
|
|
|
<script>
|
|
|
|
// synchronously set clone button states and urls here to avoid flickering
|
|
|
|
// on page load. initRepoCloneLink calls this when proto changes.
|
2022-09-20 14:01:24 +00:00
|
|
|
// this applies the protocol-dependant clone url to all elements with the
|
|
|
|
// `js-clone-url` and `js-clone-url-vsc` classes.
|
2022-08-02 04:31:38 +00:00
|
|
|
// TODO: This localStorage setting should be moved to backend user config
|
|
|
|
// so it's available during rendering, then this inline script can be removed.
|
|
|
|
(window.updateCloneStates = function() {
|
|
|
|
const httpsBtn = document.getElementById('repo-clone-https');
|
|
|
|
const sshBtn = document.getElementById('repo-clone-ssh');
|
|
|
|
const value = localStorage.getItem('repo-clone-protocol') || 'https';
|
|
|
|
const isSSH = value === 'ssh' && sshBtn || value !== 'ssh' && !httpsBtn;
|
|
|
|
|
|
|
|
if (httpsBtn) httpsBtn.classList[!isSSH ? 'add' : 'remove']('primary');
|
|
|
|
if (sshBtn) sshBtn.classList[isSSH ? 'add' : 'remove']('primary');
|
|
|
|
|
|
|
|
const btn = isSSH ? sshBtn : httpsBtn;
|
|
|
|
if (!btn) return;
|
|
|
|
|
|
|
|
const link = btn.getAttribute('data-link');
|
|
|
|
for (const el of document.getElementsByClassName('js-clone-url')) {
|
|
|
|
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
|
|
|
|
}
|
2022-09-23 04:10:26 +00:00
|
|
|
const sep = '//';
|
2022-09-20 14:01:24 +00:00
|
|
|
for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
|
2022-09-23 04:10:26 +00:00
|
|
|
el.href = `vscode:${sep}vscode.git/clone?url=${encodeURIComponent(link)}`;
|
2022-09-20 14:01:24 +00:00
|
|
|
}
|
2022-08-02 04:31:38 +00:00
|
|
|
})();
|
|
|
|
</script>
|