Skip to content

Commit 4e536ed

Browse files
authored
Remove jQuery from the installation page (#29284)
- Switched to plain JavaScript - Tested the installation page functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/286475b3-1919-4d99-b790-def10fa36e66) Signed-off-by: Yarden Shoham <[email protected]>
1 parent 7f45dfb commit 4e536ed

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

web_src/js/features/install.js

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import $ from 'jquery';
21
import {hideElem, showElem} from '../utils/dom.js';
32
import {GET} from '../modules/fetch.js';
43

54
export function initInstall() {
6-
const $page = $('.page-content.install');
7-
if ($page.length === 0) {
5+
const page = document.querySelector('.page-content.install');
6+
if (!page) {
87
return;
98
}
10-
if ($page.is('.post-install')) {
9+
if (page.classList.contains('post-install')) {
1110
initPostInstall();
1211
} else {
1312
initPreInstall();
1413
}
1514
}
16-
1715
function initPreInstall() {
1816
const defaultDbUser = 'gitea';
1917
const defaultDbName = 'gitea';
@@ -24,83 +22,82 @@ function initPreInstall() {
2422
mssql: '127.0.0.1:1433'
2523
};
2624

27-
const $dbHost = $('#db_host');
28-
const $dbUser = $('#db_user');
29-
const $dbName = $('#db_name');
25+
const dbHost = document.getElementById('db_host');
26+
const dbUser = document.getElementById('db_user');
27+
const dbName = document.getElementById('db_name');
3028

3129
// Database type change detection.
32-
$('#db_type').on('change', function () {
33-
const dbType = $(this).val();
34-
hideElem($('div[data-db-setting-for]'));
35-
showElem($(`div[data-db-setting-for=${dbType}]`));
30+
document.getElementById('db_type').addEventListener('change', function () {
31+
const dbType = this.value;
32+
hideElem('div[data-db-setting-for]');
33+
showElem(`div[data-db-setting-for=${dbType}]`);
3634

3735
if (dbType !== 'sqlite3') {
3836
// for most remote database servers
39-
showElem($(`div[data-db-setting-for=common-host]`));
40-
const lastDbHost = $dbHost.val();
37+
showElem('div[data-db-setting-for=common-host]');
38+
const lastDbHost = dbHost.value;
4139
const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
4240
if (isDbHostDefault) {
43-
$dbHost.val(defaultDbHosts[dbType] ?? '');
41+
dbHost.value = defaultDbHosts[dbType] ?? '';
4442
}
45-
if (!$dbUser.val() && !$dbName.val()) {
46-
$dbUser.val(defaultDbUser);
47-
$dbName.val(defaultDbName);
43+
if (!dbUser.value && !dbName.value) {
44+
dbUser.value = defaultDbUser;
45+
dbName.value = defaultDbName;
4846
}
4947
} // else: for SQLite3, the default path is always prepared by backend code (setting)
50-
}).trigger('change');
48+
});
49+
document.getElementById('db_type').dispatchEvent(new Event('change'));
5150

52-
const $appUrl = $('#app_url');
53-
const configAppUrl = $appUrl.val();
54-
if (configAppUrl.includes('://localhost')) {
55-
$appUrl.val(window.location.href);
51+
const appUrl = document.getElementById('app_url');
52+
if (appUrl.value.includes('://localhost')) {
53+
appUrl.value = window.location.href;
5654
}
5755

58-
const $domain = $('#domain');
59-
const configDomain = $domain.val().trim();
60-
if (configDomain === 'localhost') {
61-
$domain.val(window.location.hostname);
56+
const domain = document.getElementById('domain');
57+
if (domain.value.trim() === 'localhost') {
58+
domain.value = window.location.hostname;
6259
}
6360

6461
// TODO: better handling of exclusive relations.
65-
$('#offline-mode input').on('change', function () {
66-
if ($(this).is(':checked')) {
67-
$('#disable-gravatar').checkbox('check');
68-
$('#federated-avatar-lookup').checkbox('uncheck');
62+
document.querySelector('#offline-mode input').addEventListener('change', function () {
63+
if (this.checked) {
64+
document.querySelector('#disable-gravatar input').checked = true;
65+
document.querySelector('#federated-avatar-lookup input').checked = false;
6966
}
7067
});
71-
$('#disable-gravatar input').on('change', function () {
72-
if ($(this).is(':checked')) {
73-
$('#federated-avatar-lookup').checkbox('uncheck');
68+
document.querySelector('#disable-gravatar input').addEventListener('change', function () {
69+
if (this.checked) {
70+
document.querySelector('#federated-avatar-lookup input').checked = false;
7471
} else {
75-
$('#offline-mode').checkbox('uncheck');
72+
document.querySelector('#offline-mode input').checked = false;
7673
}
7774
});
78-
$('#federated-avatar-lookup input').on('change', function () {
79-
if ($(this).is(':checked')) {
80-
$('#disable-gravatar').checkbox('uncheck');
81-
$('#offline-mode').checkbox('uncheck');
75+
document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
76+
if (this.checked) {
77+
document.querySelector('#disable-gravatar input').checked = false;
78+
document.querySelector('#offline-mode input').checked = false;
8279
}
8380
});
84-
$('#enable-openid-signin input').on('change', function () {
85-
if ($(this).is(':checked')) {
86-
if (!$('#disable-registration input').is(':checked')) {
87-
$('#enable-openid-signup').checkbox('check');
81+
document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
82+
if (this.checked) {
83+
if (!document.querySelector('#disable-registration input').checked) {
84+
document.querySelector('#enable-openid-signup input').checked = true;
8885
}
8986
} else {
90-
$('#enable-openid-signup').checkbox('uncheck');
87+
document.querySelector('#enable-openid-signup input').checked = false;
9188
}
9289
});
93-
$('#disable-registration input').on('change', function () {
94-
if ($(this).is(':checked')) {
95-
$('#enable-captcha').checkbox('uncheck');
96-
$('#enable-openid-signup').checkbox('uncheck');
90+
document.querySelector('#disable-registration input').addEventListener('change', function () {
91+
if (this.checked) {
92+
document.querySelector('#enable-captcha input').checked = false;
93+
document.querySelector('#enable-openid-signup input').checked = false;
9794
} else {
98-
$('#enable-openid-signup').checkbox('check');
95+
document.querySelector('#enable-openid-signup input').checked = true;
9996
}
10097
});
101-
$('#enable-captcha input').on('change', function () {
102-
if ($(this).is(':checked')) {
103-
$('#disable-registration').checkbox('uncheck');
98+
document.querySelector('#enable-captcha input').addEventListener('change', function () {
99+
if (this.checked) {
100+
document.querySelector('#disable-registration input').checked = false;
104101
}
105102
});
106103
}

0 commit comments

Comments
 (0)