From 9c5b68fb22566a58320c2d39cdc56d8fdd44df67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Sat, 8 Jun 2024 12:20:26 +0100 Subject: [PATCH] fix https://github.com/nunocoracao/blowfish/issues/1521 --- assets/js/zen-mode.js | 82 +++++++++++++------------ exampleSite/config/_default/params.toml | 2 +- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/assets/js/zen-mode.js b/assets/js/zen-mode.js index 62ccc665..0da48428 100644 --- a/assets/js/zen-mode.js +++ b/assets/js/zen-mode.js @@ -1,57 +1,59 @@ function _toogleZenMode(zendModeButton) { - // Nodes selection - const body = document.querySelector('body'); - const tocRight = document.querySelector('.toc-right'); - const tocInside = document.querySelector('.toc-inside'); - const articleContent = document.querySelector('.article-content'); - const header = document.querySelector('#single_header'); + // Nodes selection + const body = document.querySelector('body'); + const tocRight = document.querySelector('.toc-right'); + const tocInside = document.querySelector('.toc-inside'); + const articleContent = document.querySelector('.article-content'); + const header = document.querySelector('#single_header'); - // Add semantic class into body tag - body.classList.toggle('zen-mode-enable'); + // Add semantic class into body tag + body.classList.toggle('zen-mode-enable'); - // Show/Hide 'toc right' and 'toc inside' + // Show/Hide 'toc right' and 'toc inside' + if (tocRight) tocRight.classList.toggle('lg:block'); + if (tocInside) tocInside.classList.toggle('lg:hidden'); - // Change width of article content - articleContent.classList.toggle('max-w-fit'); - articleContent.classList.toggle('max-w-prose'); + // Change width of article content + articleContent.classList.toggle('max-w-fit'); + articleContent.classList.toggle('max-w-prose'); - // Read i18n title from data-attributes - const titleI18nDisable = zendModeButton.getAttribute('data-title-i18n-disable'); - const titleI18nEnable = zendModeButton.getAttribute('data-title-i18n-enable'); + // Read i18n title from data-attributes + const titleI18nDisable = zendModeButton.getAttribute('data-title-i18n-disable'); + const titleI18nEnable = zendModeButton.getAttribute('data-title-i18n-enable'); - if (body.classList.contains('zen-mode-enable')) { - // Persist configuration - //localStorage.setItem('blowfish-zen-mode-enabled', 'true'); - - // Change title to enable - zendModeButton.setAttribute('title', titleI18nEnable) - // Auto-scroll to title article - window.scrollTo(window.scrollX, header.getBoundingClientRect().top - 90); - } else { - //localStorage.setItem('blowfish-zen-mode-enabled', 'false'); - zendModeButton.setAttribute('title', titleI18nDisable); - document.querySelector('body').scrollIntoView(); - } + if (body.classList.contains('zen-mode-enable')) { + // Persist configuration + //localStorage.setItem('blowfish-zen-mode-enabled', 'true'); + + // Change title to enable + zendModeButton.setAttribute('title', titleI18nEnable) + // Auto-scroll to title article + window.scrollTo(window.scrollX, header.getBoundingClientRect().top - 90); + } else { + //localStorage.setItem('blowfish-zen-mode-enabled', 'false'); + zendModeButton.setAttribute('title', titleI18nDisable); + document.querySelector('body').scrollIntoView(); + } } function _registerZendModeButtonClick(zendModeButton) { - zendModeButton.addEventListener('click', function (event) { - event.preventDefault(); + zendModeButton.addEventListener('click', function (event) { + event.preventDefault(); - // Toggle zen-mode - _toogleZenMode(zendModeButton); - }); + // Toggle zen-mode + _toogleZenMode(zendModeButton); + }); } (function init() { - window.addEventListener("DOMContentLoaded", (event) => { - // Register click on 'zen-mode-button' node element - const zendModeButton = document.getElementById('zen-mode-button'); - if(zendModeButton !== null && zendModeButton !== undefined) { - _registerZendModeButtonClick(zendModeButton); - } - }); + window.addEventListener("DOMContentLoaded", (event) => { + // Register click on 'zen-mode-button' node element + const zendModeButton = document.getElementById('zen-mode-button'); + if (zendModeButton !== null && zendModeButton !== undefined) { + _registerZendModeButtonClick(zendModeButton); + } + }); })(); \ No newline at end of file diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 325917e7..be71adf1 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -67,7 +67,7 @@ smartTOCHideUnfocusedChildren = false showPagination = true invertPagination = false showReadingTime = true - showTableOfContents = true + showTableOfContents = false showRelatedContent = true relatedContentLimit = 6 showTaxonomies = true