Skip to content

Commit 4d030b5

Browse files
committed
Hmm.
1 parent 44e370e commit 4d030b5

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

htdocs/js/MathJaxConfig/mathjax-config.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
if (!window.MathJax) {
2+
const problems = [];
3+
24
window.MathJax = {
35
tex: { packages: { '[+]': webworkConfig?.showMathJaxErrors ? [] : ['noerrors'] } },
46
loader: {
@@ -106,9 +108,12 @@ if (!window.MathJax) {
106108
},
107109
pageReady() {
108110
return MathJax.startup.defaultPageReady().then(() => {
109-
for (const problemBody of document.querySelectorAll('.problem-content')) {
110-
problemBody.style.visibility = '';
111+
for (const [problemContent, loaderOverlay, resizeObserver] of problems) {
112+
resizeObserver.disconnect();
113+
loaderOverlay.remove();
114+
problemContent.style.visibility = '';
111115
}
116+
problems.length = 0;
112117
});
113118
}
114119
},
@@ -142,7 +147,34 @@ if (!window.MathJax) {
142147
}
143148
};
144149

145-
for (const problemBody of document.querySelectorAll('.problem-content')) {
146-
problemBody.style.visibility = 'hidden';
150+
for (const problemContent of document.querySelectorAll('.problem-content')) {
151+
problemContent.style.visibility = 'hidden';
152+
const loaderOverlay = document.createElement('div');
153+
loaderOverlay.classList.add('problem-content');
154+
const bodyRectangle = problemContent.getBoundingClientRect();
155+
loaderOverlay.style.position = 'absolute';
156+
loaderOverlay.style.top = `${bodyRectangle.y}px`;
157+
loaderOverlay.style.left = `${bodyRectangle.x}px`;
158+
loaderOverlay.style.width = `${bodyRectangle.width}px`;
159+
loaderOverlay.style.height = `${bodyRectangle.height}px`;
160+
loaderOverlay.style.overflow = 'clip';
161+
loaderOverlay.style.transition = 'height 0.3s ease';
162+
loaderOverlay.animate([{ opacity: 1 }, { opacity: 0.2 }, { opacity: 1 }], {
163+
duration: 1000,
164+
iterations: Infinity,
165+
easing: 'ease-in-out'
166+
});
167+
loaderOverlay.style.cursor = 'wait';
168+
169+
problemContent.after(loaderOverlay);
170+
const resizeObserver = new ResizeObserver(() => {
171+
const bodyRectangle = problemContent.getBoundingClientRect();
172+
loaderOverlay.style.top = `${bodyRectangle.top}px`;
173+
loaderOverlay.style.left = `${bodyRectangle.left}px`;
174+
loaderOverlay.style.width = `${bodyRectangle.width}px`;
175+
loaderOverlay.style.height = `${bodyRectangle.height}px`;
176+
});
177+
resizeObserver.observe(problemContent);
178+
problems.push([problemContent, loaderOverlay, resizeObserver]);
147179
}
148180
}

0 commit comments

Comments
 (0)