/** * Author and copyright: Stefan Haack (https://shaack.com) * Repository: https://github.com/shaack/bootstrap-show-toast * License: MIT, see file 'LICENSE' */ ; (function (bootstrap) { "use strict" function createElement(html) { const template = document.createElement('template') template.innerHTML = html.trim() return template.content.firstChild } function Toast(props) { // see https://getbootstrap.com/docs/5.2/components/toasts/ this.props = { header: "", // the header text headerSmall: "", // additional text in the header, aligns right body: "", // the body text of the toast closeButton: true, // show a close button closeButtonLabel: "close", // the label of the close button closeButtonClass: "", // set to "btn-close-white" for dark backgrounds toastClass: "", // the appearance animation: true, // apply a CSS fade transition to the toast delay: 5000, // delay in milliseconds before hiding the toast, set delay to `Infinity` to make it sticky position: "top-0 end-0", // top right direction: "append", // or "prepend", the stack direction zIndex: 1100, // the z-index of the container ariaLive: "assertive", type: "info", // "info", "success", "warning", "error" } this.containerId = "bootstrap-show-toast-container-" + this.props.position.replace(" ", "_") for (let prop in props) { // noinspection JSUnfilteredForInLoop this.props[prop] = props[prop] } const cssClass = ("toast " + this.props.toastClass).trim() let toastHeader = "" const showHeader = this.props.header || this.props.headerSmall let colors = { info: "primary", success: "success", warning: "warning", error: "danger" } if (showHeader) { toastHeader = `
${this.props.header}
${this.props.headerSmall ? `${this.props.headerSmall}` : ""} ${this.props.closeButton ? `` : ""}