aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
authorChai-Shi <changchaishi@gmail.com>2024-12-31 12:22:09 +0800
committerGitHub <noreply@github.com>2024-12-31 04:22:09 +0000
commit0387195abb82080b4c488966960f25a3e8c6fe66 (patch)
tree794cf1e7705002236a33af563729284b48a303c5 /web_src/js
parentc09656e0e0384b15405f909a0e7d7e94a373448e (diff)
downloadgitea-0387195abb82080b4c488966960f25a3e8c6fe66.tar.gz
gitea-0387195abb82080b4c488966960f25a3e8c6fe66.zip
[Feature] Private README.md for organization (#32872)
Implemented #29503 --------- Co-authored-by: Ben Chang <ben_chang@htc.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/repo-new.ts42
1 files changed, 31 insertions, 11 deletions
diff --git a/web_src/js/features/repo-new.ts b/web_src/js/features/repo-new.ts
index 436288325a..ec44a14ce0 100644
--- a/web_src/js/features/repo-new.ts
+++ b/web_src/js/features/repo-new.ts
@@ -1,14 +1,34 @@
-import $ from 'jquery';
+import {hideElem, showElem} from '../utils/dom.ts';
export function initRepoNew() {
- // Repo Creation
- if ($('.repository.new.repo').length > 0) {
- $('input[name="gitignores"], input[name="license"]').on('change', () => {
- const gitignores = $('input[name="gitignores"]').val();
- const license = $('input[name="license"]').val();
- if (gitignores || license) {
- document.querySelector<HTMLInputElement>('input[name="auto_init"]').checked = true;
- }
- });
- }
+ const pageContent = document.querySelector('.page-content.repository.new-repo');
+ if (!pageContent) return;
+
+ const form = document.querySelector('.new-repo-form');
+ const inputGitIgnores = form.querySelector<HTMLInputElement>('input[name="gitignores"]');
+ const inputLicense = form.querySelector<HTMLInputElement>('input[name="license"]');
+ const inputAutoInit = form.querySelector<HTMLInputElement>('input[name="auto_init"]');
+ const updateUiAutoInit = () => {
+ inputAutoInit.checked = Boolean(inputGitIgnores.value || inputLicense.value);
+ };
+ form.addEventListener('change', updateUiAutoInit);
+ updateUiAutoInit();
+
+ const inputRepoName = form.querySelector<HTMLInputElement>('input[name="repo_name"]');
+ const inputPrivate = form.querySelector<HTMLInputElement>('input[name="private"]');
+ const updateUiRepoName = () => {
+ const helps = form.querySelectorAll(`.help[data-help-for-repo-name]`);
+ hideElem(helps);
+ let help = form.querySelector(`.help[data-help-for-repo-name="${CSS.escape(inputRepoName.value)}"]`);
+ if (!help) help = form.querySelector(`.help[data-help-for-repo-name=""]`);
+ showElem(help);
+ const repoNamePreferPrivate = {'.profile': false, '.profile-private': true};
+ const preferPrivate = repoNamePreferPrivate[inputRepoName.value];
+ // inputPrivate might be disabled because site admin "force private"
+ if (preferPrivate !== undefined && !inputPrivate.closest('.disabled, [disabled]')) {
+ inputPrivate.checked = preferPrivate;
+ }
+ };
+ inputRepoName.addEventListener('input', updateUiRepoName);
+ updateUiRepoName();
}