Skip to content

Commit 10e3a71

Browse files
Remove jQuery from the repo migration form (go-gitea#29229)
- Switched to plain JavaScript - Tested the repo migration form functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/3496ec05-48a7-449e-8cdd-f8372ba0d589) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io>
1 parent 20cbb4e commit 10e3a71

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

web_src/js/features/repo-migration.js

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,69 @@
1-
import $ from 'jquery';
21
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
32

4-
const $service = $('#service_type');
5-
const $user = $('#auth_username');
6-
const $pass = $('#auth_password');
7-
const $token = $('#auth_token');
8-
const $mirror = $('#mirror');
9-
const $lfs = $('#lfs');
10-
const $lfsSettings = $('#lfs_settings');
11-
const $lfsEndpoint = $('#lfs_endpoint');
12-
const $items = $('#migrate_items').find('input[type=checkbox]');
3+
const service = document.getElementById('service_type');
4+
const user = document.getElementById('auth_username');
5+
const pass = document.getElementById('auth_password');
6+
const token = document.getElementById('auth_token');
7+
const mirror = document.getElementById('mirror');
8+
const lfs = document.getElementById('lfs');
9+
const lfsSettings = document.getElementById('lfs_settings');
10+
const lfsEndpoint = document.getElementById('lfs_endpoint');
11+
const items = document.querySelectorAll('#migrate_items input[type=checkbox]');
1312

1413
export function initRepoMigration() {
1514
checkAuth();
1615
setLFSSettingsVisibility();
1716

18-
$user.on('input', () => {checkItems(false)});
19-
$pass.on('input', () => {checkItems(false)});
20-
$token.on('input', () => {checkItems(true)});
21-
$mirror.on('change', () => {checkItems(true)});
22-
$('#lfs_settings_show').on('click', () => { showElem($lfsEndpoint); return false });
23-
$lfs.on('change', setLFSSettingsVisibility);
24-
25-
const $cloneAddr = $('#clone_addr');
26-
$cloneAddr.on('change', () => {
27-
const $repoName = $('#repo_name');
28-
if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
29-
$repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
17+
user?.addEventListener('input', () => {checkItems(false)});
18+
pass?.addEventListener('input', () => {checkItems(false)});
19+
token?.addEventListener('input', () => {checkItems(true)});
20+
mirror?.addEventListener('change', () => {checkItems(true)});
21+
document.getElementById('lfs_settings_show')?.addEventListener('click', (e) => {
22+
e.preventDefault();
23+
e.stopPropagation();
24+
showElem(lfsEndpoint);
25+
});
26+
lfs?.addEventListener('change', setLFSSettingsVisibility);
27+
28+
const cloneAddr = document.getElementById('clone_addr');
29+
cloneAddr?.addEventListener('change', () => {
30+
const repoName = document.getElementById('repo_name');
31+
if (cloneAddr.value && !repoName?.value) { // Only modify if repo_name input is blank
32+
repoName.value = cloneAddr.value.match(/^(.*\/)?((.+?)(\.git)?)$/)[3];
3033
}
3134
});
3235
}
3336

3437
function checkAuth() {
35-
const serviceType = $service.val();
38+
if (!service) return;
39+
const serviceType = Number(service.value);
3640

3741
checkItems(serviceType !== 1);
3842
}
3943

4044
function checkItems(tokenAuth) {
4145
let enableItems;
4246
if (tokenAuth) {
43-
enableItems = $token.val() !== '';
47+
enableItems = token?.value !== '';
4448
} else {
45-
enableItems = $user.val() !== '' || $pass.val() !== '';
49+
enableItems = user?.value !== '' || pass?.value !== '';
4650
}
47-
if (enableItems && $service.val() > 1) {
48-
if ($mirror.is(':checked')) {
49-
$items.not('[name="wiki"]').attr('disabled', true);
50-
$items.filter('[name="wiki"]').attr('disabled', false);
51+
if (enableItems && Number(service?.value) > 1) {
52+
if (mirror?.checked) {
53+
for (const item of items) {
54+
item.disabled = item.name !== 'wiki';
55+
}
5156
return;
5257
}
53-
$items.attr('disabled', false);
58+
for (const item of items) item.disabled = false;
5459
} else {
55-
$items.attr('disabled', true);
60+
for (const item of items) item.disabled = true;
5661
}
5762
}
5863

5964
function setLFSSettingsVisibility() {
60-
const visible = $lfs.is(':checked');
61-
toggleElem($lfsSettings, visible);
62-
hideElem($lfsEndpoint);
65+
if (!lfs) return;
66+
const visible = lfs.checked;
67+
toggleElem(lfsSettings, visible);
68+
hideElem(lfsEndpoint);
6369
}

0 commit comments

Comments
 (0)