/** * Chatty.js * * A lightweight notification library for broadcasting messages in a user-interface. * * Author: Lansana Camara - https://github.com/lansana * @license MIT */ function Chatty(a){this.options={message:"Woohoo, you rock!",duration:3e3,infinite:!1,position:"bottom right",renderHtml:!1,isError:!1,styles:{}},a&&"object"==typeof a&&this._extend(this.options,a),this.positionClass=this.options.position,this.id="chatty-"+(new Date).getTime(),this.body=document.body,this.chatty=null}Chatty.prototype={show:function(){var a=this,b=a._resetChatty(a.chatty);return b||(b=a._createChatty()),a.body.appendChild(b),a.chatty=document.getElementById(b.id),a.options.infinite||setTimeout(function(){a._removeChatty()},a.options.duration),a},update:function(a){this._extend(this.options,a),this.options.renderHtml?this._setText(this.chatty,this.options.message,!0):this._setText(this.chatty,this.options.message),this.chatty.className="chatty-container "+this.options.position,this._extend(this.chatty.style,this.options.styles),this.options.isError&&(this.chatty.className+=" error")},close:function(){return this._removeChatty(),this},_createChatty:function(){var a=this,b=document.createElement("div");b.className="chatty-container "+a.positionClass+(a.options.isError?" error":""),b.id=a.id,a._extend(b.style,a.options.styles);var c=document.createElement("div");return c.className="chatty-message",a.options.renderHtml?a._setText(c,a.options.message,!0):a._setText(c,a.options.message),b.appendChild(c),b},_removeChatty:function(){var a=this;return a.chatty.style.opacity="0",setTimeout(function(){a.body.removeChild(a.chatty)},1e3),a},_resetChatty:function(a){a&&a.style&&(a.style.opacity="1")},_setText:function(a,b,c){for(;null!==a.firstChild;)a.removeChild(a.firstChild);if(c){var d=document.createElement("div");for(d.innerHTML=b;d.firstChild;)a.appendChild(d.firstChild)}else a.appendChild(document.createTextNode(b))},_extend:function(a,b){for(var c in b)b&&b.hasOwnProperty(c)&&(a[c]=b[c])}};