Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent clone protocol button flash on page load #13626

Merged
merged 3 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions templates/repo/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@
{{if eq $n 0}}
<div class="ui action tiny input" id="clone-panel">
{{if not $.DisableHTTP}}
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
<button class="ui basic clone button no-transition" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
</button>
{{end}}
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.CloneLink.SSH}}">
<button class="ui basic clone button no-transition" id="repo-clone-ssh" data-link="{{.CloneLink.SSH}}">
SSH
</button>
{{end}}
Expand All @@ -125,6 +125,19 @@
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
<input id="repo-clone-url" value="{{$.CloneLink.SSH}}" readonly>
{{end}}
<script defer>
const isSSH = localStorage.getItem('repo-clone-protocol') === 'ssh';
const sshButton = document.getElementById('repo-clone-ssh');
const httpsButton = document.getElementById('repo-clone-https');
const input = document.getElementById('repo-clone-url');
if (input) input.value = (isSSH ? sshButton : httpsButton).dataset.link;
if (sshButton) sshButton.classList[isSSH ? 'add' : 'remove']('primary');
if (httpsButton) httpsButton.classList[isSSH ? 'remove' : 'add']('primary');
setTimeout(() => {
if (sshButton) sshButton.classList.remove('no-transition');
if (httpsButto) httpsButton.classList.remove('no-transition');
}, 100);
</script>
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
{{svg "octicon-clippy"}}
Expand Down
24 changes: 4 additions & 20 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,16 +1138,16 @@ async function initRepository() {
$('#repo-clone-ssh').on('click', function () {
$('.clone-url').text($(this).data('link'));
$('#repo-clone-url').val($(this).data('link'));
$(this).addClass('blue');
$('#repo-clone-https').removeClass('blue');
$(this).addClass('primary');
$('#repo-clone-https').removeClass('primary');
localStorage.setItem('repo-clone-protocol', 'ssh');
});
$('#repo-clone-https').on('click', function () {
$('.clone-url').text($(this).data('link'));
$('#repo-clone-url').val($(this).data('link'));
$(this).addClass('blue');
$(this).addClass('primary');
if ($('#repo-clone-ssh').length > 0) {
$('#repo-clone-ssh').removeClass('blue');
$('#repo-clone-ssh').removeClass('primary');
localStorage.setItem('repo-clone-protocol', 'https');
}
});
Expand Down Expand Up @@ -2520,22 +2520,6 @@ $(document).ready(async () => {
initTableSort();
initNotificationsTable();

// Repo clone url.
if ($('#repo-clone-url').length > 0) {
switch (localStorage.getItem('repo-clone-protocol')) {
case 'ssh':
if ($('#repo-clone-ssh').length > 0) {
$('#repo-clone-ssh').trigger('click');
} else {
$('#repo-clone-https').trigger('click');
}
break;
default:
$('#repo-clone-https').trigger('click');
break;
}
}

const routes = {
'div.user.settings': initUserSettings,
'div.repository.settings.collaboration': initRepositoryCollaboration
Expand Down
2 changes: 2 additions & 0 deletions web_src/less/helpers.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
.rounded-left { border-radius: var(--border-radius) 0 0 var(--border-radius) !important; }
.rounded-right { border-radius: 0 var(--border-radius) var(--border-radius) 0 !important; }

.no-transition { transition: none !important; }

.bg-red { background: var(--color-red) !important; }
.bg-orange { background: var(--color-orange) !important; }
.bg-yellow { background: var(--color-yellow) !important; }
Expand Down