Allow post-window.onload editor registration
This allows grammar-checking support setup for contentEditable <div>s added to the DOM tree later.
This commit is contained in:
parent
494107bafb
commit
81240397d7
@ -1,5 +1,7 @@
|
||||
const besUrl = 'http://localhost:225/api/v2/check'
|
||||
|
||||
let besEditors = [] // Collection of all editors on page
|
||||
|
||||
class BesEditor {
|
||||
constructor(edit) {
|
||||
this.el = edit
|
||||
@ -11,6 +13,13 @@ class BesEditor {
|
||||
edit.addEventListener('click', e => this.handleClick(e))
|
||||
}
|
||||
|
||||
// Register editor
|
||||
static register(edit) {
|
||||
let editor = new BesEditor(edit)
|
||||
besEditors.push(editor)
|
||||
return editor
|
||||
}
|
||||
|
||||
// Recursively grammar-proofs one node.
|
||||
async proof(el) {
|
||||
switch (el.nodeType) {
|
||||
@ -317,14 +326,11 @@ class BesEditor {
|
||||
}
|
||||
}
|
||||
|
||||
let besEditors = [] // Collection of all editors on page
|
||||
|
||||
window.onload = () => {
|
||||
// Search and prepare all our editors found in the document.
|
||||
document.querySelectorAll('.bes-online-editor').forEach(edit => {
|
||||
let editor = new BesEditor(edit)
|
||||
besEditors.push(editor)
|
||||
})
|
||||
document
|
||||
.querySelectorAll('.bes-online-editor')
|
||||
.forEach(edit => BesEditor.register(edit))
|
||||
}
|
||||
|
||||
window.onresize = () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user