class UIFactory { toast(options) { const theToast = new Toaster(options); theToast.makeToast() theToast.show() return theToast } modal (options) { const theModal = new ModalFactory(options); theModal.makeModal() theModal.show() return theModal } } class Toaster { constructor(options) { this.options = Object.assign({}, Toaster.defaultOptions, options) this.bsToastOptions = { autohide: this.options.autohide, delay: this.options.delay, } } static defaultOptions = { id: false, title: false, muted: false, body: false, variant: 'default', autohide: true, delay: 5000, titleHtml: false, mutedHtml: false, bodyHtml: false, closeButton: true, } makeToast() { if (this.isValid()) { this.$toast = Toaster.buildToast(this.options) $('#mainToastContainer').append(this.$toast) } } show() { if (this.isValid()) { var that = this this.$toast.toast(this.bsToastOptions) .toast('show') .on('hidden.bs.toast', function () { that.removeToast() }) } } removeToast() { this.$toast.remove(); } isValid() { return this.options.title !== false || this.options.muted !== false || this.options.body !== false || this.options.titleHtml !== false || this.options.mutedHtml !== false || this.options.bodyHtml !== false } static buildToast(options) { var $toast = $('