summaryrefslogtreecommitdiffstats
path: root/error.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-01-03 18:34:19 -0500
committerBrian Cully <bjc@kublai.com>2021-02-06 10:39:32 -0500
commite92ad9f4b19a0670a80cdd293970c3a08c27a8b4 (patch)
treee8659dcdbf5f7ba3c55a118909d82dd8f0d0bcbd /error.mjs
downloadmolsim-e92ad9f4b19a0670a80cdd293970c3a08c27a8b4.tar.gz
molsim-e92ad9f4b19a0670a80cdd293970c3a08c27a8b4.zip
Initial commit.
Diffstat (limited to 'error.mjs')
-rw-r--r--error.mjs55
1 files changed, 55 insertions, 0 deletions
diff --git a/error.mjs b/error.mjs
new file mode 100644
index 0000000..0c12f0e
--- /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