From 83deb893499483ea61ee9d37f557cdd19b6bb7d9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Apr 2023 05:32:28 +0200 Subject: [PATCH 1/2] Remove jQuery ready usage --- .eslintrc.yaml | 2 +- web_src/js/index.js | 4 ++-- web_src/js/utils/dom.js | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index a73df2ee344ce..2cde9d2aa558e 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -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] diff --git a/web_src/js/index.js b/web_src/js/index.js index 80edc0548016f..839289e9d29fe 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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'; @@ -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 and rendered HTML is accessible at that point. @@ -98,7 +98,7 @@ initFormattingReplacements(); // Init Gitea's Fomantic settings initGiteaFomantic(); -$(document).ready(() => { +onDomReady(() => { initGlobalCommon(); initGlobalTooltips(); diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index d94d4cb092210..b593ec9eeeaf6 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -67,3 +67,11 @@ export function hideElem(el) { export function toggleElem(el, force) { elementsCall(el, toggleShown, force); } + +export async function onDomReady(cb) { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', cb); + } else { + cb(); + } +} From f7cd8c5b5d63071d124e912c6d9ea294aaf5bd8f Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Apr 2023 05:39:58 +0200 Subject: [PATCH 2/2] Update web_src/js/utils/dom.js --- web_src/js/utils/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index b593ec9eeeaf6..80c9f01cf2ebf 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -68,7 +68,7 @@ export function toggleElem(el, force) { elementsCall(el, toggleShown, force); } -export async function onDomReady(cb) { +export function onDomReady(cb) { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', cb); } else {