Skip to content

Commit

Permalink
fix(editor): desactivate webspellchecker if SCAYT script init fails (…
Browse files Browse the repository at this point in the history
…DEJS-1194)
  • Loading branch information
spln committed Jul 18, 2024
1 parent 00d6e05 commit dfa51a7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions projects/deja-js/component/editor/deja-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export class DejaEditorComponent extends Destroy implements OnChanges, OnInit, A
this._debounce = coerceNumberProperty(debounce);
}

private readonly errorEventListener: EventListener;

/**
* Constructor
*/
Expand All @@ -111,6 +113,20 @@ export class DejaEditorComponent extends Destroy implements OnChanges, OnInit, A
private initializer: DejaEditorService
) {
super();
this.errorEventListener = (error: ErrorEvent): any => {
if (error.message === 'Uncaught ReferenceError: SCAYT is not defined' && this.instance) {
this.instance.destroy();
this.instance = null;
const config = cloneDeep(this.config);
config.plugins = config.plugins?.split(',').filter(plugin => !plugin.includes('scayt')).join(',');
config.removePlugins = config.removePlugins ? `${config.removePlugins},scayt` : 'scayt';
/* eslint-disable camelcase */
config.scayt_autoStartup = false;
/* eslint-enable camelcase */
this.ckeditorInit(config);
}
};
window.addEventListener('error', this.errorEventListener);
}

public get value(): string {
Expand Down Expand Up @@ -166,6 +182,7 @@ export class DejaEditorComponent extends Destroy implements OnChanges, OnInit, A
this.change.complete();
this.disabled.complete();
this.instance?.destroy();
window.removeEventListener('error', this.errorEventListener);
}

/**
Expand Down

0 comments on commit dfa51a7

Please sign in to comment.