mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
Fix the page flickers when the search dialog pops up (#860)
This commit is contained in:
parent
934baf98e2
commit
a6f3be5d82
@ -1,6 +1,7 @@
|
|||||||
if (hexo-config('local_search.enable') or hexo-config('algolia_search.enable')) {
|
if (hexo-config('local_search.enable') or hexo-config('algolia_search.enable')) {
|
||||||
.search-active {
|
.search-active {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
margin-right: var(--dialog-scrollgutter, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-pop-overlay {
|
.search-pop-overlay {
|
||||||
|
|||||||
@ -100,6 +100,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Handle and trigger popup window
|
// Handle and trigger popup window
|
||||||
document.querySelectorAll('.popup-trigger').forEach(element => {
|
document.querySelectorAll('.popup-trigger').forEach(element => {
|
||||||
element.addEventListener('click', () => {
|
element.addEventListener('click', () => {
|
||||||
|
NexT.utils.setGutter();
|
||||||
document.body.classList.add('search-active');
|
document.body.classList.add('search-active');
|
||||||
// Wait for search-popup animation to complete
|
// Wait for search-popup animation to complete
|
||||||
setTimeout(() => input.focus(), 500);
|
setTimeout(() => input.focus(), 500);
|
||||||
@ -108,6 +109,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Monitor main search box
|
// Monitor main search box
|
||||||
const onPopupClose = () => {
|
const onPopupClose = () => {
|
||||||
|
NexT.utils.setGutter('0');
|
||||||
document.body.classList.remove('search-active');
|
document.body.classList.remove('search-active');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,6 +123,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
window.addEventListener('keydown', event => {
|
window.addEventListener('keydown', event => {
|
||||||
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
|
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
NexT.utils.setGutter();
|
||||||
document.body.classList.add('search-active');
|
document.body.classList.add('search-active');
|
||||||
setTimeout(() => input.focus(), 500);
|
setTimeout(() => input.focus(), 500);
|
||||||
}
|
}
|
||||||
|
|||||||
5
source/js/third-party/search/local-search.js
vendored
5
source/js/third-party/search/local-search.js
vendored
@ -1,4 +1,4 @@
|
|||||||
/* global CONFIG, pjax, LocalSearch */
|
/* global CONFIG, NexT, pjax, LocalSearch */
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
if (!CONFIG.path) {
|
if (!CONFIG.path) {
|
||||||
@ -57,6 +57,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Handle and trigger popup window
|
// Handle and trigger popup window
|
||||||
document.querySelectorAll('.popup-trigger').forEach(element => {
|
document.querySelectorAll('.popup-trigger').forEach(element => {
|
||||||
element.addEventListener('click', () => {
|
element.addEventListener('click', () => {
|
||||||
|
NexT.utils.setGutter();
|
||||||
document.body.classList.add('search-active');
|
document.body.classList.add('search-active');
|
||||||
// Wait for search-popup animation to complete
|
// Wait for search-popup animation to complete
|
||||||
setTimeout(() => input.focus(), 500);
|
setTimeout(() => input.focus(), 500);
|
||||||
@ -66,6 +67,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Monitor main search box
|
// Monitor main search box
|
||||||
const onPopupClose = () => {
|
const onPopupClose = () => {
|
||||||
|
NexT.utils.setGutter('0');
|
||||||
document.body.classList.remove('search-active');
|
document.body.classList.remove('search-active');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
window.addEventListener('keydown', event => {
|
window.addEventListener('keydown', event => {
|
||||||
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
|
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
NexT.utils.setGutter();
|
||||||
document.body.classList.add('search-active');
|
document.body.classList.add('search-active');
|
||||||
setTimeout(() => input.focus(), 500);
|
setTimeout(() => input.focus(), 500);
|
||||||
if (!localSearch.isfetched) localSearch.fetchData();
|
if (!localSearch.isfetched) localSearch.fetchData();
|
||||||
|
|||||||
@ -442,6 +442,18 @@ NexT.utils = {
|
|||||||
window.addEventListener('scroll', updateFooterPosition, { passive: true });
|
window.addEventListener('scroll', updateFooterPosition, { passive: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the CSS variable '--dialog-scrollgutter' to the specified gap value.
|
||||||
|
* If no gap is provided, it calculates the gap as the difference between
|
||||||
|
* the window's inner width and the document body's client width.
|
||||||
|
*
|
||||||
|
* @param {string} [gap] - The gap value to be set. If not provided, the
|
||||||
|
* default gap is calculated automatically.
|
||||||
|
*/
|
||||||
|
setGutter(gap) {
|
||||||
|
document.body.style.setProperty('--dialog-scrollgutter', gap || `${window.innerWidth - document.body.clientWidth}px`);
|
||||||
|
},
|
||||||
|
|
||||||
getScript(src, options = {}, legacyCondition) {
|
getScript(src, options = {}, legacyCondition) {
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
return this.getScript(src, {
|
return this.getScript(src, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user