1d8bca07f3
Adds `[repository].DOWNLOAD_OR_CLONE_METHODS` (defaulting to "download-zip,download-targz,download-bundle,vscode-clone"), which lets an instance administrator override the additional clone methods displayed on the repository home view. This is purely display-only, the clone methods not listed here are still available, unless disabled elsewhere. They're just not displayed. Fixes #710. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit 2aadcf4946e48ee43800568fe705d00a062c42bf) (cherry picked from commit 42ac34fbf9105eed27ee687b305a85515270f0cc) (cherry picked from commit bd231b02450212aca6be775663c3d24ddf19f990) (cherry picked from commit 3d3366dbbee37621fc665e557a4a87bf08104375) (cherry picked from commit 0157fb9b88fd50832c07b06c11c8dba6e059a465) (cherry picked from commit bee88f6a8309c6f9aeba1522383d77f08e5a4d2d)
45 lines
1.8 KiB
Go HTML Template
45 lines
1.8 KiB
Go HTML Template
<script>
|
|
// synchronously set clone button states and urls here to avoid flickering
|
|
// on page load. initRepoCloneLink calls this when proto changes.
|
|
// this applies the protocol-dependant clone url to all elements with the
|
|
// `js-clone-url` and `js-clone-url-vsc` classes.
|
|
// 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.textContent = window.origin.split(':')[0].toUpperCase();
|
|
httpsBtn.classList.toggle('primary', !isSSH);
|
|
httpsBtn.classList.toggle('basic', isSSH);
|
|
}
|
|
if (sshBtn) {
|
|
sshBtn.classList.toggle('primary', isSSH);
|
|
sshBtn.classList.toggle('basic', !isSSH);
|
|
}
|
|
|
|
const btn = isSSH ? sshBtn : httpsBtn;
|
|
if (!btn) return;
|
|
|
|
let link = btn.getAttribute('data-link');
|
|
if (link.startsWith('http://') || link.startsWith('https://')) {
|
|
// use current protocol/host as the clone link
|
|
const url = new URL(link);
|
|
url.protocol = window.location.protocol;
|
|
url.host = window.location.host;
|
|
link = url.toString();
|
|
}
|
|
for (const el of document.getElementsByClassName('js-clone-url')) {
|
|
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
|
|
}
|
|
for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
|
|
el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link);
|
|
}
|
|
for (const el of document.getElementsByClassName('js-clone-url-vscodium')) {
|
|
el['href'] = 'vscodium://vscode.git/clone?url=' + encodeURIComponent(link);
|
|
}
|
|
})();
|
|
</script>
|