Skip to content

Commit 9a4050f

Browse files
Consolidate clone button templates (#14023)
The four clone button templates are pretty much identical except the one in a non-empty repo had a few features which the others lacked. Consolidate them in a single shared template which also makes the JS that remembers protocol work on them all. Co-authored-by: techknowlogick <[email protected]>
1 parent 366ce66 commit 9a4050f

File tree

5 files changed

+40
-95
lines changed

5 files changed

+40
-95
lines changed

templates/repo/clone_buttons.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{if not $.DisableHTTP}}
2+
<button class="ui basic clone button no-transition" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
3+
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
4+
</button>
5+
{{end}}
6+
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
7+
<button class="ui basic clone button no-transition" id="repo-clone-ssh" data-link="{{.CloneLink.SSH}}">
8+
SSH
9+
</button>
10+
{{end}}
11+
{{if not $.DisableHTTP}}
12+
<input id="repo-clone-url" value="{{$.CloneLink.HTTPS}}" readonly>
13+
{{else if and (not .DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
14+
<input id="repo-clone-url" value="{{$.CloneLink.SSH}}" readonly>
15+
{{end}}
16+
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
17+
<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">
18+
{{svg "octicon-clippy"}}
19+
</button>
20+
{{end}}
21+
{{if not (and $.DisableHTTP $.DisableSSH)}}
22+
<script defer>
23+
const isSSH = localStorage.getItem('repo-clone-protocol') === 'ssh';
24+
const sshButton = document.getElementById('repo-clone-ssh');
25+
const httpsButton = document.getElementById('repo-clone-https');
26+
const input = document.getElementById('repo-clone-url');
27+
if (input) input.value = (isSSH ? sshButton : httpsButton).dataset.link;
28+
if (sshButton) sshButton.classList[isSSH ? 'add' : 'remove']('primary');
29+
if (httpsButton) httpsButton.classList[isSSH ? 'remove' : 'add']('primary');
30+
setTimeout(() => {
31+
if (sshButton) sshButton.classList.remove('no-transition');
32+
if (httpsButton) httpsButton.classList.remove('no-transition');
33+
}, 100);
34+
</script>
35+
{{end}}

templates/repo/empty.tmpl

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,7 @@
1818
<div class="item">
1919
<h3>{{.i18n.Tr "repo.clone_this_repo"}} <small>{{.i18n.Tr "repo.clone_helper" "http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository" | Str2html}}</small></h3>
2020
<div class="ui action small input">
21-
{{if not $.DisableHTTP}}
22-
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
23-
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
24-
</button>
25-
{{end}}
26-
{{if not $.DisableSSH}}
27-
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.CloneLink.SSH}}">
28-
SSH
29-
</button>
30-
{{end}}
31-
{{if not $.DisableHTTP}}
32-
<input id="repo-clone-url" value="{{$.CloneLink.HTTPS}}" readonly>
33-
{{else}}
34-
<input id="repo-clone-url" value="{{$.CloneLink.SSH}}" readonly>
35-
{{end}}
36-
{{if not (and $.DisableHTTP $.DisableSSH)}}
37-
<button class="ui basic 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">
38-
{{svg "octicon-clippy"}}
39-
</button>
40-
{{end}}
21+
{{template "repo/clone_buttons" .}}
4122
</div>
4223
</div>
4324

templates/repo/home.tmpl

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,43 +106,10 @@
106106
{{end}}
107107
</div>
108108
<div class="fitted item">
109-
110109
<!-- Only show clone panel in repository home page -->
111110
{{if eq $n 0}}
112111
<div class="ui action tiny input" id="clone-panel">
113-
{{if not $.DisableHTTP}}
114-
<button class="ui basic clone button no-transition" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
115-
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
116-
</button>
117-
{{end}}
118-
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
119-
<button class="ui basic clone button no-transition" id="repo-clone-ssh" data-link="{{.CloneLink.SSH}}">
120-
SSH
121-
</button>
122-
{{end}}
123-
{{if not $.DisableHTTP}}
124-
<input id="repo-clone-url" value="{{$.CloneLink.HTTPS}}" readonly>
125-
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
126-
<input id="repo-clone-url" value="{{$.CloneLink.SSH}}" readonly>
127-
{{end}}
128-
<script defer>
129-
const isSSH = localStorage.getItem('repo-clone-protocol') === 'ssh';
130-
const sshButton = document.getElementById('repo-clone-ssh');
131-
const httpsButton = document.getElementById('repo-clone-https');
132-
const input = document.getElementById('repo-clone-url');
133-
if (input) input.value = (isSSH ? sshButton : httpsButton).dataset.link;
134-
if (sshButton) sshButton.classList[isSSH ? 'add' : 'remove']('primary');
135-
if (httpsButton) httpsButton.classList[isSSH ? 'remove' : 'add']('primary');
136-
setTimeout(() => {
137-
if (sshButton) sshButton.classList.remove('no-transition');
138-
if (httpsButton) httpsButton.classList.remove('no-transition');
139-
}, 100);
140-
</script>
141-
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
142-
<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">
143-
{{svg "octicon-clippy"}}
144-
</button>
145-
{{end}}
112+
{{template "repo/clone_buttons" .}}
146113
<div class="ui basic jump dropdown icon button poping up" data-content="{{.i18n.Tr "repo.download_archive"}}" data-variation="tiny inverted" data-position="top right">
147114
{{svg "octicon-download"}}
148115
<div class="menu">

templates/repo/wiki/revision.tmpl

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,9 @@
44
{{ $title := .title}}
55
<div class="ui container">
66
<div class="ui stackable grid">
7-
<div class="ui eight wide column text right">
7+
<div class="ui eight wide column text right df ac je">
88
<div class="ui action small input" id="clone-panel">
9-
{{if not $.DisableHTTP}}
10-
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.WikiCloneLink.HTTPS}}">
11-
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
12-
</button>
13-
{{end}}
14-
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
15-
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.WikiCloneLink.SSH}}">
16-
SSH
17-
</button>
18-
{{end}}
19-
{{if not $.DisableHTTP}}
20-
<input id="repo-clone-url" value="{{$.WikiCloneLink.HTTPS}}" readonly>
21-
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
22-
<input id="repo-clone-url" value="{{$.WikiCloneLink.SSH}}" readonly>
23-
{{end}}
24-
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
25-
<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">
26-
{{svg "octicon-clippy"}}
27-
</button>
28-
{{end}}
9+
{{template "repo/clone_buttons" .}}
2910
</div>
3011
</div>
3112
<div class="ui header eight wide column">

templates/repo/wiki/view.tmpl

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,7 @@
3030
</div>
3131
<div class="right fitted item">
3232
<div class="ui action small input" id="clone-panel">
33-
{{if not $.DisableHTTP}}
34-
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.WikiCloneLink.HTTPS}}">
35-
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
36-
</button>
37-
{{end}}
38-
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
39-
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.WikiCloneLink.SSH}}">
40-
SSH
41-
</button>
42-
{{end}}
43-
{{if not $.DisableHTTP}}
44-
<input id="repo-clone-url" value="{{$.WikiCloneLink.HTTPS}}" readonly>
45-
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
46-
<input id="repo-clone-url" value="{{$.WikiCloneLink.SSH}}" readonly>
47-
{{end}}
48-
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
49-
<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">
50-
{{svg "octicon-clippy"}}
51-
</button>
52-
{{end}}
33+
{{template "repo/clone_buttons" .}}
5334
</div>
5435
</div>
5536
</div>

0 commit comments

Comments
 (0)