diff options
author | Brian Cully <bjc@kublai.com> | 2021-02-17 21:40:03 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2021-02-17 21:40:28 -0500 |
commit | 4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d (patch) | |
tree | 35c929036f31e9e1c641ea1b007432aedf373166 /error.mjs | |
download | molsim2-4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d.tar.gz molsim2-4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d.zip |
Initial commit.
Diffstat (limited to 'error.mjs')
-rw-r--r-- | error.mjs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/error.mjs b/error.mjs new file mode 100644 index 0000000..535a956 --- /dev/null +++ b/error.mjs @@ -0,0 +1,55 @@ +class Error { + constructor(elt) { + this.elt = elt + + this._boundClickHandler = this.clickHandler.bind(this) + this.button.addEventListener('click', this._boundClickHandler) + } + + get errorElt() { + if (this._errorElt === undefined) { + this._errorElt = this.elt.querySelector('p') + } + return this._errorElt + } + + get button() { + if (this._button === undefined) { + this._button = this.elt.querySelector('button') + } + return this._button + } + + get innerHTML() { + return this.errorElt.tinnerHTML + } + + set innerHTML(html) { + this.errorElt.innerHTML = html + } + + get onClick() { + if (this._onClick !== undefined) { + return this._onClick + } + return () => {} + } + + set onClick(fn) { + this._onClick = fn + } + + show() { + this.elt.classList.remove('hidden') + } + + hide() { + this.elt.classList.add('hidden') + } + + clickHandler() { + this.onClick() + } +} + +export default Error |