Skip to content

Commit fd0cbcb

Browse files
committed
Hmm.
1 parent 44e370e commit fd0cbcb

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

htdocs/js/MathJaxConfig/mathjax-config.js

Lines changed: 47 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,45 @@ 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+
163+
loaderOverlay.classList.add(
164+
'd-flex',
165+
'flex-column',
166+
'justify-content-start',
167+
'align-items-center',
168+
'text-dark'
169+
);
170+
171+
const loaderText = document.createElement('div');
172+
loaderText.textContent = 'Loading...';
173+
loaderText.classList.add('fs-1');
174+
175+
const loaderIcon = document.createElement('i');
176+
loaderIcon.classList.add('fa-solid', 'fa-spinner', 'fa-spin', 'fa-2x');
177+
178+
loaderOverlay.append(loaderText, loaderIcon);
179+
180+
problemContent.after(loaderOverlay);
181+
const resizeObserver = new ResizeObserver(() => {
182+
const bodyRectangle = problemContent.getBoundingClientRect();
183+
loaderOverlay.style.top = `${bodyRectangle.top}px`;
184+
loaderOverlay.style.left = `${bodyRectangle.left}px`;
185+
loaderOverlay.style.width = `${bodyRectangle.width}px`;
186+
loaderOverlay.style.height = `${bodyRectangle.height}px`;
187+
});
188+
resizeObserver.observe(problemContent);
189+
problems.push([problemContent, loaderOverlay, resizeObserver]);
147190
}
148191
}

0 commit comments

Comments
 (0)