Toast - A Bootstrap 4.2+ jQuery plugin for the toast component https://github.com/exacti/Toast
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
2.6 KiB

6 years ago
/**
* @author Script47 (https://github.com/Script47/Toast)
* @description Toast - A Bootstrap 4.2+ jQuery plugin for the toast component
* @version 0.8.0
6 years ago
**/
(function(g){g.toast=function(b){var c=g("body");b.container&&1===b.container.length&&(c=b.container);c.children(".toast-container").length||(c.prepend('<div class="toast-container" aria-live="polite" aria-atomic="true"></div>'),c.children(".toast-container").append('<div class="toast-wrapper"></div>'),c.on("hidden.bs.toast",".toast",function(){g(this).remove()}));c=c.children(".toast-container").children(".toast-wrapper");var k="toast-"+(g(".toast").length+1),a="",d=a="",e="text-muted",f="",t=b.title||
"Notice!",u=b.subtitle||"",r=b.content||"",l=b.delay||-1,h=b.img,m=b.ico,n=b.pause_on_hover||!1,p=!1,v=b.prepend,q="";switch(b.type||"info"){case "info":a="bg-info";f=e=d="text-white";break;case "success":a="bg-success";f=e=d="text-white";break;case "warning":case "warn":a="bg-warning";f=e=d="text-white";break;case "error":case "danger":a="bg-danger";f=e=d="text-white";break;case "dark":a="bg-dark";f=e=d="text-white";break;case "primary":a="bg-primary";f=e=d="text-white";break;case "secondary":a=
"bg-secondary";f=e=d="text-white";break;case "light":a="bg-light";f=e=d="";break;case "white":a="bg-white";f=e=d="text-dark";break;case "transparent":a="bg-transparent",f=e=d=""}!1!==n?(b=Math.floor(Date.now()/1E3)+l/1E3,q='data-autohide="false"',n='data-hide-timestamp="'+b+'"'):q=-1===l?'data-autohide="false"':'data-delay="'+l+'"';a='<div id="'+k+'" class="toast" role="alert" aria-live="assertive" aria-atomic="true" '+q+" "+n+'><div class="toast-header '+(a+" "+d+'">');"undefined"!==typeof h&&"undefined"===
typeof m&&(a+='<img src="'+h.src+'" class="'+(h["class"]||"")+' mr-2" alt="'+(h.alt||"Image")+'" '+("undefined"!==typeof h.title?'data-toggle="tooltip" title="'+h.title+'"':"")+">");"undefined"!==typeof m&&"undefined"===typeof h&&(a+=m);a=a+('<strong class="mr-auto '+("undefined"!==typeof m?"ml-2":"")+'">'+t+'</strong><small class="')+(e+'">'+u+"</small>");a+='<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">';a+='<span aria-hidden="true" class="'+f+'">&times;</span>';
a+="</button>";a+="</div>";""!==r&&(a+='<div class="toast-body">',a+=r,a+="</div>");a+="</div>";!0===v?(c.prepend(a),c.find(".toast:first").toast("show")):(c.append(a),c.find(".toast:last").toast("show"));!1!==n&&(setTimeout(function(){p||g("#"+k).toast("hide")},l),g(document).on("mouseover","#"+k,function(){p=!0}),g(document).on("mouseleave","#"+k,function(){var a=Math.floor(Date.now()/1E3),b=parseInt(g(this).data("hide-timestamp"));p=!1;a>=b&&g(this).toast("hide")}))}})(jQuery);