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