diff --git a/online-editor.js b/online-editor.js index 60fde9c..a9bd9cb 100644 --- a/online-editor.js +++ b/online-editor.js @@ -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 = () => {