Skip to content

Commit

Permalink
fix: mathjax resize on sindow resize (openedx#32606)
Browse files Browse the repository at this point in the history
* fix: mathjax resize on sindow resize

* fix: add resize for mathjax in wiki and cms
  • Loading branch information
muselesscreator authored Jul 5, 2023
1 parent 810bf97 commit a68fd49
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cms/templates/content_libraries/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<!-- Configure and load MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%' },
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {
inlineMath: [
["\\(","\\)"],
Expand All @@ -92,6 +98,18 @@
]
}
});
window.addEventListener('resize', MJrenderer);
let 1 = -1;
let delay = 1000;
function MJrenderer() {
if (t >= 0) {
window.clearTimeout(t);
}
t = window.setTimeout(function() {
MathJax.Hub.Queue(["Rerenderer", MathJax.Hub]);
t = -1;
}, delay);
};
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.signal.Interest(function(message) {
Expand Down
27 changes: 27 additions & 0 deletions common/templates/mathjax_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@
%if mathjax_mode is not Undefined and mathjax_mode == 'wiki':
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {inlineMath: [ ['$','$'], ["\\(","\\)"]],
displayMath: [ ['$$','$$'], ["\\[","\\]"]]}
});
</script>
%else:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
},
messageStyle: "none",
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {
inlineMath: [
["\\(","\\)"],
Expand Down Expand Up @@ -85,6 +97,21 @@
explorer: true
}
};
window.addEventListener('resize', MJrerender);

let t = -1;
let delay = 1000;
function MJrerender() {
if (t >= 0) {
// If we are still waiting, then the user is still resizing =>
// postpone the action further!
window.clearTimeout(t);
}
t = window.setTimeout(function() {
MathJax.Hub.Queue(["Rerender",MathJax.Hub]);
t = -1; // Reset the handle
}, delay);
};
</script>

<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates.
Expand Down

0 comments on commit a68fd49

Please sign in to comment.