wishthis/node_modules/fomantic-ui/dist/components/toast.min.js
2022-01-13 14:00:31 +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 2021 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(A,e,n,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 o,s,a,i,c,l,r,u,d=A.isPlainObject(w)?A.extend(!0,{},A.fn.toast.settings,w):A.extend({},A.fn.toast.settings),p=d.className,f=d.selector,m=d.error,e=d.namespace,g=d.fields,n="."+e,t=e+"-module",h=A(this),v=d.context?A(d.context):A("body"),b=h.hasClass("toast")||h.hasClass("message")||h.hasClass("card"),C=this,y=b?h.data(t):D;u={initialize:function(){u.verbose("Initializing element"),u.has.container()||u.create.container(),(b||""!==d.message||""!==d.title||""!==u.get.iconClass()||d.showImage||u.has.configActions())&&("string"==typeof d.showProgress&&-1!==[p.top,p.bottom].indexOf(d.showProgress)||(d.showProgress=!1),u.create.toast(),d.closeOnClick&&(d.closeIcon||0<A(s).find(f.input).length||u.has.configActions())&&(d.closeOnClick=!1),d.closeOnClick||o.addClass(p.unclickable),u.bind.events()),u.instantiate(),o&&u.show()},instantiate:function(){u.verbose("Storing instance of toast"),y=u,h.data(t,y)},destroy:function(){o&&(u.debug("Removing toast",o),u.unbind.events(),o.remove(),l=s=o=D,d.onRemove.call(o,C),r=c=i=D),h.removeData(t)},show:function(e){e=e||function(){},u.debug("Showing toast"),!1!==d.onShow.call(o,C)?u.animate.show(e):u.debug("onShow callback returned false, cancelling toast animation")},close:function(e){e=e||function(){},u.remove.visible(),u.unbind.events(),u.animate.close(e)},create:{container:function(){u.verbose("Creating container"),v.append(A("<div/>",{class:d.position+" "+p.container+" "+(d.horizontal?p.horizontal:"")}))},toast:function(){o=A("<div/>",{class:p.box});var e=u.get.iconClass();if(b)s=d.cloneModule?h.clone().removeAttr("id"):h,r=s.find("> i"+u.helpers.toClass(p.close)),d.closeIcon=0<r.length,""!==e&&s.find(f.icon).attr("class",e+" "+p.icon),d.showImage&&s.find(f.image).attr("src",d.showImage),""!==d.title&&s.find(f.title).html(u.helpers.escape(d.title,d.preserveHTML)),""!==d.message&&s.find(f.message).html(u.helpers.escape(d.message,d.preserveHTML));else{u.verbose("Creating toast"),s=A("<div/>");var n=A("<div/>",{class:p.content});""!==e&&s.append(A("<i/>",{class:e+" "+p.icon})),d.showImage&&s.append(A("<img>",{class:p.image+" "+d.classImage,src:d.showImage})),""!==d.title&&n.append(A("<div/>",{class:p.title,text:d.title})),n.append(A("<div/>",{class:p.message,html:u.helpers.escape(d.message,d.preserveHTML)})),s.addClass(d.class+" "+p.toast).append(n),s.css("opacity",d.opacity),d.closeIcon&&((r=A("<i/>",{class:p.close+" "+("string"==typeof d.closeIcon?d.closeIcon:"")})).hasClass(p.left)?s.prepend(r):s.append(r))}if(s.hasClass(p.compact)&&(d.compact=!0),s.hasClass("card")&&(d.compact=!1),a=s.find(".actions"),u.has.configActions()&&(0===a.length&&(a=A("<div/>",{class:p.actions+" "+(d.classActions||"")}).appendTo(s)),s.hasClass("card")&&!a.hasClass(p.attached)&&(a.addClass(p.extraContent),a.hasClass(p.vertical)&&(a.removeClass(p.vertical),u.error(m.verticalCard))),d.actions.forEach(function(e){var n=e[g.icon]?'<i class="'+u.helpers.deQuote(e[g.icon])+' icon"></i>':"",t=u.helpers.escape(e[g.text]||"",d.preserveHTML),o=u.helpers.deQuote(e[g.class]||""),s=e[g.click]&&A.isFunction(e[g.click])?e[g.click]:function(){};a.append(A("<button/>",{html:n+t,class:p.button+" "+o,click:function(){!1!==s.call(C,h)&&u.close()}}))})),a&&a.hasClass(p.vertical)&&s.addClass(p.vertical),0<a.length&&!a.hasClass(p.attached)&&(!a||a.hasClass(p.basic)&&!a.hasClass(p.left)||s.addClass(p.actions)),"auto"===d.displayTime&&(d.displayTime=Math.max(d.minDisplayTime,s.text().split(" ").length/d.wordsPerMinute*6e4)),o.append(s),0<a.length&&a.hasClass(p.attached)&&(a.addClass(p.buttons),a.detach(),s.addClass(p.attached),a.hasClass(p.vertical)?(s.wrap(A("<div/>",{class:p.vertical+" "+p.attached+" "+(d.compact?p.compact:"")})),a.hasClass(p.left)?s.addClass(p.left).parent().addClass(p.left).prepend(a):s.parent().append(a)):a.hasClass(p.top)?(o.prepend(a),s.addClass(p.bottom)):(o.append(a),s.addClass(p.top))),h!==s&&(C=(h=s)[0]),0<d.displayTime){var t=p.progressing+" "+(d.pauseOnHover?p.pausable:"");d.showProgress&&(i=A("<div/>",{class:p.progress+" "+(d.classProgress||d.class),"data-percent":""}),d.classProgress||(s.hasClass("toast")&&!s.hasClass(p.inverted)?i.addClass(p.inverted):i.removeClass(p.inverted)),c=A("<div/>",{class:"bar "+(d.progressUp?"up ":"down ")+t}),i.addClass(d.showProgress).append(c),i.hasClass(p.top)?o.prepend(i):o.append(i),c.css("animation-duration",d.displayTime/1e3+"s")),(l=A("<span/>",{class:"wait "+t})).css("animation-duration",d.displayTime/1e3+"s"),l.appendTo(s)}d.compact&&(o.addClass(p.compact),s.addClass(p.compact),i&&i.addClass(p.compact)),d.newestOnTop?o.prependTo(u.get.container()):o.appendTo(u.get.container())}},bind:{events:function(){u.debug("Binding events to toast"),(d.closeOnClick||d.closeIcon)&&(d.closeIcon?r:s).on("click"+n,u.event.click),l&&l.on("animationend"+n,u.close),o.on("click"+n,f.approve,u.event.approve).on("click"+n,f.deny,u.event.deny)}},unbind:{events:function(){u.debug("Unbinding events to toast"),(d.closeOnClick||d.closeIcon)&&(d.closeIcon?r:s).off("click"+n),l&&l.off("animationend"+n),o.off("click"+n)}},animate:{show:function(e){e=A.isFunction(e)?e:function(){},d.transition&&u.can.useElement("transition")&&h.transition("is supported")&&(u.set.visible(),o.transition({animation:d.transition.showMethod+" in",queue:!1,debug:d.debug,verbose:d.verbose,duration:d.transition.showDuration,onComplete:function(){e.call(o,C),d.onVisible.call(o,C)}}))},close:function(e){e=A.isFunction(e)?e:function(){},u.debug("Closing toast"),!1!==d.onHide.call(o,C)?d.transition&&A.fn.transition!==D&&h.transition("is supported")?o.transition({animation:d.transition.hideMethod+" out",queue:!1,duration:d.transition.hideDuration,debug:d.debug,verbose:d.verbose,interval:50,onBeforeHide:function(e){e=A.isFunction(e)?e:function(){},""!==d.transition.closeEasing?o&&(o.css("opacity",0),o.wrap("<div/>").parent().hide(d.transition.closeDuration,d.transition.closeEasing,function(){o&&(o.parent().remove(),e.call(o))})):e.call(o)},onComplete:function(){e.call(o,C),d.onHidden.call(o,C),u.destroy()}}):u.error(m.noTransition):u.debug("onHide callback returned false, cancelling toast animation")},pause:function(){l.css("animationPlayState","paused"),c&&c.css("animationPlayState","paused")},continue:function(){l.css("animationPlayState","running"),c&&c.css("animationPlayState","running")}},has:{container:function(){return u.verbose("Determining if there is already a container"),0<v.find(u.helpers.toClass(d.position)+f.container+(d.horizontal?u.helpers.toClass(p.horizontal):"")).length},toast:function(){return!!u.get.toast()},toasts:function(){return 0<u.get.toasts().length},configActions:function(){return Array.isArray(d.actions)&&0<d.actions.length}},get:{container:function(){return v.find(u.helpers.toClass(d.position)+f.container)[0]},toastBox:function(){return o||null},toast:function(){return s||null},toasts:function(){return A(u.get.container()).find(f.box)},iconClass:function(){return"string"==typeof d.showIcon?d.showIcon:d.showIcon&&d.icons[d.class]?d.icons[d.class]:""},remainingTime:function(){return l?l.css("opacity")*d.displayTime:0}},set:{visible:function(){s.addClass(p.visible)}},remove:{visible:function(){s.removeClass(p.visible)}},event:{click:function(e){0===A(e.target).closest("a").length&&(d.onClick.call(o,C),u.close())},approve:function(){!1!==d.onApprove.call(C,h)?u.close():u.verbose("Approve callback returned false cancelling close")},deny:function(){!1!==d.onDeny.call(C,h)?u.close():u.verbose("Deny callback returned false cancelling close")}},helpers:{toClass:function(e){var n=e.split(" "),t="";return n.forEach(function(e){t+="."+e}),t},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||(u.error(m.noElement.replace("{element}",e)),!1)}},setting:function(e,n){if(u.debug("Changing setting",e,n),A.isPlainObject(e))A.extend(!0,d,e);else{if(n===D)return d[e];A.isPlainObject(d[e])?A.extend(!0,d[e],n):d[e]=n}},internal:function(e,n){if(A.isPlainObject(e))A.extend(!0,u,e);else{if(n===D)return u[e];u[e]=n}},debug:function(){!d.silent&&d.debug&&(d.performance?u.performance.log(arguments):(u.debug=Function.prototype.bind.call(console.info,console,d.name+":"),u.debug.apply(console,arguments)))},verbose:function(){!d.silent&&d.verbose&&d.debug&&(d.performance?u.performance.log(arguments):(u.verbose=Function.prototype.bind.call(console.info,console,d.name+":"),u.verbose.apply(console,arguments)))},error:function(){d.silent||(u.error=Function.prototype.bind.call(console.error,console,d.name+":"),u.error.apply(console,arguments))},performance:{log:function(e){var n,t;d.performance&&(t=(n=(new Date).getTime())-(x||n),x=n,I.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:C,"Execution Time":t})),clearTimeout(u.performance.timer),u.performance.timer=setTimeout(u.performance.display,500)},display:function(){var e=d.name+":",t=0;x=!1,clearTimeout(u.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=C||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]:u.error(m.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&&u.initialize(),u.invoke(P)):(y!==D&&y.invoke("destroy"),u.initialize(),k=h)}),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,document);