wishthis/semantic/dist/components/toast.min.js

11 lines
13 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2023-08-17 09:47:40 +00:00
* # Fomantic UI - 2.9.2
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
2023-08-17 09:47:40 +00:00
!function(D,E,H){"use strict";function z(e){return"function"==typeof e&&"number"!=typeof e.nodeType}E=void 0!==E&&E.Math===Math?E:globalThis,D.fn.toast=function(x){var k,e=D(this),T=e.selector||"",I=Date.now(),P=[],O=x,M="string"==typeof O,A=[].slice.call(arguments,1);return e.each(function(){var t,o,a,s,i,c,l,e,r=D.isPlainObject(x)?D.extend(!0,{},D.fn.toast.settings,x):D.extend({},D.fn.toast.settings),d=r.className,u=r.selector,p=r.error,n=r.namespace,f=r.fields,g="."+n,m=n+"-module",h=D(this),v=r.context?[E,H].indexOf(r.context)<0?D(H).find(r.context):D(r.context):D("body"),b=h.hasClass("toast")||h.hasClass("message")||h.hasClass("card"),C=this,y=b?h.data(m):void 0,w={initialize:function(){w.verbose("Initializing element"),w.create.id(),w.has.container()||w.create.container(),(b||""!==r.message||""!==r.title||""!==w.get.iconClass()||r.showImage||w.has.configActions())&&("string"==typeof r.showProgress&&-1!==[d.top,d.bottom].indexOf(r.showProgress)||(r.showProgress=!1),w.create.toast(),r.closeOnClick&&(r.closeIcon||0<D(o).find(u.input).length||w.has.configActions())&&(r.closeOnClick=!1),r.closeOnClick||t.addClass(d.unclickable),w.bind.events()),w.instantiate(),t&&w.show()},instantiate:function(){w.verbose("Storing instance of toast"),y=w,h.data(m,y)},destroy:function(){t&&(w.debug("Removing toast",t),w.unbind.events(),t.remove(),c=o=t=void 0,r.onRemove.call(t,C),l=i=s=void 0),h.removeData(m)},show:function(e){!1===r.onShow.call(t,C)?w.debug("onShow callback returned false, cancelling toast animation"):(e=e||function(){},w.debug("Showing toast"),w.animate.show(e))},close:function(e){!1===r.onHide.call(t,C)?w.debug("onHide callback returned false, cancelling toast animation"):(e=e||function(){},w.debug("Closing toast"),w.remove.visible(),w.unbind.events(),w.animate.close(e))},create:{container:function(){w.verbose("Creating container"),v.append(D("<div/>",{class:r.position+" "+d.container+" "+(r.horizontal?d.horizontal:"")+" "+(r.context&&"body"!==r.context?d.absolute:"")}))},id:function(){e=(Math.random().toString(16)+"000000000").slice(2,10),w.verbose("Creating unique id for element",e)},toast:function(){t=D("<div/>",{class:d.box});var e,n=w.get.iconClass();b?(o=r.cloneModule?h.clone().removeAttr("id"):h,l=o.find("> i"+w.helpers.toClass(d.close)),r.closeIcon=0<l.length,""!==n&&o.find(u.icon).attr("class",n+" "+d.icon),r.showImage&&o.find(u.image).attr("src",r.showImage),""!==r.title&&o.find(u.title).html(w.helpers.escape(r.title,r.preserveHTML)),""!==r.message&&o.find(u.message).html(w.helpers.escape(r.message,r.preserveHTML))):(w.verbose("Creating toast"),o=D("<div/>",{role:"alert"}),e=D("<div/>",{class:d.content}),""!==n&&o.append(D("<i/>",{class:n+" "+d.icon})),r.showImage&&o.append(D("<img>",{class:d.image+" "+r.classImage,src:r.showImage})),""!==r.title&&(n="_"+w.get.id()+"title",o.attr("aria-labelledby",n),e.append(D("<div/>",{class:d.title,id:n,html:w.helpers.escape(r.title,r.preserveHTML)}))),n="_"+w.get.id()+"desc",o.attr("aria-describedby",n),e.append(D("<div/>",{class:d.message,id:n,html:w.helpers.escape(r.message,r.preserveHTML)})),o.addClass(r.class+" "+d.toast).append(e),o.css("opacity",String(r.opacity)),r.closeIcon&&((l=D("<i/>",{class:d.close+" "+("string"==typeof r.closeIcon?r.closeIcon:""),role:"button",tabindex:0,"aria-label":r.text.close})).hasClass(d.left)?o.prepend(l):o.append(l))),o.hasClass(d.compact)&&(r.compact=!0),o.hasClass("card")&&(r.compact=!1),a=o.find(".actions"),w.has.configActions()&&(0===a.length&&(a=D("<div/>",{class:d.actions+" "+(r.classActions||"")}).appendTo(o)),o.hasClass("card")&&!a.hasClass(d.attached)&&(a.addClass(d.extraContent),a.hasClass(d.vertical))&&(a.removeClass(d.vertical),w.error(p.verticalCard)),r.actions.forEach(function(e){var n=e[f.icon]?"<i "+(e[f.text]?'aria-hidden="true"':"")+' class="'+w.helpers.deQuote(e[f.icon])+' icon"></i>':"",t=w.helpers.escape(e[f.text]||"",r.preserveHTML),o=w.helpers.deQuote(e[f.class]||""),s=e[f.click]&&z(e[f.click])?e[f.click]:function(){};a.append(D("<button/>",{html:n+t,"aria-label":(e[f.text]||e[f.icon]||"").replace(/<[^>]+(>|$)