@@ -53,20 +53,49 @@ export function substituteRepoOpenWithUrl(tmpl: string, url: string): string {
53
53
function initCloneSchemeUrlSelection ( parent : Element ) {
54
54
const elCloneUrlInput = parent . querySelector < HTMLInputElement > ( '.repo-clone-url' ) ;
55
55
56
- const tabSsh = parent . querySelector ( '.repo-clone-ssh' ) ;
57
56
const tabHttps = parent . querySelector ( '.repo-clone-https' ) ;
57
+ const tabSsh = parent . querySelector ( '.repo-clone-ssh' ) ;
58
+ const tabTea = parent . querySelector ( '.repo-clone-tea' ) ;
58
59
const updateClonePanelUi = function ( ) {
59
- const scheme = localStorage . getItem ( 'repo-clone-protocol' ) || 'https' ;
60
- const isSSH = scheme === 'ssh' && Boolean ( tabSsh ) || scheme !== 'ssh' && ! tabHttps ;
60
+ let scheme = localStorage . getItem ( 'repo-clone-protocol' ) ;
61
+ if ( ! [ 'https' , 'ssh' , 'tea' ] . includes ( scheme ) ) {
62
+ scheme = 'https' ;
63
+ }
64
+
65
+ // Fallbacks if the scheme preference is not available in the tabs, for example: empty repo page, there are only HTTPS and SSH
66
+ if ( scheme === 'tea' && ! tabTea ) {
67
+ scheme = 'https' ;
68
+ }
69
+ if ( scheme === 'https' && ! tabHttps ) {
70
+ scheme = 'ssh' ;
71
+ } else if ( scheme === 'ssh' && ! tabSsh ) {
72
+ scheme = 'https' ;
73
+ }
74
+
75
+ const isHttps = scheme === 'https' ;
76
+ const isSsh = scheme === 'ssh' ;
77
+ const isTea = scheme === 'tea' ;
78
+
61
79
if ( tabHttps ) {
62
80
tabHttps . textContent = window . origin . split ( ':' ) [ 0 ] . toUpperCase ( ) ; // show "HTTP" or "HTTPS"
63
- tabHttps . classList . toggle ( 'active' , ! isSSH ) ;
81
+ tabHttps . classList . toggle ( 'active' , isHttps ) ;
64
82
}
65
83
if ( tabSsh ) {
66
- tabSsh . classList . toggle ( 'active' , isSSH ) ;
84
+ tabSsh . classList . toggle ( 'active' , isSsh ) ;
85
+ }
86
+ if ( tabTea ) {
87
+ tabTea . classList . toggle ( 'active' , isTea ) ;
88
+ }
89
+
90
+ let tab : Element ;
91
+ if ( isHttps ) {
92
+ tab = tabHttps ;
93
+ } else if ( isSsh ) {
94
+ tab = tabSsh ;
95
+ } else if ( isTea ) {
96
+ tab = tabTea ;
67
97
}
68
98
69
- const tab = isSSH ? tabSsh : tabHttps ;
70
99
if ( ! tab ) return ;
71
100
const link = toOriginUrl ( tab . getAttribute ( 'data-link' ) ) ;
72
101
@@ -84,12 +113,16 @@ function initCloneSchemeUrlSelection(parent: Element) {
84
113
85
114
updateClonePanelUi ( ) ;
86
115
// tabSsh or tabHttps might not both exist, eg: guest view, or one is disabled by the server
116
+ tabHttps ?. addEventListener ( 'click' , ( ) => {
117
+ localStorage . setItem ( 'repo-clone-protocol' , 'https' ) ;
118
+ updateClonePanelUi ( ) ;
119
+ } ) ;
87
120
tabSsh ?. addEventListener ( 'click' , ( ) => {
88
121
localStorage . setItem ( 'repo-clone-protocol' , 'ssh' ) ;
89
122
updateClonePanelUi ( ) ;
90
123
} ) ;
91
- tabHttps ?. addEventListener ( 'click' , ( ) => {
92
- localStorage . setItem ( 'repo-clone-protocol' , 'https ' ) ;
124
+ tabTea ?. addEventListener ( 'click' , ( ) => {
125
+ localStorage . setItem ( 'repo-clone-protocol' , 'tea ' ) ;
93
126
updateClonePanelUi ( ) ;
94
127
} ) ;
95
128
elCloneUrlInput . addEventListener ( 'focus' , ( ) => {
0 commit comments