@@ -53,20 +53,49 @@ export function substituteRepoOpenWithUrl(tmpl: string, url: string): string {
5353function initCloneSchemeUrlSelection ( parent : Element ) {
5454 const elCloneUrlInput = parent . querySelector < HTMLInputElement > ( '.repo-clone-url' ) ;
5555
56- const tabSsh = parent . querySelector ( '.repo-clone-ssh' ) ;
5756 const tabHttps = parent . querySelector ( '.repo-clone-https' ) ;
57+ const tabSsh = parent . querySelector ( '.repo-clone-ssh' ) ;
58+ const tabTea = parent . querySelector ( '.repo-clone-tea' ) ;
5859 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+
6179 if ( tabHttps ) {
6280 tabHttps . textContent = window . origin . split ( ':' ) [ 0 ] . toUpperCase ( ) ; // show "HTTP" or "HTTPS"
63- tabHttps . classList . toggle ( 'active' , ! isSSH ) ;
81+ tabHttps . classList . toggle ( 'active' , isHttps ) ;
6482 }
6583 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 ;
6797 }
6898
69- const tab = isSSH ? tabSsh : tabHttps ;
7099 if ( ! tab ) return ;
71100 const link = toOriginUrl ( tab . getAttribute ( 'data-link' ) ) ;
72101
@@ -84,12 +113,16 @@ function initCloneSchemeUrlSelection(parent: Element) {
84113
85114 updateClonePanelUi ( ) ;
86115 // 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+ } ) ;
87120 tabSsh ?. addEventListener ( 'click' , ( ) => {
88121 localStorage . setItem ( 'repo-clone-protocol' , 'ssh' ) ;
89122 updateClonePanelUi ( ) ;
90123 } ) ;
91- tabHttps ?. addEventListener ( 'click' , ( ) => {
92- localStorage . setItem ( 'repo-clone-protocol' , 'https ' ) ;
124+ tabTea ?. addEventListener ( 'click' , ( ) => {
125+ localStorage . setItem ( 'repo-clone-protocol' , 'tea ' ) ;
93126 updateClonePanelUi ( ) ;
94127 } ) ;
95128 elCloneUrlInput . addEventListener ( 'focus' , ( ) => {
0 commit comments