| 1 |
/*--Start--Manage Toast*/ |
| 2 |
class TagembedToast { |
| 3 |
constructor() { |
| 4 |
this.id = "Toast"; |
| 5 |
this.position = "__tagembed__is-top-center"; |
| 6 |
this.type = ""; |
| 7 |
this.icon = ""; |
| 8 |
this.className = "__tagembed__toast"; |
| 9 |
this.duration = 3000; |
| 10 |
this.isFullScreen = false; |
| 11 |
} |
| 12 |
info(options) { |
| 13 |
this.type = "__tagembed__bg-info"; |
| 14 |
this.icon = "fa-info"; |
| 15 |
this.show(options); |
| 16 |
} |
| 17 |
warning(options) { |
| 18 |
this.type = "__tagembed__bg-warning"; |
| 19 |
this.icon = "fa-exclamatio"; |
| 20 |
this.show(options); |
| 21 |
} |
| 22 |
danger(options) { |
| 23 |
this.type = "__tagembed__bg-danger"; |
| 24 |
this.icon = "fa-times"; |
| 25 |
this.show(options); |
| 26 |
} |
| 27 |
success(options) { |
| 28 |
this.type = "__tagembed__bg-success"; |
| 29 |
this.icon = "fa-check"; |
| 30 |
this.show(options); |
| 31 |
} |
| 32 |
show(options) { |
| 33 |
if (options.hasOwnProperty("position")) { |
| 34 |
this.position = options.position; |
| 35 |
} |
| 36 |
if (options.hasOwnProperty("type")) { |
| 37 |
this.type = options.type; |
| 38 |
} |
| 39 |
if (options.hasOwnProperty("message")) { |
| 40 |
this.message = options.message; |
| 41 |
} |
| 42 |
if (options.hasOwnProperty("duration")) { |
| 43 |
this.duration = options.duration; |
| 44 |
} |
| 45 |
/*create toast*/ |
| 46 |
let toastDiv = document.createElement("div"); |
| 47 |
let elemHTML = '<span class="__tagembed__faicon"><i class="fas ' + this.icon + '" aria-hidden="true"></i></span><span class="__tagembed__btnmsg">' + this.message + '</span>'; |
| 48 |
toastDiv.innerHTML = elemHTML; |
| 49 |
toastDiv.className = this.type; |
| 50 |
let toastParentDiv = document.createElement("div"); |
| 51 |
toastParentDiv.setAttribute('id', this.id); |
| 52 |
toastParentDiv.className = this.className + " " + this.position; |
| 53 |
if (options.hasOwnProperty("isFullScreen") && options.isFullScreen == true) { |
| 54 |
toastParentDiv.className += " __tagembed__is-full-screen"; |
| 55 |
} |
| 56 |
toastParentDiv.appendChild(toastDiv); |
| 57 |
let bodyElement = document.body; |
| 58 |
bodyElement.appendChild(toastParentDiv); |
| 59 |
let self = this; |
| 60 |
setTimeout(function () { |
| 61 |
let element = document.getElementById(self.id); |
| 62 |
element.className = ""; |
| 63 |
element.parentNode.removeChild(element); |
| 64 |
}, this.duration); |
| 65 |
} |
| 66 |
} |
| 67 |
/*--End--Manage Toast*/ |