Skip to content

Commit ae36113

Browse files
authored
Remove jQuery ready usage (#23858)
Replace it with equal function of our own and enable the eslint rule to forbid future usage.
1 parent eadda68 commit ae36113

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.eslintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ rules:
164164
jquery/no-parse-html: [2]
165165
jquery/no-prop: [0]
166166
jquery/no-proxy: [2]
167-
jquery/no-ready: [0]
167+
jquery/no-ready: [2]
168168
jquery/no-serialize: [2]
169169
jquery/no-show: [2]
170170
jquery/no-size: [2]

web_src/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// bootstrap module must be the first one to be imported, it handles webpack lazy-loading and global errors
22
import './bootstrap.js';
33

4-
import $ from 'jquery';
54
import {initRepoActivityTopAuthorsChart} from './components/RepoActivityTopAuthors.vue';
65
import {initDashboardRepoList} from './components/DashboardRepoList.vue';
76

@@ -90,6 +89,7 @@ import {initCaptcha} from './features/captcha.js';
9089
import {initRepositoryActionView} from './components/RepoActionView.vue';
9190
import {initGlobalTooltips} from './modules/tippy.js';
9291
import {initGiteaFomantic} from './modules/fomantic.js';
92+
import {onDomReady} from './utils/dom.js';
9393

9494
// Run time-critical code as soon as possible. This is safe to do because this
9595
// script appears at the end of <body> and rendered HTML is accessible at that point.
@@ -98,7 +98,7 @@ initFormattingReplacements();
9898
// Init Gitea's Fomantic settings
9999
initGiteaFomantic();
100100

101-
$(document).ready(() => {
101+
onDomReady(() => {
102102
initGlobalCommon();
103103

104104
initGlobalTooltips();

web_src/js/utils/dom.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ export function hideElem(el) {
6767
export function toggleElem(el, force) {
6868
elementsCall(el, toggleShown, force);
6969
}
70+
71+
export function onDomReady(cb) {
72+
if (document.readyState === 'loading') {
73+
document.addEventListener('DOMContentLoaded', cb);
74+
} else {
75+
cb();
76+
}
77+
}

0 commit comments

Comments
 (0)