|
@@ -10,11 +10,12 @@ export default class Toast {
|
|
|
|
|
|
this.visible = false;
|
|
this.visible = false;
|
|
|
|
|
|
- this.content = content;
|
|
|
|
this.persistent = persistent !== undefined ? persistent : false;
|
|
this.persistent = persistent !== undefined ? persistent : false;
|
|
this.timeout = timeout ? timeout : 6000;
|
|
this.timeout = timeout ? timeout : 6000;
|
|
this.interactable = interactable !== undefined ? interactable : true;
|
|
this.interactable = interactable !== undefined ? interactable : true;
|
|
|
|
|
|
|
|
+ this.content = content;
|
|
|
|
+
|
|
if (!this.persistent) this.startTimer();
|
|
if (!this.persistent) this.startTimer();
|
|
|
|
|
|
if (this.interactable) this.dragListener();
|
|
if (this.interactable) this.dragListener();
|
|
@@ -33,6 +34,18 @@ export default class Toast {
|
|
} else
|
|
} else
|
|
this.element.innerHTML = this.content;
|
|
this.element.innerHTML = this.content;
|
|
|
|
|
|
|
|
+ if (this.interactable) {
|
|
|
|
+ // create "close" icon
|
|
|
|
+ const closeIcon = document.createElement("span");
|
|
|
|
+ closeIcon.classList.add("close-icon");
|
|
|
|
+
|
|
|
|
+ // add "close" icon to toast
|
|
|
|
+ this.element.appendChild(closeIcon);
|
|
|
|
+
|
|
|
|
+ // detect click on "close" icon and therefore destroy the toast
|
|
|
|
+ this.element.children[0].addEventListener("click", () => this.destroy(), false);
|
|
|
|
+ }
|
|
|
|
+
|
|
this.visible = true;
|
|
this.visible = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,7 +99,7 @@ export default class Toast {
|
|
}
|
|
}
|
|
|
|
|
|
handleInputLoss() {
|
|
handleInputLoss() {
|
|
- if (this.element.style.opacity < 0.15) return this.destroy();
|
|
|
|
|
|
+ if (this.element.style.opacity && this.element.style.opacity < 0.15) return this.destroy();
|
|
else {
|
|
else {
|
|
this.element.style.opacity = 1;
|
|
this.element.style.opacity = 1;
|
|
this.element.style.left = 0;
|
|
this.element.style.left = 0;
|