Skip to content
Merged
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
22 changes: 13 additions & 9 deletions htdocs/js/apps/MathQuill/mqeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@
{ id: 'text', latex: '\\text', tooltip: 'text mode (")', icon: 'Tt' }
];

answerQuill.hasFocus = false;

// Open the toolbar when the mathquill answer box gains focus.
answerQuill.textarea.addEventListener('focusin', () => {
answerQuill.hasFocus = true;
if (answerQuill.toolbar) return;

answerQuill.toolbar = document.createElement('div');
Expand Down Expand Up @@ -114,6 +117,7 @@
}));

button.addEventListener('click', () => {
answerQuill.hasFocus = true;
answerQuill.mathField.cmd(button.dataset.latex);
answerQuill.textarea.focus();
})
Expand All @@ -136,15 +140,15 @@
});

answerQuill.textarea.addEventListener('focusout', (e) => {
if (e.relatedTarget && (e.relatedTarget.closest('.quill-toolbar') ||
e.relatedTarget.classList.contains('symbol-button')))
return;
if (answerQuill.toolbar) {
window.removeEventListener('resize', answerQuill.toolbar.adjustWidth);
answerQuill.toolbar.tooltips.forEach((tooltip) => tooltip.dispose());
answerQuill.toolbar.remove();
delete answerQuill.toolbar;
}
answerQuill.hasFocus = false;
setTimeout(function() {
if (!answerQuill.hasFocus && answerQuill.toolbar) {
window.removeEventListener('resize', answerQuill.toolbar.adjustWidth);
answerQuill.toolbar.tooltips.forEach((tooltip) => tooltip.dispose());
answerQuill.toolbar.remove();
delete answerQuill.toolbar;
}
}, 200);
});

// Trigger an answer preview when the enter key is pressed in an answer box.
Expand Down