-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Clean up and fix clone button script (#20415) The button 'primary' class needs to be set in a synchronous script to prevent flicker of the button which was regressed recently, fixed that. Additionally, reduced the two script tags to just one, the previous scripts were actually initializing the buttons thrice on the empty repo page, now it only initializes once. Finally, removed duplicate code and re-used the inline function in the update code as well. I had to split out the script into a separate template as on the empty repo page, the script needs access to the clone URL span in the example text, which is rendered below the clone buttons, so buttons and script could not be combined. * Add default value for clone URLs Default clone URLs to HTTP(S) in DOM rendering. JS will immediately replace this if the user preference is SSH. Fixes: #20558
- Loading branch information
1 parent
51c8c0f
commit 56b9955
Showing
7 changed files
with
33 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script> | ||
// synchronously set clone button states and urls here to avoid flickering | ||
// on page load. initRepoCloneLink calls this when proto changes. | ||
// 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.classList[!isSSH ? 'add' : 'remove']('primary'); | ||
if (sshBtn) sshBtn.classList[isSSH ? 'add' : 'remove']('primary'); | ||
const btn = isSSH ? sshBtn : httpsBtn; | ||
if (!btn) return; | ||
const link = btn.getAttribute('data-link'); | ||
for (const el of document.getElementsByClassName('js-clone-url')) { | ||
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link; | ||
} | ||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters