MDL-75244 form: Change checker should check existence of tinyMCE API

The window.tinyMCE.editors API was present in version 3 of TinyMCE, but
is not present in later versions. As a result, this check tries to loop
over a variable which does not exist and throws an error in the process.

We should check that window.tinyMCE *and* window.tinyMCE.editors both
exist before attempting to loop over them.
This commit is contained in:
Andrew Nicols 2022-07-19 12:37:49 +08:00
parent 4ce642e8ba
commit c48c431374
3 changed files with 3 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -272,7 +272,7 @@ export const isAnyWatchedFormDirty = () => {
// Handle TinyMCE editor instances.
// TinyMCE forms may not have been initialised at the time that startWatching is called.
// Check whether any tinyMCE editor is dirty.
if (typeof window.tinyMCE !== 'undefined') {
if (typeof window.tinyMCE !== 'undefined' && window.tinyMCE.editors) {
if (window.tinyMCE.editors.some(editor => editor.isDirty())) {
return true;
}