[194a359] | 1 | /******/ (() => { // webpackBootstrap
|
---|
| 2 | /******/ "use strict";
|
---|
| 3 | var __webpack_exports__ = {};
|
---|
| 4 | /*!******************************************!*\
|
---|
| 5 | !*** ./resources/assets/js/Toast.min.js ***!
|
---|
| 6 | \******************************************/
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | function Toast(t) {
|
---|
| 10 | if (!t.message) throw new Error("Toast.js - You need to set a message to display");
|
---|
| 11 | this.options = t, this.options.type = t.type || "default", this.toastContainerEl = document.querySelector(".toastjs-container"), this.toastEl = document.querySelector(".toastjs"), this._init();
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | Toast.prototype._createElements = function () {
|
---|
| 15 | var t = this;
|
---|
| 16 | return new Promise(function (e, o) {
|
---|
| 17 | t.toastContainerEl = document.createElement("div"), t.toastContainerEl.classList.add("toastjs-container"), t.toastContainerEl.setAttribute("role", "alert"), t.toastContainerEl.setAttribute("aria-hidden", !0), t.toastEl = document.createElement("div"), t.toastEl.classList.add("toastjs"), t.toastContainerEl.appendChild(t.toastEl), document.body.appendChild(t.toastContainerEl), setTimeout(function () {
|
---|
| 18 | return e();
|
---|
| 19 | }, 500);
|
---|
| 20 | });
|
---|
| 21 | }, Toast.prototype._addEventListeners = function () {
|
---|
| 22 | var t = this;
|
---|
| 23 |
|
---|
| 24 | if (document.querySelector(".toastjs-btn--close").addEventListener("click", function () {
|
---|
| 25 | t._close();
|
---|
| 26 | }), this.options.customButtons) {
|
---|
| 27 | var e = Array.prototype.slice.call(document.querySelectorAll(".toastjs-btn--custom"));
|
---|
| 28 | e.map(function (e, o) {
|
---|
| 29 | e.addEventListener("click", function (e) {
|
---|
| 30 | return t.options.customButtons[o].onClick(e);
|
---|
| 31 | });
|
---|
| 32 | });
|
---|
| 33 | }
|
---|
| 34 | }, Toast.prototype._close = function () {
|
---|
| 35 | var t = this;
|
---|
| 36 | return new Promise(function (e, o) {
|
---|
| 37 | t.toastContainerEl.setAttribute("aria-hidden", !0), setTimeout(function () {
|
---|
| 38 | t.toastEl.innerHTML = "", t.toastEl.classList.remove("default", "success", "warning", "danger"), t.focusedElBeforeOpen && t.focusedElBeforeOpen.focus(), e();
|
---|
| 39 | }, 1e3);
|
---|
| 40 | });
|
---|
| 41 | }, Toast.prototype._open = function () {
|
---|
| 42 | this.toastEl.classList.add(this.options.type), this.toastContainerEl.setAttribute("aria-hidden", !1);
|
---|
| 43 | var t = "";
|
---|
| 44 | this.options.customButtons && (t = this.options.customButtons.map(function (t, e) {
|
---|
| 45 | return '<button type="button" class="toastjs-btn toastjs-btn--custom">' + t.text + "</button>";
|
---|
| 46 | }), t = t.join("")), this.toastEl.innerHTML = "\n <p>" + this.options.message + '</p>\n <button type="button" class="toastjs-btn toastjs-btn--close">Close</button>\n ' + t + "\n ", this.focusedElBeforeOpen = document.activeElement, document.querySelector(".toastjs-btn--close").focus();
|
---|
| 47 | }, Toast.prototype._init = function () {
|
---|
| 48 | var t = this;
|
---|
| 49 | Promise.resolve().then(function () {
|
---|
| 50 | return t.toastContainerEl ? Promise.resolve() : t._createElements();
|
---|
| 51 | }).then(function () {
|
---|
| 52 | return "false" == t.toastContainerEl.getAttribute("aria-hidden") ? t._close() : Promise.resolve();
|
---|
| 53 | }).then(function () {
|
---|
| 54 | t._open(), t._addEventListeners();
|
---|
| 55 | });
|
---|
| 56 | };
|
---|
| 57 | /******/ })()
|
---|
| 58 | ; |
---|