Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated knowl.js for MathJax compatibility of hidden content #2247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions js_lib/knowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class SlideRevealer {
this.animatedElement.setAttribute("open","");
this.triggerElement.setAttribute("open","");
this.contentElement.style.display = '';
// Wait for the next frame to call the toggle function
window.requestAnimationFrame(() => this.toggle(true));
// Trigger the animation to expand or collapse the knowl.
// Delay the MathJax typesetting until the knowl is visible to ensure proper measurements
// are taken, but before the unrolling begins. This helps avoid layout shifts and ensures
// smooth animation with correctly sized content.
MathJax.typesetPromise().then(() => window.requestAnimationFrame(() => this.toggle(true)));
} else if (this.animationState === SlideRevealer.STATE.EXPANDING || this.animatedElement.hasAttribute("open")) {
this.toggle(false);
}
Expand Down Expand Up @@ -312,7 +315,6 @@ class LinkKnowl {
this.outputElement.append(...children);

// render any knowls and mathjax in the knowl
MathJax.typesetPromise([this.outputElement]);
addKnowls(this.outputElement);

// force any scripts (e.g. sagecell) to execute by evaling them
Expand Down