"function"!=typeof object.create&&(object.create=function(t){function o(){}return o.prototype=t,new o}),function(t,o,i,s){"use strict";var n={_positionclasses:["bottom-left","bottom-right","top-right","top-left","bottom-center","top-center","mid-center"],_defaulticons:["success","error","info","warning"],init:function(o,i){this.prepareoptions(o,t.toast.options),this.process()},prepareoptions:function(o,i){var s={};"string"==typeof o||o instanceof array?s.text=o:s=o,this.options=t.extend({},i,s)},process:function(){this.setup(),this.addtodom(),this.position(),this.bindtoast(),this.animate()},setup:function(){var o="";if(this._toastel=this._toastel||t("
",{"class":"jq-toast-single"}),o+='',this.options.allowtoastclose&&(o+='×'),this.options.text instanceof array){this.options.heading&&(o+='

'+this.options.heading+"

"),o+='"}else this.options.heading&&(o+='

'+this.options.heading+"

"),o+=this.options.text;this._toastel.html(o),this.options.bgcolor!==!1&&this._toastel.css("background-color",this.options.bgcolor),this.options.textcolor!==!1&&this._toastel.css("color",this.options.textcolor),this.options.textalign&&this._toastel.css("text-align",this.options.textalign),this.options.icon!==!1&&(this._toastel.addclass("jq-has-icon"),-1!==t.inarray(this.options.icon,this._defaulticons)&&this._toastel.addclass("jq-icon-"+this.options.icon)),this.options["class"]!==!1&&this._toastel.addclass(this.options["class"])},position:function(){"string"==typeof this.options.position&&-1!==t.inarray(this.options.position,this._positionclasses)?"bottom-center"===this.options.position?this._container.css({left:t(o).outerwidth()/2-this._container.outerwidth()/2,bottom:20}):"top-center"===this.options.position?this._container.css({left:t(o).outerwidth()/2-this._container.outerwidth()/2,top:20}):"mid-center"===this.options.position?this._container.css({left:t(o).outerwidth()/2-this._container.outerwidth()/2,top:t(o).outerheight()/2-this._container.outerheight()/2}):this._container.addclass(this.options.position):"object"==typeof this.options.position?this._container.css({top:this.options.position.top?this.options.position.top:"auto",bottom:this.options.position.bottom?this.options.position.bottom:"auto",left:this.options.position.left?this.options.position.left:"auto",right:this.options.position.right?this.options.position.right:"auto"}):this._container.addclass("bottom-left")},bindtoast:function(){var t=this;this._toastel.on("aftershown",function(){t.processloader()}),this._toastel.find(".close-jq-toast-single").on("click",function(o){o.preventdefault(),"fade"===t.options.showhidetransition?(t._toastel.trigger("beforehide"),t._toastel.fadeout(function(){t._toastel.trigger("afterhidden")})):"slide"===t.options.showhidetransition?(t._toastel.trigger("beforehide"),t._toastel.slideup(function(){t._toastel.trigger("afterhidden")})):(t._toastel.trigger("beforehide"),t._toastel.hide(function(){t._toastel.trigger("afterhidden")}))}),"function"==typeof this.options.beforeshow&&this._toastel.on("beforeshow",function(){t.options.beforeshow()}),"function"==typeof this.options.aftershown&&this._toastel.on("aftershown",function(){t.options.aftershown()}),"function"==typeof this.options.beforehide&&this._toastel.on("beforehide",function(){t.options.beforehide()}),"function"==typeof this.options.afterhidden&&this._toastel.on("afterhidden",function(){t.options.afterhidden()})},addtodom:function(){var o=t(".jq-toast-wrap");if(0===o.length?(o=t("
",{"class":"jq-toast-wrap"}),t("body").append(o)):(!this.options.stack||isnan(parseint(this.options.stack,10)))&&o.empty(),o.find(".jq-toast-single:hidden").remove(),o.append(this._toastel),this.options.stack&&!isnan(parseint(this.options.stack),10)){var i=o.find(".jq-toast-single").length,s=i-this.options.stack;s>0&&t(".jq-toast-wrap").find(".jq-toast-single").slice(0,s).remove()}this._container=o},canautohide:function(){return this.options.hideafter!==!1&&!isnan(parseint(this.options.hideafter,10))},processloader:function(){if(!this.canautohide()||this.options.loader===!1)return!1;var t=this._toastel.find(".jq-toast-loader"),o=(this.options.hideafter-400)/1e3+"s",i=this.options.loaderbg,s=t.attr("style")||"";s=s.substring(0,s.indexof("-webkit-transition")),s+="-webkit-transition: width "+o+" ease-in; -o-transition: width "+o+" ease-in; transition: width "+o+" ease-in; background-color: "+i+";",t.attr("style",s).addclass("jq-toast-loaded")},animate:function(){var t=this;if(this._toastel.hide(),this._toastel.trigger("beforeshow"),"fade"===this.options.showhidetransition.tolowercase()?this._toastel.fadein(function(){t._toastel.trigger("aftershown")}):"slide"===this.options.showhidetransition.tolowercase()?this._toastel.slidedown(function(){t._toastel.trigger("aftershown")}):this._toastel.show(function(){t._toastel.trigger("aftershown")}),this.canautohide()){var t=this;o.settimeout(function(){"fade"===t.options.showhidetransition.tolowercase()?(t._toastel.trigger("beforehide"),t._toastel.fadeout(function(){t._toastel.trigger("afterhidden")})):"slide"===t.options.showhidetransition.tolowercase()?(t._toastel.trigger("beforehide"),t._toastel.slideup(function(){t._toastel.trigger("afterhidden")})):(t._toastel.trigger("beforehide"),t._toastel.hide(function(){t._toastel.trigger("afterhidden")}))},this.options.hideafter)}},reset:function(o){"all"===o?t(".jq-toast-wrap").remove():this._toastel.remove()},update:function(t){this.prepareoptions(t,this.options),this.setup(),this.bindtoast()}};t.toast=function(t){var o=object.create(n);return o.init(t,this),{reset:function(t){o.reset(t)},update:function(t){o.update(t)}}},t.toast.options={text:"",heading:"",showhidetransition:"fade",allowtoastclose:!0,hideafter:3e3,loader:!0,loaderbg:"#9ec600",stack:5,position:"bottom-left",bgcolor:!1,textcolor:!1,textalign:"left",icon:!1,beforeshow:function(){},aftershown:function(){},beforehide:function(){},afterhidden:function(){}}}(jquery,window,document); /** * 提示框 * @param text * @param icon * @param hideafter * * $("#success").click(function(){ showmsg("成功样式!", "success", 2000); }) $("#info").click(function(){ showmsg("提示样式!", "info", 2000); }); $("#warning").click(function(){ showmsg("警告样式!", "warning", 2000); }) $("#error").click(function(){ showmsg("错误样式!", "error", 2000); }) */ function showmsg(text, icon, hideafter) { if (heading == undefined) { var heading = "提示"; } $.toast({ text: text,//消息提示框的内容。 // heading: heading,//消息提示框的标题。 icon: icon,//消息提示框的图标样式。 showhidetransition: 'fade',//消息提示框的动画效果。可取值:plain,fade,slide。 allowtoastclose: false,//是否显示关闭按钮。(true 显示,false 不显示) hideafter: hideafter,//设置为false则消息提示框不自动关闭.设置为一个数值则在指定的毫秒之后自动关闭消息提框 stack: 1,//消息栈。同时允许的提示框数量 position: 'top-center',//消息提示框的位置:bottom-left, bottom-right,bottom-center,top-left,top-right,top-center,mid-center。 textalign: 'left',//文本对齐:left, right, center。 loader: false,//是否显示加载条 //bgcolor: '#ff1356',//背景颜色。 //textcolor: '#eee',//文字颜色。 loaderbg: '#ffffff',//加载条的背景颜色。 beforeshow: function(){ // alert('the toast is about to appear'); }, aftershown: function () { // alert('toast has appeared.'); }, beforehide: function () { // alert('toast is about to hide.'); }, afterhidden: function () { // alert('toast has been hidden.'); } /*toast事件 beforeshow 会在toast即将出现之前触发 aftershown 会在toast出现后触发 beforehide 会在toast藏起来之前触发 afterhidden 会在toast藏起来后被触发 */ }); }