Skip to content

Commit

Permalink
🐛 Fix: take a dirty hack to fix the bug of APlayer and smoothScroll
Browse files Browse the repository at this point in the history
Fixed #292
  • Loading branch information
Lruihao committed Jul 24, 2024
1 parent 99dc099 commit 4666125
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ class FixIt {
return;
}
// It's a dirty hack to fix the bug of APlayer, see https://github.com/hugo-fixit/FixIt/issues/292
if (typeof APlayer === 'function') {
const $newTocCore = $tocCore.cloneNode(true);
$tocCore.parentElement.replaceChild($newTocCore, $tocCore);
$tocCore = $newTocCore;
}
// if (typeof APlayer === 'function') {
// const $newTocCore = $tocCore.cloneNode(true);
// $tocCore.parentElement.replaceChild($newTocCore, $tocCore);
// $tocCore = $newTocCore;
// }
if (document.getElementById('toc-static').dataset.kept === 'true' || this.util.isTocStatic()) {
const $tocContentStatic = document.getElementById('toc-content-static');
if ($tocCore.parentElement !== $tocContentStatic) {
Expand Down Expand Up @@ -579,6 +579,25 @@ class FixIt {
}, false);
}

/**
* It's a dirty hack to fix the bug of APlayer and smoothScroll.
* see https://github.com/hugo-fixit/FixIt/issues/292
*/
fixTocScroll() {
if (typeof APlayer === 'function') {
// remove APlayer click event listener of the toc link
let $tocCore = document.getElementById('TableOfContents');
const $newTocCore = $tocCore.cloneNode(true);
$tocCore.parentElement.replaceChild($newTocCore, $tocCore);
$tocCore = $newTocCore;
// remove APlayer click event listener of the heading mark
this.util.forEach(document.querySelectorAll('.heading-mark'), ($headingMark) => {
const $newHeadingMark = $headingMark.cloneNode(true);
$headingMark.parentElement.replaceChild($newHeadingMark, $headingMark);
});
}
}

initMath(target = document.body) {
if (this.config.math) {
renderMathInElement(target, this.config.math);
Expand Down Expand Up @@ -1000,6 +1019,7 @@ class FixIt {
this.initToc();
this.initTocListener();
this.initPangu();
this.fixTocScroll();
this.util.forEach(document.querySelectorAll('.encrypted-hidden'), ($element) => {
$element.classList.replace('encrypted-hidden', 'decrypted-shown');
});
Expand Down Expand Up @@ -1257,6 +1277,7 @@ class FixIt {
if (!this.config.encryption?.all) {
this.initToc();
this.initTocListener();
this.fixTocScroll();
}
this.onScroll();
this.onResize();
Expand Down

0 comments on commit 4666125

Please sign in to comment.