Skip to content

Commit

Permalink
fix issue Insert equation in question text #15 - thanks to mwehr
Browse files Browse the repository at this point in the history
srobotta committed Sep 6, 2023
1 parent 4eca8a4 commit 325d172
Showing 7 changed files with 15 additions and 47 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -105,6 +105,11 @@ at https://docs.moodle.org/en/Multi-language_content_filter.

## History

### current master
- Fix issue [Insert equation in question text](https://github.com/srobotta/moodle-tiny_cloze/issues/15).
Credits to that fix actually go to [Mario Wehr](https://github.com/mwehr) because of his
[contribution in this pull request](https://github.com/bfh/moodle-tiny_multilang2/pull/5)

### v1.1
- Fix source code view, special html was not always formatted correctly.

2 changes: 1 addition & 1 deletion amd/build/commands.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/commands.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/ui.min.js.map

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions amd/src/commands.js
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import {
clozeeditButtonName,
icon,
} from './common';
import {displayDialogue, resolveSubquestion, onInit, onBeforeGetContent, onPreProcess, onPostProcess, onBlur} from './ui';
import {displayDialogue, resolveSubquestion, onInit, onBeforeGetContent, onSubmit} from './ui';

/**
* Get the setup function for the buttons.
@@ -81,8 +81,6 @@ export const getSetup = async() => {

editor.on('init', () => onInit(editor));
editor.on('BeforeGetContent', format => onBeforeGetContent(format));
editor.on('PreProcess', format => onPreProcess(format));
editor.on('PostProcess', format => onPostProcess(format));
editor.on('blur', () => onBlur());
editor.on('submit', () => onSubmit());
};
};
43 changes: 4 additions & 39 deletions amd/src/ui.js
Original file line number Diff line number Diff line change
@@ -379,13 +379,6 @@ const getQuestionTypes = function() {
*/
let _editor = null;

/**
* Remember the blur event to reapply the marker <span>s because they get lost in the first place.
* @type boolean
* @private
*/
let _isBlurred = false;

/**
* A reference to the currently open form.
*
@@ -588,36 +581,10 @@ const onBeforeGetContent = function(content) {
};

/**
* When the content is supposed to be saved (happens also when the editor window is blurred)
* then we need to remove or markers (e.g. <span> elements that encapsulate the cloze
* question strings).
* @param {object} content
*/
const onPreProcess = function(content) {
if (!isNull(content.save) && content.save === true && !_modal) {
// Remove markers only if modal is not called, otherwise we will lose our new question marker.
_removeMarkers();
}
};

/**
* When the blur event was triggered, the editor is still there, we need to reapply
* the previously removed styling. If this was a submit event, then do not reapply the
* styling to prevent that this is saved in the database.
* @param {object} content
*/
const onPostProcess = function(content) {
if (!isNull(content.save) && content.save === true && _isBlurred) {
_addMarkers();
_isBlurred = false;
}
};

/**
* Notice when the editor content is blurred, because the focus left the editor window.
* Fires when the form containing the editor is submitted.
*/
const onBlur = function() {
_isBlurred = true;
const onSubmit = function() {
_removeMarkers();
};

/**
@@ -1022,7 +989,5 @@ export {
resolveSubquestion,
onInit,
onBeforeGetContent,
onPreProcess,
onPostProcess,
onBlur
onSubmit,
};

0 comments on commit 325d172

Please sign in to comment.