| 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 |
/* The message is rendered as text only. No markup is built from it, so there is |
| 47 |
nothing for an attacker to break out of. */ |
| 48 |
let toastDiv = document.createElement("div"); |
| 49 |
let toastIconSpan = document.createElement("span"); |
| 50 |
toastIconSpan.className = "__tagembed__faicon"; |
| 51 |
let toastIcon = document.createElement("i"); |
| 52 |
toastIcon.className = "fas " + this.icon; |
| 53 |
toastIcon.setAttribute("aria-hidden", "true"); |
| 54 |
toastIconSpan.appendChild(toastIcon); |
| 55 |
let toastMessageSpan = document.createElement("span"); |
| 56 |
toastMessageSpan.className = "__tagembed__btnmsg"; |
| 57 |
toastMessageSpan.textContent = (this.message === undefined || this.message === null) ? "" : String(this.message); |
| 58 |
toastDiv.appendChild(toastIconSpan); |
| 59 |
toastDiv.appendChild(toastMessageSpan); |
| 60 |
toastDiv.className = this.type; |
| 61 |
let toastParentDiv = document.createElement("div"); |
| 62 |
toastParentDiv.setAttribute('id', this.id); |
| 63 |
toastParentDiv.className = this.className + " " + this.position; |
| 64 |
if (options.hasOwnProperty("isFullScreen") && options.isFullScreen == true) { |
| 65 |
toastParentDiv.className += " __tagembed__is-full-screen"; |
| 66 |
} |
| 67 |
toastParentDiv.appendChild(toastDiv); |
| 68 |
let bodyElement = document.body; |
| 69 |
bodyElement.appendChild(toastParentDiv); |
| 70 |
let self = this; |
| 71 |
setTimeout(function () { |
| 72 |
let element = document.getElementById(self.id); |
| 73 |
element.className = ""; |
| 74 |
element.parentNode.removeChild(element); |
| 75 |
}, this.duration); |
| 76 |
} |
| 77 |
} |
| 78 |
/*--End--Manage Toast*/ |