mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-02-02 11:32:30 -06:00
Merge pull request #1526 from nunocoracao/1521-zen-mode-doenst-work-when-toc-is-disabled
🐛 fix https://github.com/nunocoracao/blowfish/issues/1521
This commit is contained in:
commit
ef71d07bc3
2 changed files with 43 additions and 41 deletions
|
@ -1,57 +1,59 @@
|
||||||
function _toogleZenMode(zendModeButton) {
|
function _toogleZenMode(zendModeButton) {
|
||||||
// Nodes selection
|
// Nodes selection
|
||||||
const body = document.querySelector('body');
|
const body = document.querySelector('body');
|
||||||
const tocRight = document.querySelector('.toc-right');
|
const tocRight = document.querySelector('.toc-right');
|
||||||
const tocInside = document.querySelector('.toc-inside');
|
const tocInside = document.querySelector('.toc-inside');
|
||||||
const articleContent = document.querySelector('.article-content');
|
const articleContent = document.querySelector('.article-content');
|
||||||
const header = document.querySelector('#single_header');
|
const header = document.querySelector('#single_header');
|
||||||
|
|
||||||
|
|
||||||
// Add semantic class into body tag
|
// Add semantic class into body tag
|
||||||
body.classList.toggle('zen-mode-enable');
|
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');
|
tocRight.classList.toggle('lg:block');
|
||||||
|
if (tocInside)
|
||||||
tocInside.classList.toggle('lg:hidden');
|
tocInside.classList.toggle('lg:hidden');
|
||||||
|
|
||||||
// Change width of article content
|
// Change width of article content
|
||||||
articleContent.classList.toggle('max-w-fit');
|
articleContent.classList.toggle('max-w-fit');
|
||||||
articleContent.classList.toggle('max-w-prose');
|
articleContent.classList.toggle('max-w-prose');
|
||||||
|
|
||||||
// Read i18n title from data-attributes
|
// Read i18n title from data-attributes
|
||||||
const titleI18nDisable = zendModeButton.getAttribute('data-title-i18n-disable');
|
const titleI18nDisable = zendModeButton.getAttribute('data-title-i18n-disable');
|
||||||
const titleI18nEnable = zendModeButton.getAttribute('data-title-i18n-enable');
|
const titleI18nEnable = zendModeButton.getAttribute('data-title-i18n-enable');
|
||||||
|
|
||||||
if (body.classList.contains('zen-mode-enable')) {
|
if (body.classList.contains('zen-mode-enable')) {
|
||||||
// Persist configuration
|
// Persist configuration
|
||||||
//localStorage.setItem('blowfish-zen-mode-enabled', 'true');
|
//localStorage.setItem('blowfish-zen-mode-enabled', 'true');
|
||||||
|
|
||||||
// Change title to enable
|
// Change title to enable
|
||||||
zendModeButton.setAttribute('title', titleI18nEnable)
|
zendModeButton.setAttribute('title', titleI18nEnable)
|
||||||
// Auto-scroll to title article
|
// Auto-scroll to title article
|
||||||
window.scrollTo(window.scrollX, header.getBoundingClientRect().top - 90);
|
window.scrollTo(window.scrollX, header.getBoundingClientRect().top - 90);
|
||||||
} else {
|
} else {
|
||||||
//localStorage.setItem('blowfish-zen-mode-enabled', 'false');
|
//localStorage.setItem('blowfish-zen-mode-enabled', 'false');
|
||||||
zendModeButton.setAttribute('title', titleI18nDisable);
|
zendModeButton.setAttribute('title', titleI18nDisable);
|
||||||
document.querySelector('body').scrollIntoView();
|
document.querySelector('body').scrollIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _registerZendModeButtonClick(zendModeButton) {
|
function _registerZendModeButtonClick(zendModeButton) {
|
||||||
zendModeButton.addEventListener('click', function (event) {
|
zendModeButton.addEventListener('click', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Toggle zen-mode
|
// Toggle zen-mode
|
||||||
_toogleZenMode(zendModeButton);
|
_toogleZenMode(zendModeButton);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
(function init() {
|
(function init() {
|
||||||
window.addEventListener("DOMContentLoaded", (event) => {
|
window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
// Register click on 'zen-mode-button' node element
|
// Register click on 'zen-mode-button' node element
|
||||||
const zendModeButton = document.getElementById('zen-mode-button');
|
const zendModeButton = document.getElementById('zen-mode-button');
|
||||||
if(zendModeButton !== null && zendModeButton !== undefined) {
|
if (zendModeButton !== null && zendModeButton !== undefined) {
|
||||||
_registerZendModeButtonClick(zendModeButton);
|
_registerZendModeButtonClick(zendModeButton);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
|
@ -67,7 +67,7 @@ smartTOCHideUnfocusedChildren = false
|
||||||
showPagination = true
|
showPagination = true
|
||||||
invertPagination = false
|
invertPagination = false
|
||||||
showReadingTime = true
|
showReadingTime = true
|
||||||
showTableOfContents = true
|
showTableOfContents = false
|
||||||
showRelatedContent = true
|
showRelatedContent = true
|
||||||
relatedContentLimit = 6
|
relatedContentLimit = 6
|
||||||
showTaxonomies = true
|
showTaxonomies = true
|
||||||
|
|
Loading…
Reference in a new issue