From 0040a3cfdd10e26da099f8ae0240774a6e931ac9 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 17 Apr 2024 06:10:01 +0800 Subject: [PATCH] perf: replace jQuery with Vanilla JS (#1681) Also replaced `magnific-popup` with `GLightbox` --- _data/origin/basic.yml | 9 +- _data/origin/cors.yml | 9 +- _includes/comments/disqus.html | 4 +- _includes/comments/giscus.html | 3 +- _includes/comments/utterances.html | 3 +- _includes/head.html | 4 +- _includes/js-selector.html | 11 +- _includes/mermaid.html | 50 +++---- _includes/sidebar.html | 2 +- _includes/topbar.html | 2 +- _javascript/modules/components/back-to-top.js | 15 +- .../modules/components/category-collapse.js | 49 ++++--- _javascript/modules/components/clipboard.js | 123 +++++++++-------- _javascript/modules/components/img-loading.js | 36 +++-- _javascript/modules/components/img-popup.js | 17 +-- .../modules/components/locale-datetime.js | 42 +++--- .../modules/components/mode-watcher.js | 15 +- .../modules/components/search-display.js | 130 ++++++++---------- _javascript/modules/components/sidebar.js | 12 +- _sass/addon/commons.scss | 25 ++-- assets/js/pwa/app.js | 14 +- 21 files changed, 272 insertions(+), 303 deletions(-) diff --git a/_data/origin/basic.yml b/_data/origin/basic.yml index ed99ea850a6..73822515027 100644 --- a/_data/origin/basic.yml +++ b/_data/origin/basic.yml @@ -4,9 +4,6 @@ webfonts: /assets/lib/fonts/main.css # Libraries -jquery: - js: /assets/lib/jquery/jquery.min.js - bootstrap: css: /assets/lib/bootstrap/bootstrap.min.css js: /assets/lib/bootstrap/bootstrap.bundle.min.js @@ -31,9 +28,9 @@ dayjs: relativeTime: /assets/lib/dayjs/plugin/relativeTime.min.js localizedFormat: /assets/lib/dayjs/plugin/localizedFormat.min.js -magnific-popup: - css: /assets/lib/magnific-popup/magnific-popup.css - js: /assets/lib/magnific-popup/jquery.magnific-popup.min.js +glightbox: + css: /assets/lib/glightbox/glightbox.min.css + js: /assets/lib/glightbox/glightbox.min.js lazy-polyfill: css: /assets/lib/loading-attribute-polyfill/loading-attribute-polyfill.min.css diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml index 614139f8e37..a10d31cc274 100644 --- a/_data/origin/cors.yml +++ b/_data/origin/cors.yml @@ -17,9 +17,6 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Sour # Libraries -jquery: - js: https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js - bootstrap: css: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css js: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js @@ -44,9 +41,9 @@ dayjs: relativeTime: https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/relativeTime.min.js localizedFormat: https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/localizedFormat.min.js -magnific-popup: - css: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/magnific-popup.min.css - js: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/jquery.magnific-popup.min.js +glightbox: + css: https://cdn.jsdelivr.net/npm/glightbox@3.3.0/dist/css/glightbox.min.css + js: https://cdn.jsdelivr.net/npm/glightbox@3.3.0/dist/js/glightbox.min.js lazy-polyfill: css: https://cdn.jsdelivr.net/npm/loading-attribute-polyfill@2.1.1/dist/loading-attribute-polyfill.min.css diff --git a/_includes/comments/disqus.html b/_includes/comments/disqus.html index e59ed37dd2b..bef843acc35 100644 --- a/_includes/comments/disqus.html +++ b/_includes/comments/disqus.html @@ -28,7 +28,7 @@ { threshold: [0] } ); - disqus_observer.observe(document.querySelector('#disqus_thread')); + disqus_observer.observe(document.getElementById('disqus_thread')); /* Auto switch theme */ function reloadDisqus() { @@ -44,7 +44,7 @@ } } - if (document.querySelector('.mode-toggle')) { + if (document.getElementById('mode-toggle')) { window.addEventListener('message', reloadDisqus); } diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index 526aa22bcf1..f3b8a54b73c 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -2,7 +2,6 @@ diff --git a/_includes/sidebar.html b/_includes/sidebar.html index 0b5560a33b0..577cc13f814 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -44,7 +44,7 @@