-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotiModal.min.js
1 lines (1 loc) · 4.06 KB
/
notiModal.min.js
1
!function(t){NModal=function(o){var i;try{i=window.localStorage}catch(t){i=!1}this._options=t.extend({name:"",title:"Hello world",content:"Hi there, this is a test content",ok:"ok",no_more:"Stop showing this",close:"Close",top:"20px",bottom:"initial",max_width:"320px",animation_duration:"500ms",show_duration:1e4,delay:0,sound:!1,force:!1,auto_hide:!1,storage:i,template:'<div class="popover notiModal" role="tooltip"> <div class="arrow"></div> <h3 class="popover-title">{{title}}</h3> <div class="popover-content">{{content}}</div> <div class="popover-navigation"> <button class="btn btn-sm btn-default" data-role="ok">{{ok}}</button> <button class="btn btn-sm btn-default" data-role="no_more">{{no_more}}r</button> <button class="btn btn-sm btn-default" data-role="close">{{close}}</button> </div> </div>',onOkClick:function(t){},onClose:function(t){}},t.notiModal.config,o),this.shift_right="-"+(parseFloat(this._options.max_width)+20)+"px",this.init(this._options,!0)},NModal.prototype.addStyle=function(t){this.modal.css({display:"block","max-width":this.cssMeasureUnit(t.max_width),right:this.shift_right,top:"initial"!==t.bottom?"initial":this.cssMeasureUnit(t.top),bottom:this.cssMeasureUnit(t.bottom),left:"auto",position:"fixed","-webkit-transition":"all "+t.animation_duration+" ease-out","-moz-transition":"all "+t.animation_duration+" ease-out","-o-transition":"all "+t.animation_duration+" ease-out",transition:"all "+t.animation_duration+" ease-out","border-bottom-right-radius":"0","border-top-right-radius":"0"}),this.modal.find(".popover-navigation").css({"margin-bottom":"9px","margin-left":"14px","padding-right":"25px"})},NModal.prototype.replaceTemplate=function(t){this.modal.attr("id","notimodal_"+this._options.name),this.modal.find("h3.popover-title").html(t.title),this.modal.find(".popover-content").html(t.content),this.modal.find('button[data-role="ok"]').html(t.ok),this.modal.find('button[data-role="no_more"]').html(t.no_more),this.modal.find('button[data-role="close"]').html(t.close),this.modal.addClass(t.name)},NModal.prototype.cssMeasureUnit=function(t){return isNaN(t)?t:parseFloat(t)+"px"},NModal.prototype.init=function(o){var i=this.getModalElement().length,n=t(o.template);i&&this.modal.replaceWith(n),this.modal=n,this.addStyle(o),this.replaceTemplate(o),this.attachEvents(o),i||t("body").append(this.modal)},NModal.prototype.getModalElement=function(){return t("#notimodal_"+this._options.name)},NModal.prototype.attachEvents=function(t){var o=this;this.modal.find('button[data-role="ok"]').click(function(){t.onOkClick(o)}),this.modal.find('button[data-role="close"]').click(function(){o.hide()}),this.modal.find('button[data-role="no_more"]').click(function(){o.setState("never_show_"+t.name,!0),o.hide()})},NModal.prototype.setState=function(t,o){if(this._options.storage){keyName=this._options.name+"_"+t;try{this._options.storage.setItem(t,o)}catch(t){e=t,e.code===DOMException.QUOTA_EXCEEDED_ERR&&this._debug("LocalStorage quota exceeded. State storage failed.")}}},NModal.prototype.getState=function(t){var o=!1;return this._options.storage&&(o=this._options.storage.getItem(t)),o},NModal.prototype.show=function(o){var i=this;is_never_show_again=this.getState("never_show_"+this._options.name);var n=t.extend({},this._options,o);this.init(n),is_never_show_again&&!n.force||setTimeout(function(){(i.modal.css("right",-5),n.sound)&&new Audio("sound/notify.mp3").play();n.auto_hide&&setTimeout(function(){i.hide()},n.show_duration)},n.delay)},NModal.prototype.hide=function(t){var o=this;this.modal.css("right",this.shift_right),setTimeout(function(){t&&t(o),o._options.onClose(o)},parseInt(this._options.animation_duration))},NotiModal=function(){this.noti_modals={}},NotiModal.prototype.init=function(t,o){if(!(t in this.noti_modals))return o.name=t,this.noti_modals[t]=new NModal(o),this.noti_modals[t];console.error("modal name : "+t+" already taken")},NotiModal.prototype.get=function(t){if(t in this.noti_modals)return this.noti_modals[t];console.error("no such modal name : "+t)},NotiModal.prototype.config={sound:!1,force:!1,auto_hide:!1,show_duration:1e4},t.notiModal=new NotiModal}(window.jQuery);