/*! * # Fomantic-UI 2.9.3 - Toast * https://github.com/fomantic/Fomantic-UI/ * * * Released under the MIT license * https://opensource.org/licenses/MIT * */ (function ($, window, document) { 'use strict'; function isFunction(obj) { return typeof obj === 'function' && typeof obj.nodeType !== 'number'; } window = window !== undefined && window.Math === Math ? window : globalThis; $.fn.toast = function (parameters) { var $allModules = $(this), $body = $('body'), time = Date.now(), performance = [], query = arguments[0], methodInvoked = typeof query === 'string', queryArguments = [].slice.call(arguments, 1), contextCheck = function (context, win) { var $context; if ([window, document].indexOf(context) >= 0) { $context = $(context); } else { $context = $(win.document).find(context); if ($context.length === 0) { $context = win.frameElement ? contextCheck(context, win.parent) : $body; } } return $context; }, returnedValue ; $allModules.each(function () { var settings = $.isPlainObject(parameters) ? $.extend(true, {}, $.fn.toast.settings, parameters) : $.extend({}, $.fn.toast.settings), className = settings.className, selector = settings.selector, error = settings.error, namespace = settings.namespace, fields = settings.fields, eventNamespace = '.' + namespace, moduleNamespace = namespace + '-module', $module = $(this), $toastBox, $toast, $actions, $progress, $progressBar, $animationObject, $close, $context = settings.context ? contextCheck(settings.context, window) : $body, isToastComponent = $module.hasClass('toast') || $module.hasClass('message') || $module.hasClass('card'), element = this, instance = isToastComponent ? $module.data(moduleNamespace) : undefined, id, module ; module = { initialize: function () { module.verbose('Initializing element'); module.create.id(); if (!module.has.container()) { module.create.container(); } if (isToastComponent || settings.message !== '' || settings.title !== '' || module.get.iconClass() !== '' || settings.showImage || module.has.configActions()) { if (typeof settings.showProgress !== 'string' || [className.top, className.bottom].indexOf(settings.showProgress) === -1) { settings.showProgress = false; } module.create.toast(); if (settings.closeOnClick && (settings.closeIcon || $($toast).find(selector.input).length > 0 || module.has.configActions())) { settings.closeOnClick = false; } if (!settings.closeOnClick) { $toastBox.addClass(className.unclickable); } module.bind.events(); } module.instantiate(); if ($toastBox) { module.show(); } }, instantiate: function () { module.verbose('Storing instance of toast'); instance = module; $module .data(moduleNamespace, instance) ; }, destroy: function () { if ($toastBox) { module.debug('Removing toast', $toastBox); module.unbind.events(); settings.onRemove.call($toastBox, element); $toastBox.remove(); $toastBox = undefined; $toast = undefined; $animationObject = undefined; $progress = undefined; $progressBar = undefined; $close = undefined; } $module .removeData(moduleNamespace) ; }, show: function (callback) { if (settings.onShow.call($toastBox, element) === false) { module.debug('onShow callback returned false, cancelling toast animation'); return; } callback = callback || function () {}; module.debug('Showing toast'); module.animate.show(callback); }, close: function (callback) { if (settings.onHide.call($toastBox, element) === false) { module.debug('onHide callback returned false, cancelling toast animation'); return; } callback = callback || function () {}; module.debug('Closing toast'); module.remove.visible(); module.unbind.events(); module.animate.close(callback); }, create: { container: function () { module.verbose('Creating container'); $context.append($('
', { class: settings.position + ' ' + className.container + ' ' + (settings.horizontal ? className.horizontal : '') + ' ' + (settings.context && settings.context !== 'body' ? className.absolute : ''), })); }, id: function () { id = (Math.random().toString(16) + '000000000').slice(2, 10); module.verbose('Creating unique id for element', id); }, toast: function () { $toastBox = $('
', { class: className.box }); var iconClass = module.get.iconClass(); if (!isToastComponent) { module.verbose('Creating toast'); $toast = $('
', { role: 'alert' }); var $content = $('
', { class: className.content }); if (iconClass !== '') { $toast.append($('', { class: iconClass + ' ' + className.icon })); } if (settings.showImage) { $toast.append($('', { class: className.image + ' ' + settings.classImage, src: settings.showImage, })); } if (settings.title !== '') { var titleId = '_' + module.get.id() + 'title'; $toast.attr('aria-labelledby', titleId); $content.append($('
', { class: className.title, id: titleId, html: module.helpers.escape(settings.title, settings.preserveHTML), })); } var descId = '_' + module.get.id() + 'desc'; $toast.attr('aria-describedby', descId); $content.append($('
', { class: className.message, id: descId, html: module.helpers.escape(settings.message, settings.preserveHTML), })); $toast .addClass(settings.class + ' ' + className.toast) .append($content) ; $toast.css('opacity', String(settings.opacity)); if (settings.closeIcon) { $close = $('', { class: className.close + ' ' + (typeof settings.closeIcon === 'string' ? settings.closeIcon : ''), role: 'button', tabindex: 0, 'aria-label': settings.text.close, }); if ($close.hasClass(className.left)) { $toast.prepend($close); } else { $toast.append($close); } } } else { $toast = settings.cloneModule ? $module.clone().removeAttr('id') : $module; $close = $toast.find('> i' + module.helpers.toClass(className.close)); settings.closeIcon = $close.length > 0; if (iconClass !== '') { $toast.find(selector.icon).attr('class', iconClass + ' ' + className.icon); } if (settings.showImage) { $toast.find(selector.image).attr('src', settings.showImage); } if (settings.title !== '') { $toast.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML)); } if (settings.message !== '') { $toast.find(selector.message).html(module.helpers.escape(settings.message, settings.preserveHTML)); } } if ($toast.hasClass(className.compact)) { settings.compact = true; } if ($toast.hasClass('card')) { settings.compact = false; } $actions = $toast.find('.actions'); if (module.has.configActions()) { if ($actions.length === 0) { $actions = $('
', { class: className.actions + ' ' + (settings.classActions || '') }).appendTo($toast); } if ($toast.hasClass('card') && !$actions.hasClass(className.attached)) { $actions.addClass(className.extraContent); if ($actions.hasClass(className.vertical)) { $actions.removeClass(className.vertical); module.error(error.verticalCard); } } settings.actions.forEach(function (el) { var icon = el[fields.icon] ? '' : '', text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML), cls = module.helpers.deQuote(el[fields.class] || ''), click = el[fields.click] && isFunction(el[fields.click]) ? el[fields.click] : function () {} ; $actions.append($('