Skip to content

Commit

Permalink
Remove jQuery ready usage (#23858)
Browse files Browse the repository at this point in the history
Replace it with equal function of our own and enable the eslint rule to
forbid future usage.
  • Loading branch information
silverwind authored Apr 1, 2023
1 parent eadda68 commit ae36113
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ rules:
jquery/no-parse-html: [2]
jquery/no-prop: [0]
jquery/no-proxy: [2]
jquery/no-ready: [0]
jquery/no-ready: [2]
jquery/no-serialize: [2]
jquery/no-show: [2]
jquery/no-size: [2]
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// bootstrap module must be the first one to be imported, it handles webpack lazy-loading and global errors
import './bootstrap.js';

import $ from 'jquery';
import {initRepoActivityTopAuthorsChart} from './components/RepoActivityTopAuthors.vue';
import {initDashboardRepoList} from './components/DashboardRepoList.vue';

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

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

$(document).ready(() => {
onDomReady(() => {
initGlobalCommon();

initGlobalTooltips();
Expand Down
8 changes: 8 additions & 0 deletions web_src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ export function hideElem(el) {
export function toggleElem(el, force) {
elementsCall(el, toggleShown, force);
}

export function onDomReady(cb) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', cb);
} else {
cb();
}
}

0 comments on commit ae36113

Please sign in to comment.