Merge branch 'MDL-79264-MOODLE_401_STABLE' of https://github.com/geichelberger/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols
2023-09-08 22:22:59 +08:00
committed by Jun Pataleta
3 changed files with 16 additions and 12 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+14 -10
View File
@@ -24,7 +24,7 @@
import EquationModal from 'tiny_equation/modal';
import ModalFactory from 'core/modal_factory';
import ModalEvents from 'core/modal_events';
import {getLibraries, getTexDocsUrl} from 'tiny_equation/options';
import {getContextId, getLibraries, getTexDocsUrl} from 'tiny_equation/options';
import {notifyFilterContentUpdated} from 'core/event';
import * as TinyEquationRepository from 'tiny_equation/repository';
import {exception as displayException} from 'core/notification';
@@ -65,15 +65,17 @@ const displayDialogue = async(editor) => {
const root = $root[0];
currentForm = root.querySelector(Selectors.elements.form);
const contextId = getContextId(editor);
$root.on(ModalEvents.hidden, () => {
modalPromises.destroy();
});
$root.on(ModalEvents.shown, () => {
const library = root.querySelector(Selectors.elements.library);
TinyEquationRepository.filterEquation(1, library.innerHTML).then(async data => {
TinyEquationRepository.filterEquation(contextId, library.innerHTML).then(async data => {
library.innerHTML = data.content;
updatePreview();
updatePreview(contextId);
notifyFilter(library);
return data;
}).catch(displayException);
@@ -85,7 +87,7 @@ const displayDialogue = async(editor) => {
const textArea = e.target.closest('.tiny_equation_equation');
if (libraryItem) {
e.preventDefault();
selectLibraryItem(libraryItem);
selectLibraryItem(libraryItem, contextId);
}
if (submitAction) {
e.preventDefault();
@@ -93,14 +95,14 @@ const displayDialogue = async(editor) => {
modalPromises.destroy();
}
if (textArea) {
debounce(updatePreview(), 500);
debounce(updatePreview(contextId), 500);
}
});
root.addEventListener('keyup', (e) => {
const textArea = e.target.closest(Selectors.elements.equationTextArea);
if (textArea) {
debounce(updatePreview(), 500);
debounce(updatePreview(contextId), 500);
}
});
@@ -135,8 +137,9 @@ const getTemplateContext = (editor, data) => {
/**
* Handle select library item.
* @param {Object} libraryItem
* @param {number} contextId
*/
const selectLibraryItem = (libraryItem) => {
const selectLibraryItem = (libraryItem, contextId) => {
const tex = libraryItem.getAttribute('data-tex');
const input = currentForm.querySelector(Selectors.elements.equationTextArea);
let oldValue;
@@ -162,13 +165,14 @@ const selectLibraryItem = (libraryItem) => {
input.selectionStart = input.selectionEnd = focusPoint;
updatePreview();
updatePreview(contextId);
};
/**
* Update the preview section.
* @param {number} contextId
*/
const updatePreview = () => {
const updatePreview = (contextId) => {
const textarea = currentForm.querySelector(Selectors.elements.equationTextArea);
const preview = currentForm.querySelector(Selectors.elements.preview);
const prefix = '';
@@ -206,7 +210,7 @@ const updatePreview = () => {
equation = prefix + equation.substring(0, currentPos) + cursorLatex + equation.substring(currentPos);
equation = Selectors.delimiters.start + ' ' + equation + ' ' + Selectors.delimiters.end;
TinyEquationRepository.filterEquation(1, equation).then((data) => {
TinyEquationRepository.filterEquation(contextId, equation).then((data) => {
preview.innerHTML = data.content;
notifyFilter(preview);