(function ($) { "use strict"; $.fn.toast = function (opts) { return new Toast(this[0], opts); }; var Toast = (function () { var Toast = function (containerEl, opts) { if (typeof containerEl === "string" || containerEl instanceof String) { this.container = document.getElementById(containerEl); } else { this.container = containerEl; } if (!this.container) { window.alert("Error finding container for toast " + containerEl); return; } if (typeof (opts) === "string" || typeof (opts) === "number") { opts = { message: opts }; } this.addCssClass = opts.addCssClass ? opts.addCssClass : ""; this.message = opts.message || ""; this.delay=opts.delay||this.delay; this.position=opts.position||""; this.addCssClass+=" "+this.position; this.type=opts.type||""; //Check if the container exists this.container=$(this.container); if(this.container.find(".afToastContainer").length===0) { this.container.append("
"); } this.container=this.container.find(".afToastContainer"); this.container.removeClass("tr br tl bl tc bc").addClass(this.addCssClass); if(opts.autoClose===false) this.autoClose=false; this.show(); }; Toast.prototype = { addCssClass: null, message: null, delay:5000, el:null, container:null, timer:null, autoClose:true, show: function () { var self = this; var markup = "