Rename and simplify constructor parameters

This commit is contained in:
Aljaž Grilc 2024-03-13 08:11:02 +01:00
parent 41c5954e89
commit dde1010026

View File

@ -3,7 +3,7 @@ const besUrl = 'http://localhost:225/api/v2/check'
let besEditors = [] // Collection of all grammar checking services in the document
class BesEditor {
constructor(edit, isCkeditor) {
constructor(edit, CKEditorInstance) {
this.el = edit
this.timer = null
this.children = []
@ -11,10 +11,8 @@ class BesEditor {
this.correctionPanel = correctionPanel
this.scrollPanel = scrollPanel
this.offsetTop = null
// TODO: consider simplfing ckeditor handling by using a single constructor parameter
this.isCKeditor = !!isCkeditor
this.CKEditorInstance = isCkeditor
edit.classList.add('bes-online-editor')
this.CKEditorInstance = CKEditorInstance
if (!this.CKEditorInstance) edit.classList.add('bes-online-editor')
this.originalSpellcheck = edit.spellcheck
edit.spellcheck = false
this.proof(edit)
@ -28,11 +26,11 @@ class BesEditor {
* Registers grammar checking service
*
* @param {Element} edit DOM element to register grammar checking service for
* @param {Boolean} isCkeditor Enable CKEditor tweaks
* @param {CKEditorInstance} CKEditorInstance Enable CKEditor tweaks
* @returns {BesEditor} Grammar checking service instance
*/
static register(edit, isCkeditor) {
return new BesEditor(edit, isCkeditor)
static register(edit, CKEditorInstance) {
return new BesEditor(edit, CKEditorInstance)
}
/**
@ -172,7 +170,7 @@ class BesEditor {
this.markProofed(el, matches)
// This is a solution for displaying mistakes in CKEditor. It is not the best solution, but it works for now.
if (this.isCKeditor) {
if (this.CKEditorInstance) {
const resizeEvent = new Event('resize')
window.dispatchEvent(resizeEvent)
}
@ -544,7 +542,7 @@ class BesEditor {
replacement +
text.substring(match.offset + match.length)
el.textContent = newText
if (editor.isCKeditor) {
if (editor.CKEditorInstance) {
const { CKEditorInstance } = editor
CKEditorInstance.model.change(writer => {
// Find the corresponding element in the model.