Skip to content

Commit

Permalink
Fix the page flickers when the search dialog pops up
Browse files Browse the repository at this point in the history
  • Loading branch information
penxian committed Dec 12, 2024
1 parent 77adbf5 commit 5697532
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/css/_common/components/third-party/search.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if (hexo-config('local_search.enable') or hexo-config('algolia_search.enable')) {
.search-active {
overflow: hidden;
padding-right: var(--dialog-scrollgutter, 0);
}

.search-pop-overlay {
Expand Down
2 changes: 1 addition & 1 deletion source/css/_common/outline/header/github-banner.styl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (hexo-config('github_banner.enable')) {
color: white;
fill: var(--theme-color);
position: absolute;
right: 0;
right: var(--dialog-scrollgutter, 0);
top: 0;
z-index: $zindex-0;
}
Expand Down
1 change: 0 additions & 1 deletion source/css/_common/scaffolding/base.styl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ body {
line-height: $line-height-base;
min-height: 100%;
position: relative;
transition: padding $transition-ease;

if (hexo-config('body_scrollbar.overlay')) {
overflow-x: hidden;
Expand Down
3 changes: 3 additions & 0 deletions source/js/third-party/search/algolia-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Handle and trigger popup window
document.querySelectorAll('.popup-trigger').forEach(element => {
element.addEventListener('click', () => {
document.body.style.setProperty("--dialog-scrollgutter", `${window.innerWidth - document.body.clientWidth}px`);

Check failure on line 99 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
document.body.classList.add('search-active');
// Wait for search-popup animation to complete
setTimeout(() => input.focus(), 500);
Expand All @@ -104,6 +105,7 @@ document.addEventListener('DOMContentLoaded', () => {

// Monitor main search box
const onPopupClose = () => {
document.body.style.setProperty("--dialog-scrollgutter", 0);

Check failure on line 108 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
document.body.classList.remove('search-active');
};

Expand All @@ -117,6 +119,7 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('keydown', event => {
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault();
document.body.style.setProperty("--dialog-scrollgutter", `${window.innerWidth - document.body.clientWidth}px`);

Check failure on line 122 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
document.body.classList.add('search-active');
setTimeout(() => input.focus(), 500);
}
Expand Down
3 changes: 3 additions & 0 deletions source/js/third-party/search/local-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Handle and trigger popup window
document.querySelectorAll('.popup-trigger').forEach(element => {
element.addEventListener('click', () => {
document.body.style.setProperty("--dialog-scrollgutter", `${window.innerWidth - document.body.clientWidth}px`);

Check failure on line 60 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
document.body.classList.add('search-active');
// Wait for search-popup animation to complete
setTimeout(() => input.focus(), 500);
Expand All @@ -66,6 +67,7 @@ document.addEventListener('DOMContentLoaded', () => {

// Monitor main search box
const onPopupClose = () => {
document.body.style.setProperty("--dialog-scrollgutter", 0);

Check failure on line 70 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
document.body.classList.remove('search-active');
};

Expand All @@ -82,6 +84,7 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('keydown', event => {
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault();
document.body.style.setProperty("--dialog-scrollgutter", `${window.innerWidth - document.body.clientWidth}px`)

Check failure on line 87 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote

Check failure on line 87 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Missing semicolon
document.body.classList.add('search-active');
setTimeout(() => input.focus(), 500);
if (!localSearch.isfetched) localSearch.fetchData();
Expand Down

0 comments on commit 5697532

Please sign in to comment.