wishthis/semantic/dist/components/toast.min.js
2022-02-23 22:46:34 +01:00

11 lines
No EOL
13 KiB
JavaScript

/*
* # Fomantic UI - 2.8.8
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(A,e,D){"use strict";A.isFunction=A.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),A.fn.toast=function(w){var k,e=A(this),T=e.selector||"",x=(new Date).getTime(),I=[],P=w,O="string"==typeof P,M=[].slice.call(arguments,1);return e.each(function(){var t,o,a,s,p,i,f,c=A.isPlainObject(w)?A.extend(!0,{},A.fn.toast.settings,w):A.extend({},A.fn.toast.settings),l=c.className,m=c.selector,g=c.error,e=c.namespace,h=c.fields,n="."+e,v=e+"-module",r=A(this),b=c.context?A(c.context):A("body"),C=r.hasClass("toast")||r.hasClass("message")||r.hasClass("card"),u=this,y=C?r.data(v):D,d={initialize:function(){d.verbose("Initializing element"),d.has.container()||d.create.container(),(C||""!==c.message||""!==c.title||""!==d.get.iconClass()||c.showImage||d.has.configActions())&&("string"==typeof c.showProgress&&-1!==[l.top,l.bottom].indexOf(c.showProgress)||(c.showProgress=!1),d.create.toast(),c.closeOnClick&&(c.closeIcon||0<A(o).find(m.input).length||d.has.configActions())&&(c.closeOnClick=!1),c.closeOnClick||t.addClass(l.unclickable),d.bind.events()),d.instantiate(),t&&d.show()},instantiate:function(){d.verbose("Storing instance of toast"),y=d,r.data(v,y)},destroy:function(){t&&(d.debug("Removing toast",t),d.unbind.events(),t.remove(),i=o=t=D,c.onRemove.call(t,u),f=p=s=D),r.removeData(v)},show:function(e){e=e||function(){},d.debug("Showing toast"),!1!==c.onShow.call(t,u)?d.animate.show(e):d.debug("onShow callback returned false, cancelling toast animation")},close:function(e){e=e||function(){},d.remove.visible(),d.unbind.events(),d.animate.close(e)},create:{container:function(){d.verbose("Creating container"),b.append(A("<div/>",{class:c.position+" "+l.container+" "+(c.horizontal?l.horizontal:"")}))},toast:function(){t=A("<div/>",{class:l.box});var e,n=d.get.iconClass();C?(o=c.cloneModule?r.clone().removeAttr("id"):r,f=o.find("> i"+d.helpers.toClass(l.close)),c.closeIcon=0<f.length,""!==n&&o.find(m.icon).attr("class",n+" "+l.icon),c.showImage&&o.find(m.image).attr("src",c.showImage),""!==c.title&&o.find(m.title).html(d.helpers.escape(c.title,c.preserveHTML)),""!==c.message&&o.find(m.message).html(d.helpers.escape(c.message,c.preserveHTML))):(d.verbose("Creating toast"),o=A("<div/>"),e=A("<div/>",{class:l.content}),""!==n&&o.append(A("<i/>",{class:n+" "+l.icon})),c.showImage&&o.append(A("<img>",{class:l.image+" "+c.classImage,src:c.showImage})),""!==c.title&&e.append(A("<div/>",{class:l.title,text:c.title})),e.append(A("<div/>",{class:l.message,html:d.helpers.escape(c.message,c.preserveHTML)})),o.addClass(c.class+" "+l.toast).append(e),o.css("opacity",c.opacity),c.closeIcon&&((f=A("<i/>",{class:l.close+" "+("string"==typeof c.closeIcon?c.closeIcon:"")})).hasClass(l.left)?o.prepend(f):o.append(f))),o.hasClass(l.compact)&&(c.compact=!0),o.hasClass("card")&&(c.compact=!1),a=o.find(".actions"),d.has.configActions()&&(0===a.length&&(a=A("<div/>",{class:l.actions+" "+(c.classActions||"")}).appendTo(o)),o.hasClass("card")&&!a.hasClass(l.attached)&&(a.addClass(l.extraContent),a.hasClass(l.vertical)&&(a.removeClass(l.vertical),d.error(g.verticalCard))),c.actions.forEach(function(e){var n=e[h.icon]?'<i class="'+d.helpers.deQuote(e[h.icon])+' icon"></i>':"",t=d.helpers.escape(e[h.text]||"",c.preserveHTML),o=d.helpers.deQuote(e[h.class]||""),s=e[h.click]&&A.isFunction(e[h.click])?e[h.click]:function(){};a.append(A("<button/>",{html:n+t,class:l.button+" "+o,click:function(){!1!==s.call(u,r)&&d.close()}}))})),a&&a.hasClass(l.vertical)&&o.addClass(l.vertical),0<a.length&&!a.hasClass(l.attached)&&(!a||a.hasClass(l.basic)&&!a.hasClass(l.left)||o.addClass(l.actions)),"auto"===c.displayTime&&(c.displayTime=Math.max(c.minDisplayTime,o.text().split(" ").length/c.wordsPerMinute*6e4)),t.append(o),0<a.length&&a.hasClass(l.attached)&&(a.addClass(l.buttons),a.detach(),o.addClass(l.attached),a.hasClass(l.vertical)?(o.wrap(A("<div/>",{class:l.vertical+" "+l.attached+" "+(c.compact?l.compact:"")})),a.hasClass(l.left)?o.addClass(l.left).parent().addClass(l.left).prepend(a):o.parent().append(a)):a.hasClass(l.top)?(t.prepend(a),o.addClass(l.bottom)):(t.append(a),o.addClass(l.top))),r!==o&&(u=(r=o)[0]),0<c.displayTime&&(n=l.progressing+" "+(c.pauseOnHover?l.pausable:""),c.showProgress&&(s=A("<div/>",{class:l.progress+" "+(c.classProgress||c.class),"data-percent":""}),c.classProgress||(o.hasClass("toast")&&!o.hasClass(l.inverted)?s.addClass(l.inverted):s.removeClass(l.inverted)),p=A("<div/>",{class:"bar "+(c.progressUp?"up ":"down ")+n}),s.addClass(c.showProgress).append(p),s.hasClass(l.top)?t.prepend(s):t.append(s),p.css("animation-duration",c.displayTime/1e3+"s")),(i=A("<span/>",{class:"wait "+n})).css("animation-duration",c.displayTime/1e3+"s"),i.appendTo(o)),c.compact&&(t.addClass(l.compact),o.addClass(l.compact),s&&s.addClass(l.compact)),c.newestOnTop?t.prependTo(d.get.container()):t.appendTo(d.get.container())}},bind:{events:function(){d.debug("Binding events to toast"),(c.closeOnClick||c.closeIcon)&&(c.closeIcon?f:o).on("click"+n,d.event.click),i&&i.on("animationend"+n,d.close),t.on("click"+n,m.approve,d.event.approve).on("click"+n,m.deny,d.event.deny)}},unbind:{events:function(){d.debug("Unbinding events to toast"),(c.closeOnClick||c.closeIcon)&&(c.closeIcon?f:o).off("click"+n),i&&i.off("animationend"+n),t.off("click"+n)}},animate:{show:function(e){e=A.isFunction(e)?e:function(){},c.transition&&d.can.useElement("transition")&&r.transition("is supported")&&(d.set.visible(),t.transition({animation:c.transition.showMethod+" in",queue:!1,debug:c.debug,verbose:c.verbose,duration:c.transition.showDuration,onComplete:function(){e.call(t,u),c.onVisible.call(t,u)}}))},close:function(e){e=A.isFunction(e)?e:function(){},d.debug("Closing toast"),!1!==c.onHide.call(t,u)?c.transition&&A.fn.transition!==D&&r.transition("is supported")?t.transition({animation:c.transition.hideMethod+" out",queue:!1,duration:c.transition.hideDuration,debug:c.debug,verbose:c.verbose,interval:50,onBeforeHide:function(e){e=A.isFunction(e)?e:function(){},""!==c.transition.closeEasing?t&&(t.css("opacity",0),t.wrap("<div/>").parent().hide(c.transition.closeDuration,c.transition.closeEasing,function(){t&&(t.parent().remove(),e.call(t))})):e.call(t)},onComplete:function(){e.call(t,u),c.onHidden.call(t,u),d.destroy()}}):d.error(g.noTransition):d.debug("onHide callback returned false, cancelling toast animation")},pause:function(){i.css("animationPlayState","paused"),p&&p.css("animationPlayState","paused")},continue:function(){i.css("animationPlayState","running"),p&&p.css("animationPlayState","running")}},has:{container:function(){return d.verbose("Determining if there is already a container"),0<b.find(d.helpers.toClass(c.position)+m.container+(c.horizontal?d.helpers.toClass(l.horizontal):"")).length},toast:function(){return!!d.get.toast()},toasts:function(){return 0<d.get.toasts().length},configActions:function(){return Array.isArray(c.actions)&&0<c.actions.length}},get:{container:function(){return b.find(d.helpers.toClass(c.position)+m.container)[0]},toastBox:function(){return t||null},toast:function(){return o||null},toasts:function(){return A(d.get.container()).find(m.box)},iconClass:function(){return"string"==typeof c.showIcon?c.showIcon:c.showIcon&&c.icons[c.class]?c.icons[c.class]:""},remainingTime:function(){return i?i.css("opacity")*c.displayTime:0}},set:{visible:function(){o.addClass(l.visible)}},remove:{visible:function(){o.removeClass(l.visible)}},event:{click:function(e){0===A(e.target).closest("a").length&&(c.onClick.call(t,u),d.close())},approve:function(){!1!==c.onApprove.call(u,r)?d.close():d.verbose("Approve callback returned false cancelling close")},deny:function(){!1!==c.onDeny.call(u,r)?d.close():d.verbose("Deny callback returned false cancelling close")}},helpers:{toClass:function(e){var e=e.split(" "),n="";return e.forEach(function(e){n+="."+e}),n},deQuote:function(e){return String(e).replace(/"/g,"")},escape:function(e,n){if(n)return e;var t={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"};return/[&<>"'`]/.test(e)?(e=e.replace(/&(?![a-z0-9#]{1,6};)/,"&amp;")).replace(/[<>"'`]/g,function(e){return t[e]}):e}},can:{useElement:function(e){return A.fn[e]!==D||(d.error(g.noElement.replace("{element}",e)),!1)}},setting:function(e,n){if(d.debug("Changing setting",e,n),A.isPlainObject(e))A.extend(!0,c,e);else{if(n===D)return c[e];A.isPlainObject(c[e])?A.extend(!0,c[e],n):c[e]=n}},internal:function(e,n){if(A.isPlainObject(e))A.extend(!0,d,e);else{if(n===D)return d[e];d[e]=n}},debug:function(){!c.silent&&c.debug&&(c.performance?d.performance.log(arguments):(d.debug=Function.prototype.bind.call(console.info,console,c.name+":"),d.debug.apply(console,arguments)))},verbose:function(){!c.silent&&c.verbose&&c.debug&&(c.performance?d.performance.log(arguments):(d.verbose=Function.prototype.bind.call(console.info,console,c.name+":"),d.verbose.apply(console,arguments)))},error:function(){c.silent||(d.error=Function.prototype.bind.call(console.error,console,c.name+":"),d.error.apply(console,arguments))},performance:{log:function(e){var n,t;c.performance&&(t=(n=(new Date).getTime())-(x||n),x=n,I.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:u,"Execution Time":t})),clearTimeout(d.performance.timer),d.performance.timer=setTimeout(d.performance.display,500)},display:function(){var e=c.name+":",t=0;x=!1,clearTimeout(d.performance.timer),A.each(I,function(e,n){t+=n["Execution Time"]}),e+=" "+t+"ms",T&&(e+=" '"+T+"'"),(console.group!==D||console.table!==D)&&0<I.length&&(console.groupCollapsed(e),console.table?console.table(I):A.each(I,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),I=[]}},invoke:function(o,e,n){var s,a,t,i=y;return e=e||M,n=u||n,"string"==typeof o&&i!==D&&(o=o.split(/[\. ]/),s=o.length-1,A.each(o,function(e,n){var t=e!=s?n+o[e+1].charAt(0).toUpperCase()+o[e+1].slice(1):o;if(A.isPlainObject(i[t])&&e!=s)i=i[t];else{if(i[t]!==D)return a=i[t],!1;{if(!A.isPlainObject(i[n])||e==s)return i[n]!==D?a=i[n]:d.error(g.method,o),!1;i=i[n]}}})),A.isFunction(a)?t=a.apply(n,e):a!==D&&(t=a),Array.isArray(k)?k.push(t):k!==D?k=[k,t]:t!==D&&(k=t),a}};O?(y===D&&d.initialize(),d.invoke(P)):(y!==D&&y.invoke("destroy"),d.initialize(),k=r)}),k!==D?k:this},A.fn.toast.settings={name:"Toast",namespace:"toast",silent:!1,debug:!1,verbose:!1,performance:!0,context:"body",position:"top right",horizontal:!1,class:"neutral",classProgress:!1,classActions:!1,classImage:"mini",title:"",message:"",displayTime:3e3,minDisplayTime:1e3,wordsPerMinute:120,showIcon:!1,newestOnTop:!1,showProgress:!1,pauseOnHover:!0,progressUp:!1,opacity:1,compact:!0,closeIcon:!1,closeOnClick:!0,cloneModule:!0,actions:!1,preserveHTML:!0,showImage:!1,transition:{showMethod:"scale",showDuration:500,hideMethod:"scale",hideDuration:500,closeEasing:"easeOutCubic",closeDuration:500},error:{method:"The method you called is not defined.",noElement:"This module requires ui {element}",verticalCard:"Vertical but not attached actions are not supported for card layout"},className:{container:"ui toast-container",box:"floating toast-box",progress:"ui attached active progress",toast:"ui toast",icon:"centered icon",visible:"visible",content:"content",title:"ui header",message:"message",actions:"actions",extraContent:"extra content",button:"ui button",buttons:"ui buttons",close:"close icon",image:"ui image",vertical:"vertical",horizontal:"horizontal",attached:"attached",inverted:"inverted",compact:"compact",pausable:"pausable",progressing:"progressing",top:"top",bottom:"bottom",left:"left",basic:"basic",unclickable:"unclickable"},icons:{info:"info",success:"checkmark",warning:"warning",error:"times"},selector:{container:".ui.toast-container",box:".toast-box",toast:".ui.toast",title:".header",message:".message:not(.ui)",image:"> img.image, > .image > img",icon:"> i.icon",input:'input:not([type="hidden"]), textarea, select, button, .ui.button, ui.dropdown',approve:".actions .positive, .actions .approve, .actions .ok",deny:".actions .negative, .actions .deny, .actions .cancel"},fields:{class:"class",text:"text",icon:"icon",click:"click"},onShow:function(){},onVisible:function(){},onClick:function(){},onHide:function(){},onHidden:function(){},onRemove:function(){},onApprove:function(){},onDeny:function(){}},A.extend(A.easing,{easeOutBounce:function(e,n,t,o,s){return(n/=s)<1/2.75?o*(7.5625*n*n)+t:n<2/2.75?o*(7.5625*(n-=1.5/2.75)*n+.75)+t:n<2.5/2.75?o*(7.5625*(n-=2.25/2.75)*n+.9375)+t:o*(7.5625*(n-=2.625/2.75)*n+.984375)+t},easeOutCubic:function(e){return--e*e*e+1}})}(jQuery,window,void document);