2 Commits

Author SHA1 Message Date
Dome c06b2e25ba TOC optimizations 2026-04-22 10:47:30 +02:00
Dome 4424799bb0 TOC Optimizations 2026-04-22 08:30:54 +02:00
2 changed files with 51 additions and 23 deletions
+47 -20
View File
@@ -14,6 +14,8 @@ document.addEventListener('DOMContentLoaded', function () {
var headingOffset = 88; var headingOffset = 88;
var ticking = false; var ticking = false;
var tocBottomOffset = null;
function isDesktop() { function isDesktop() {
return desktopQuery.matches; return desktopQuery.matches;
} }
@@ -34,6 +36,26 @@ document.addEventListener('DOMContentLoaded', function () {
}); });
} }
function getArticleElement() {
return document.querySelector(
'.single-post .post-content article, ' +
'.single-post .post-content, ' +
'article.post, article, ' +
'.entry-content'
);
}
function getTocBottomOffset() {
if (tocBottomOffset !== null) return tocBottomOffset;
var value = getComputedStyle(document.documentElement)
.getPropertyValue('--toc-bottom-offset')
.trim();
tocBottomOffset = parseInt(value, 10) || 12;
return tocBottomOffset;
}
function syncPosition() { function syncPosition() {
if (!isDesktop()) { if (!isDesktop()) {
document.documentElement.style.setProperty('--zeitfresser-toc-top', stickyTop + 'px'); document.documentElement.style.setProperty('--zeitfresser-toc-top', stickyTop + 'px');
@@ -84,23 +106,32 @@ document.addEventListener('DOMContentLoaded', function () {
return; return;
} }
var footer = document.querySelector('footer.site-footer, footer, #colophon'); var article = getArticleElement();
if (!footer) return;
var footerRect = footer.getBoundingClientRect(); if (!article) {
var tocRect = toc.getBoundingClientRect();
var offset = 40;
var triggerOffset = Math.min(200, window.innerHeight * 0.2);
var overlap = tocRect.bottom - (footerRect.top - triggerOffset);
if (overlap > -offset) {
var strength = 0.85;
var correction = Math.max(0, (overlap + offset) * strength);
toc.style.transform = 'translateY(-' + correction + 'px)';
} else {
toc.style.transform = ''; toc.style.transform = '';
return;
}
toc.style.transform = '';
var scrollTop = window.scrollY || window.pageYOffset;
var articleRect = article.getBoundingClientRect();
var articleBottom = articleRect.top + scrollTop + articleRect.height;
var tocRect = toc.getBoundingClientRect();
var tocTop = tocRect.top + scrollTop;
var tocHeight = tocRect.height;
var tocBottom = tocTop + tocHeight;
var offset = getTocBottomOffset();
var maxBottom = articleBottom - offset;
var overflow = Math.ceil(tocBottom - maxBottom);
if (overflow > 0) {
toc.style.transform = 'translateY(-' + overflow + 'px)';
} }
} }
@@ -120,10 +151,7 @@ document.addEventListener('DOMContentLoaded', function () {
function updateProgress() { function updateProgress() {
if (!progressBar) return; if (!progressBar) return;
var article = document.querySelector( var article = getArticleElement();
'.single-post .post-content article, ' +
'.single-post .post-content, article.post, article'
);
if (!article) { if (!article) {
progressBar.style.width = '0%'; progressBar.style.width = '0%';
@@ -139,7 +167,6 @@ document.addEventListener('DOMContentLoaded', function () {
function updateActiveHeading() { function updateActiveHeading() {
var headings = getHeadings(); var headings = getHeadings();
if (!headings.length) return; if (!headings.length) return;
var currentId = headings[0].target.id; var currentId = headings[0].target.id;
+4 -3
View File
@@ -5,7 +5,7 @@ Author: Zeitfresser
Author URI: https://ztfr.eu/ Author URI: https://ztfr.eu/
Theme URI: https://ztfr.eu/ Theme URI: https://ztfr.eu/
Description: Zeitfresser Wordpress Theme Description: Zeitfresser Wordpress Theme
Version: 1.1 Version: 1.3
Tested up to: 6.2 Tested up to: 6.2
Requires PHP: 7.0 Requires PHP: 7.0
License: GNU General Public License v2 or later License: GNU General Public License v2 or later
@@ -34,6 +34,7 @@ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:b
:root{ :root{
--zeitfresser-toc-top-offset: 10px; --zeitfresser-toc-top-offset: 10px;
--zeitfresser-toc-width: 230px; --zeitfresser-toc-width: 230px;
--toc-bottom-offset: 10px;
} }
.zeitfresser-floating-toc{ .zeitfresser-floating-toc{
@@ -53,7 +54,7 @@ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:b
backdrop-filter:none !important; backdrop-filter:none !important;
box-shadow:none !important; box-shadow:none !important;
overflow:hidden !important; overflow:visible !important;
transform:none; transform:none;
pointer-events:auto !important; pointer-events:auto !important;
@@ -64,7 +65,7 @@ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:b
opacity: 0; opacity: 0;
transition: opacity 0.12s ease-out; transition: opacity 0.12s ease-out;
will-change: opacity, transform; will-change: transform, opacity;
} }
.zeitfresser-floating-toc.is-visible{ .zeitfresser-floating-toc.is-visible{