Display highlight elements in CKEditor cases.
This commit is contained in:
		@@ -11,6 +11,7 @@ class BesEditor {
 | 
				
			|||||||
    this.correctionPanel = correctionPanel
 | 
					    this.correctionPanel = correctionPanel
 | 
				
			||||||
    this.scrollPanel = scrollPanel
 | 
					    this.scrollPanel = scrollPanel
 | 
				
			||||||
    this.offsetTop = null
 | 
					    this.offsetTop = null
 | 
				
			||||||
 | 
					    this.isCKeditor = false
 | 
				
			||||||
    this.disableSpellcheck(edit)
 | 
					    this.disableSpellcheck(edit)
 | 
				
			||||||
    this.proof(edit)
 | 
					    this.proof(edit)
 | 
				
			||||||
    edit.addEventListener('beforeinput', e => this.handleBeforeInput(e), false)
 | 
					    edit.addEventListener('beforeinput', e => this.handleBeforeInput(e), false)
 | 
				
			||||||
@@ -21,9 +22,10 @@ class BesEditor {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Register editor
 | 
					  // Register editor
 | 
				
			||||||
  static register(edit) {
 | 
					  static register(edit, isCkeditor) {
 | 
				
			||||||
    let editor = new BesEditor(edit)
 | 
					    let editor = new BesEditor(edit)
 | 
				
			||||||
    besEditors.push(editor)
 | 
					    besEditors.push(editor)
 | 
				
			||||||
 | 
					    if (isCkeditor) editor.isCKeditor = true
 | 
				
			||||||
    return editor
 | 
					    return editor
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -145,6 +147,12 @@ class BesEditor {
 | 
				
			|||||||
                  })
 | 
					                  })
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                this.markProofed(el, matches)
 | 
					                this.markProofed(el, matches)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // This is a solution for CKEditor. It is not the best solution, but it works for now.
 | 
				
			||||||
 | 
					                if (this.isCKeditor) {
 | 
				
			||||||
 | 
					                  const resizeEvent = new Event('resize')
 | 
				
			||||||
 | 
					                  window.dispatchEvent(resizeEvent)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
              })
 | 
					              })
 | 
				
			||||||
              .catch(error => {
 | 
					              .catch(error => {
 | 
				
			||||||
                // TODO: Make parsing issues non-fatal. But show an error sign somewhere in the UI.
 | 
					                // TODO: Make parsing issues non-fatal. But show an error sign somewhere in the UI.
 | 
				
			||||||
@@ -278,6 +286,7 @@ class BesEditor {
 | 
				
			|||||||
  // Adds grammar mistake markup
 | 
					  // Adds grammar mistake markup
 | 
				
			||||||
  addMistakeMarkup(range, scrollPanel) {
 | 
					  addMistakeMarkup(range, scrollPanel) {
 | 
				
			||||||
    // TODO: Consider using range.getClientRects() instead of range.getBoundingClientRect()
 | 
					    // TODO: Consider using range.getClientRects() instead of range.getBoundingClientRect()
 | 
				
			||||||
 | 
					    // In CKEditor case, the highlight element is not shown for some reason. But after resizing the window it is shown.
 | 
				
			||||||
    const clientRects = range.getClientRects()
 | 
					    const clientRects = range.getClientRects()
 | 
				
			||||||
    const scrollPanelRect = scrollPanel.getBoundingClientRect()
 | 
					    const scrollPanelRect = scrollPanel.getBoundingClientRect()
 | 
				
			||||||
    const highlight = document.createElement('div')
 | 
					    const highlight = document.createElement('div')
 | 
				
			||||||
@@ -523,6 +532,12 @@ window.onload = () => {
 | 
				
			|||||||
  document
 | 
					  document
 | 
				
			||||||
    .querySelectorAll('.bes-online-editor')
 | 
					    .querySelectorAll('.bes-online-editor')
 | 
				
			||||||
    .forEach(edit => BesEditor.register(edit))
 | 
					    .forEach(edit => BesEditor.register(edit))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // TODO: not the most optimal solution, but it works for now
 | 
				
			||||||
 | 
					  // Find contenteditable element inside ckeditor and prepare it
 | 
				
			||||||
 | 
					  document.querySelectorAll('.ck-editor__editable').forEach(edit => {
 | 
				
			||||||
 | 
					    BesEditor.register(edit, true)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.onresize = () => {
 | 
					window.onresize = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user