1
0

toast.min.js 7.7 KB

1234567891011
  1. /*
  2. * # Fomantic UI - 2.7.8
  3. * https://github.com/fomantic/Fomantic-UI
  4. * http://fomantic-ui.com/
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(P,e,n,O){"use strict";P.isFunction=P.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")(),P.fn.toast=function(b){var v,e=P(this),y=e.selector||"",w=(new Date).getTime(),T=[],C=b,x="string"==typeof C,k=[].slice.call(arguments,1);return e.each(function(){var r,i=P.isPlainObject(b)?P.extend(!0,{},P.fn.toast.settings,b):P.extend({},P.fn.toast.settings),s=i.className,e=i.selector,c=i.error,n=i.namespace,o="."+n,t=n+"-module",a=P(this),l=P("<div/>",{class:i.className.box}),u=P("<div/>"),d=P("<div/>",{class:i.className.progress+" "+i.class}),p=P("<div/>",{class:"bar"}),f=P("<i/>",{class:"close icon"}),m=i.context?P(i.context):P("body"),g=this,h=a.data(t);r={initialize:function(){r.verbose("Initializing element"),"string"==typeof i.showProgress&&-1!==["top","bottom"].indexOf(i.showProgress)||(i.showProgress=!1),r.has.container()||r.create.container(),r.create.toast(),r.bind.events(),0<i.displayTime&&(r.closeTimer=setTimeout(r.close,i.displayTime+(i.showProgress?300:0))),r.show()},destroy:function(){r.debug("Removing toast",u),u.remove(),u=O,i.onRemove.call(u,g)},show:function(e){e=e||function(){},r.debug("Showing toast"),!1!==i.onShow.call(u,g)?r.animate.show(e):r.debug("onShow callback returned false, cancelling toast animation")},close:function(e){r.closeTimer&&clearTimeout(r.closeTimer),e=e||function(){},r.remove.visible(),r.unbind.events(),r.animate.close(e)},create:{container:function(){r.verbose("Creating container"),m.append('<div class="ui '+i.position+" "+s.container+'"></div>')},toast:function(){var e=P("<div/>").addClass(s.content);r.verbose("Creating toast"),i.closeIcon&&(u.append(f),u.css("cursor","default"));var n="string"==typeof i.showIcon?i.showIcon:i.showIcon&&i.icons[i.class]?i.icons[i.class]:"";if(""!=n){var o=P("<i/>").addClass(n+" "+s.icon);u.addClass(s.icon).append(o)}if(""!==i.title){var t=P("<div/>").addClass(s.title).text(i.title);e.append(t)}e.append(P("<div/>").html(i.message)),u.addClass(i.class+" "+s.toast).append(e),u.css("opacity",i.opacity),(i.compact||u.hasClass("compact"))&&l.addClass("compact"),u.hasClass("toast")&&!u.hasClass("inverted")?d.addClass("inverted"):d.removeClass("inverted"),u=l.append(u),i.showProgress&&0<i.displayTime&&(d.addClass(i.showProgress).append(p),d.hasClass("top")?u.prepend(d):u.append(d),p.css("transition","width "+i.displayTime/1e3+"s linear"),p.width(i.progressUp?"0%":"100%"),setTimeout(function(){void 0!==d&&p.width(i.progressUp?"100%":"0%")},300)),i.newestOnTop?u.prependTo(r.get.container()):u.appendTo(r.get.container())}},bind:{events:function(){r.debug("Binding events to toast"),(i.closeIcon?f:u).on("click"+o,r.event.click)}},unbind:{events:function(){r.debug("Unbinding events to toast"),(i.closeIcon?f:u).off("click"+o)}},animate:{show:function(e){e=P.isFunction(e)?e:function(){},i.transition&&P.fn.transition!==O&&a.transition("is supported")?(r.set.visible(),u.transition({animation:i.transition.showMethod+" in",queue:!1,debug:i.debug,verbose:i.verbose,duration:i.transition.showDuration,onComplete:function(){e.call(u,g),i.onVisible.call(u,g)}})):r.error(c.noTransition)},close:function(e){e=P.isFunction(e)?e:function(){},r.debug("Closing toast"),!1!==i.onHide.call(u,g)?i.transition&&P.fn.transition!==O&&a.transition("is supported")?u.transition({animation:i.transition.hideMethod+" out",queue:!1,duration:i.transition.hideDuration,debug:i.debug,verbose:i.verbose,onBeforeHide:function(e){e=P.isFunction(e)?e:function(){},""!==i.transition.closeEasing?(u.css("opacity",0),u.wrap("<div/>").parent().slideUp(500,i.transition.closeEasing,function(){u.parent().remove(),e.call(u)})):e.call(u)},onComplete:function(){r.destroy(),e.call(u,g),i.onHidden.call(u,g)}}):r.error(c.noTransition):r.debug("onHide callback returned false, cancelling toast animation")}},has:{container:function(){return r.verbose("Determining if there is already a container"),0<m.find(r.helpers.toClass(i.position)+e.container).length}},get:{container:function(){return m.find(r.helpers.toClass(i.position)+e.container)[0]}},set:{visible:function(){u.addClass(s.visible)}},remove:{visible:function(){u.removeClass(s.visible)}},event:{click:function(){i.onClick.call(u,g),r.close()}},helpers:{toClass:function(e){var n=e.split(" "),o="";return n.forEach(function(e){o+="."+e}),o}},setting:function(e,n){if(r.debug("Changing setting",e,n),P.isPlainObject(e))P.extend(!0,i,e);else{if(n===O)return i[e];P.isPlainObject(i[e])?P.extend(!0,i[e],n):i[e]=n}},internal:function(e,n){if(P.isPlainObject(e))P.extend(!0,r,e);else{if(n===O)return r[e];r[e]=n}},debug:function(){!i.silent&&i.debug&&(i.performance?r.performance.log(arguments):(r.debug=Function.prototype.bind.call(console.info,console,i.name+":"),r.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?r.performance.log(arguments):(r.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),r.verbose.apply(console,arguments)))},error:function(){i.silent||(r.error=Function.prototype.bind.call(console.error,console,i.name+":"),r.error.apply(console,arguments))},performance:{log:function(e){var n,o;i.performance&&(o=(n=(new Date).getTime())-(w||n),w=n,T.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:g,"Execution Time":o})),clearTimeout(r.performance.timer),r.performance.timer=setTimeout(r.performance.display,500)},display:function(){var e=i.name+":",o=0;w=!1,clearTimeout(r.performance.timer),P.each(T,function(e,n){o+=n["Execution Time"]}),e+=" "+o+"ms",y&&(e+=" '"+y+"'"),(console.group!==O||console.table!==O)&&0<T.length&&(console.groupCollapsed(e),console.table?console.table(T):P.each(T,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),T=[]}},invoke:function(t,e,n){var i,s,o,a=h;return e=e||k,n=g||n,"string"==typeof t&&a!==O&&(t=t.split(/[\. ]/),i=t.length-1,P.each(t,function(e,n){var o=e!=i?n+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(P.isPlainObject(a[o])&&e!=i)a=a[o];else{if(a[o]!==O)return s=a[o],!1;if(!P.isPlainObject(a[n])||e==i)return a[n]!==O?s=a[n]:r.error(c.method,t),!1;a=a[n]}})),P.isFunction(s)?o=s.apply(n,e):s!==O&&(o=s),Array.isArray(v)?v.push(o):v!==O?v=[v,o]:o!==O&&(v=o),s}},x?(h===O&&r.initialize(),r.invoke(C)):(h!==O&&h.invoke("destroy"),r.initialize())}),v!==O?v:this},P.fn.toast.settings={name:"Toast",namespace:"toast",silent:!1,debug:!1,verbose:!1,performance:!0,context:"body",position:"top right",class:"info",title:"",message:"",displayTime:3e3,showIcon:!0,newestOnTop:!1,showProgress:!1,progressUp:!0,opacity:1,compact:!0,closeIcon:!1,transition:{showMethod:"scale",showDuration:500,hideMethod:"scale",hideDuration:500,closeEasing:"easeOutBounce"},error:{method:"The method you called is not defined.",noTransition:"This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>"},className:{container:"toast-container",box:"toast-box",progress:"ui attached active progress",toast:"ui toast",icon:"icon",visible:"visible",content:"content",title:"header"},icons:{info:"info",success:"checkmark",warning:"warning",error:"times"},selector:{container:".toast-container",box:".toast-box",toast:".ui.toast"},onShow:function(){},onVisible:function(){},onClick:function(){},onHide:function(){},onHidden:function(){},onRemove:function(){}},P.extend(P.easing,{easeOutBounce:function(e,n,o,t,i){return(n/=i)<1/2.75?t*(7.5625*n*n)+o:n<2/2.75?t*(7.5625*(n-=1.5/2.75)*n+.75)+o:n<2.5/2.75?t*(7.5625*(n-=2.25/2.75)*n+.9375)+o:t*(7.5625*(n-=2.625/2.75)*n+.984375)+o}})}(jQuery,window,document);