修复流畅性
This commit is contained in:
1 parent
3a7bddb881
commit
9ab38b6e6a
11 files changed
+175
-82
No files matched your search
@@ -1,3 +1,19 @@
|
||||
window.refreshFloatingTools = function() {
|
||||
if (typeof window.initFloatingTools !== 'function') return;
|
||||
var delays = [0, 60, 180];
|
||||
delays.forEach(function(delay) {
|
||||
setTimeout(function() {
|
||||
requestAnimationFrame(function() {
|
||||
try {
|
||||
window.initFloatingTools();
|
||||
} catch (e) {
|
||||
console.error('initFloatingTools error:', e);
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
});
|
||||
};
|
||||
|
||||
window.initFloatingTools = function() {
|
||||
try {
|
||||
// 0. Global Toolbar Visibility (Homepage Check)
|
||||
@@ -7,29 +23,21 @@ window.initFloatingTools = function() {
|
||||
// 1. Check for Homepage-specific element (.recent-posts)
|
||||
// 2. Ensure NOT on a Post page (.post-content)
|
||||
// 3. Fallback: Check pathname (only if DOM check is ambiguous)
|
||||
var hasRecentPosts = document.querySelector('.recent-posts');
|
||||
var hasPostContent = document.querySelector('.post-content');
|
||||
|
||||
var isHomePage = false;
|
||||
if (hasRecentPosts && !hasPostContent) {
|
||||
isHomePage = true;
|
||||
} else if (!hasRecentPosts && !hasPostContent) {
|
||||
// Could be Archive or Custom Page. Check Path.
|
||||
var path = window.location.pathname;
|
||||
if (path === '/' || path === '/index.html' || path.startsWith('/page/')) {
|
||||
isHomePage = true;
|
||||
}
|
||||
}
|
||||
var pjaxContainer = document.getElementById('pjax-container');
|
||||
var hasRecentPosts = !!(pjaxContainer && pjaxContainer.querySelector('.recent-posts'));
|
||||
var hasArticle = !!(pjaxContainer && (pjaxContainer.querySelector('#post-writing') || pjaxContainer.querySelector('#Comments')));
|
||||
var path = window.location.pathname;
|
||||
var isHomePage = !hasArticle && (hasRecentPosts || path === '/' || path === '/index.html' || path.startsWith('/page/'));
|
||||
|
||||
if (container) {
|
||||
if (isHomePage) {
|
||||
container.style.display = 'none';
|
||||
// Do not return here, let other logic run in case we need to reset state
|
||||
// But for performance, we can skip binding if hidden?
|
||||
// No, better to bind so if it becomes visible later (unlikely without PJAX) it works.
|
||||
// Actually, with PJAX, this function runs again. So we can just hide it.
|
||||
} else {
|
||||
container.style.display = ''; // Restore display
|
||||
container.style.display = 'flex';
|
||||
container.classList.remove('hidden');
|
||||
container.style.visibility = 'visible';
|
||||
container.style.opacity = '1';
|
||||
container.style.pointerEvents = 'auto';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,18 +63,19 @@ window.initFloatingTools = function() {
|
||||
}
|
||||
|
||||
if (window.IntersectionObserver) {
|
||||
var observer = new IntersectionObserver(function(entries) {
|
||||
if (window.backToTopObserver) {
|
||||
window.backToTopObserver.disconnect();
|
||||
}
|
||||
window.backToTopObserver = new IntersectionObserver(function(entries) {
|
||||
entries.forEach(function(entry) {
|
||||
if (!entry.isIntersecting) {
|
||||
// Sentinel is out of view (scrolled down past 300px)
|
||||
backToTopButton.classList.add('show');
|
||||
} else {
|
||||
// Sentinel is in view (near top)
|
||||
backToTopButton.classList.remove('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(sentinel);
|
||||
window.backToTopObserver.observe(sentinel);
|
||||
} else {
|
||||
// Fallback for very old browsers
|
||||
var ticking = false;
|
||||
@@ -207,18 +216,32 @@ window.initFloatingTools = function() {
|
||||
window.lightboxObserver.disconnect();
|
||||
}
|
||||
|
||||
if (container) {
|
||||
if (container && !isHomePage) {
|
||||
var lightboxToolsHidden = null;
|
||||
var syncLightboxState = function() {
|
||||
var lightbox = document.querySelector('.view-image');
|
||||
var lightboxOpen = false;
|
||||
if (lightbox) {
|
||||
var rect = lightbox.getBoundingClientRect();
|
||||
var style = window.getComputedStyle(lightbox);
|
||||
lightboxOpen = style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0' && rect.width > 0 && rect.height > 0;
|
||||
}
|
||||
if (lightboxToolsHidden === lightboxOpen) return;
|
||||
lightboxToolsHidden = lightboxOpen;
|
||||
|
||||
if (lightboxOpen) {
|
||||
container.classList.add('hidden');
|
||||
} else {
|
||||
container.classList.remove('hidden');
|
||||
container.style.display = 'flex';
|
||||
container.style.visibility = 'visible';
|
||||
container.style.opacity = '1';
|
||||
container.style.pointerEvents = 'auto';
|
||||
}
|
||||
};
|
||||
|
||||
window.lightboxObserver = new MutationObserver(function() {
|
||||
syncLightboxState();
|
||||
requestAnimationFrame(syncLightboxState);
|
||||
});
|
||||
|
||||
window.lightboxObserver.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
Reference in new issue
Block a user