-
Notifications
You must be signed in to change notification settings - Fork 1
/
bsbox2.min.js
7 lines (7 loc) · 2.42 KB
/
bsbox2.min.js
1
2
3
4
5
6
7
/*
* bsbox 2.0.1.0
* required: jQuery
* Author: Cres Jie Labasano
* Email: [email protected]
*/
!function(t,o){"use strict";if(!o)return console.error("jQuery is required"),0;var e={dialog:{title:"Message",type:""},notification:{sticky:!1,timeout:5e3,type:"success",closeBtn:!0,template:"alert",message:"Bsbox Notification",closeOnClick:!0,transitionIn:"slideDown",transitionOut:"slideUp",location:"bottom left"}},i={NotifContainerClass:".bsbox-notif-container"},n={dialog:function(t){var e="",i="";t.title&&(e='<div class="modal-header box-header box-'+t.type+'" ><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h4 class="modal-title">'+t.title+"</h4></div>"),t.message&&(i='<div class="modal-body box-'+(t.type&&!t.title?t.type:"")+'">'+t.message+"</div>");var n='<div id="bsboxDialog" class="modal fade"><div class="modal-dialog"><div class="modal-content">'+e+i+"</div></div></div>",s=o(n);if(t.buttons){s.find(".modal-content").append('<div class="modal-footer"></div>');for(var a=0;a<t.buttons.length;a++){var l=t.buttons[a],d=o('<button class="btn"></button>').html(l.text).on(l.on);l["class"]&&d.addClass(l["class"]),l.attr&&d.attr(l.attr),s.find(".modal-footer").append(d)}}return s},notication:{alert:function(t){var e=o('<div class="alert alert-'+t.type+'" style="display:none"></div>').html(t.message);if(t.closeBtn){var i=o('<button class="close">×</button>');e.prepend(i)}return e}}},s=function(t){var e=function(t){t&&(t="."+t.replace(/ /gi,"."));var e=i.NotifContainerClass+t;if(o(e).length)return o(e);var n=o('<div class="'+e.replace(/\./gi," ")+'"></div>');return o("body").append(n),n},a=e(t.location),l=n.notication[t.template](t);return t.sticky||setTimeout(s.close,t.timeout,l,t),t.closeOnClick&&l.click(function(){s.close(o(this),t)}),a.append(l),l.data("bsboxNotif.options",t)[t.transitionIn]()};s.close=function(t,o){t[o.transitionOut]({complete:function(){this.remove()}})},t.bsbox={dialog:function(t){var t=t.constructor==Object?o.extend({},e.dialog,t):o.extend({},e.dialog,{message:t}),i=n.dialog(t).on("hidden.bs.modal",function(){this.remove()});return o("body").append(i),i.modal("show")},notif:function(t){return t=t.constructor==Object?o.extend({},e.notification,t):o.extend({},e.notification,{message:t}),s(t)},version:"2.0.1.0"},o.extend(bsbox.notif,{close:function(t){s.close(t,t.data("bsboxNotif.options"))},addTemplate:function(t,o){return n.notification[t]=o,this}})}(window,jQuery);