Rework the MathJax.typesetPromise usage.#1431
Conversation
Alex-Jordan
left a comment
There was a problem hiding this comment.
I'm not seeing any issues from using this branch. I'm not sure what to look at for testing. But I'll mark it as approved.
|
I still think that using the Instead, I'd suggest using the Then in If you really want to avoid jitter from MathJax's typesetting of expressions, not just in popovers, but in the page itself, you could add document.querySelector('#problem_body').style.visibility="hidden";to the bottom of the pageReady() {
return MathJax.startup.defaultPageReady()
.then(() => document.querySelector('#problem_body').style.visibility='');
},into the |
The `MathJax.typesetPromise` calls no longer need to be passed through the `MathJax.startupPromise` according to @dpvc. See his comments on this in openwebwork/webwork2#2955. Also, make the `MathJax.typesetPromise` calls to typeset popover contents specific to the particular popover that needs to be typeset instead of typesetting all popovers in the page. This is not done in the way that @dpvc suggested because moving the typesetting from the `show.bs.popover` event to the `shown.bs.popover` event results in visual motion as the popover is typeset and possibly resized, and that is not desirable. Instead a timeout is used. This works because Bootstrap creates the `popover.tip` element immediately after Bootstrap triggers the `show.bs.popover` event, and so when the timeout handler is executed it is available to work with. But that is still before the css transitions are complete which is when the `shown.bs.popover` event is triggered. Note that in `htdocs/js/Knowls/knowl.js` and `htdocs/js/DragNDrop/dragndrop.js`, the `typesetPromise` method is often not yet defined on the `MathJax` object when those calls are made. That is okay, because if it isn't yet defined, that means that MathJax is still typesetting the page, and gets those elements. Generally the call is only needed for cases where those things are added to the page later.
…event. This is certainly better than a timeout, and I don't know how I missed that event. To be honest I didn't know it existed and have missed it in the documentation for years. Thanks @dpvc for pointing this out.
f2bae2e to
52c8539
Compare
|
I switched to the the |
dpvc
left a comment
There was a problem hiding this comment.
Looks good, with one question about an update that might not be needed.
| } | ||
| feedbackBtn.addEventListener('inserted.bs.popover', () => { | ||
| // Render MathJax previews. | ||
| if (window.MathJax) MathJax.typesetPromise([feedbackPopover.tip]).then(() => feedbackPopover.update()); |
There was a problem hiding this comment.
I haven't tested it, but I wonder if the popover update is still needed, as it hasn't been shown, yet, and showing it may get the position/size right automatically. Just a thought.
I didn't know about it, either, but hoped there might be one for "created but not yet shown", and so looked for the list of events, and there it was! |
|
Yeah, I might have missed it partially due to the order they list the events in the documentation. The |
|
I will check on if the |
Agreed. That would make things clearer. |
I am seeing several instances where the function is not defined. So protect against calling it if it isn't. Presumably the cases where it is not defined will still be caught by the initial typeset.
|
I added protection against calling the Also, it seems that the |
|
OK, sounds good. Thanks for checking! |
This was suggested by @dpvc in openwebwork/pg#1431. The point is to prevent the visual motion that occurs while the MathJax content is rendered. This doesn't use the `#problem_body` id selector since that is not on all problems (it isn't in Gateway tests), but uses the `.problem-content` class selector instead, since that is on all problems. Also, a `for of` loop and `document.querySelectorAll` is needed for tests, since there can be more than one problem. I am not entirely sold on the empty area shown in the mean time, but it does prevent the jitter for the text within the problem. Perhaps if someone wants to toy with css, a loading block could be shown with a transition that fades in the problem when the MathJax rendering is completed. Note that webwork2 renders MathJax in places outside of the problem content, and those will not be affected by this.
somiaj
left a comment
There was a problem hiding this comment.
A quick test of various rendering, popups, and everything worked. There are multiple approvals, but some changes since the last one, I'm going to merge soon so it can get more testing.
The
MathJax.typesetPromisecalls no longer need to be passed through theMathJax.startupPromiseaccording to @dpvc. See his comments on this in openwebwork/webwork2#2955.Also, make the
MathJax.typesetPromisecalls to typeset popover contents specific to the particular popover that needs to be typeset instead of typesetting all popovers in the page. This is not done in the way that @dpvc suggested because moving the typesetting from theshow.bs.popoverevent to theshown.bs.popoverevent results in visual motion as the popover is typeset and possibly resized, and that is not desirable. Instead a timeout is used. This works because Bootstrap creates thepopover.tipelement immediately after Bootstrap triggers theshow.bs.popoverevent, and so when the timeout handler is executed it is available to work with. But that is still before the css transitions are complete which is when theshown.bs.popoverevent is triggered.Note that in
htdocs/js/Knowls/knowl.jsandhtdocs/js/DragNDrop/dragndrop.js, thetypesetPromisemethod is often not yet defined on theMathJaxobject when those calls are made. That is okay, because if it isn't yet defined, that means that MathJax is still typesetting the page, and gets those elements. Generally the call is only needed for cases where those things are added to the page later.