diff --git a/js/bootstrap-notify.js b/js/bootstrap-notify.js index caa3f12..89bded6 100644 --- a/js/bootstrap-notify.js +++ b/js/bootstrap-notify.js @@ -17,39 +17,45 @@ */ (function ($) { - var Notification = function (element, options) { + var Notification = function (element, options, node) { // Element collection this.$element = $(element); - this.$note = $('
'); this.options = $.extend(true, {}, $.fn.notify.defaults, options); - // Setup from options - if(this.options.transition) - if(this.options.transition == 'fade') - this.$note.addClass('in').addClass(this.options.transition); - else this.$note.addClass(this.options.transition); - else this.$note.addClass('fade').addClass('in'); + if (node != undefined) { + this.$note = node instanceof jQuery ? node : $(node); + } else { + this.$note = $(''); + // Setup from options + if(this.options.transition) + if(this.options.transition == 'fade') + this.$note.addClass('in').addClass(this.options.transition); + else this.$note.addClass(this.options.transition); + else this.$note.addClass('fade').addClass('in'); - if(this.options.type) - this.$note.addClass('alert-' + this.options.type); - else this.$note.addClass('alert-success'); + if(this.options.type) + this.$note.addClass('alert-' + this.options.type); + else this.$note.addClass('alert-success'); - if(!this.options.message && this.$element.data("message") !== '') // dom text - this.$note.html(this.$element.data("message")); - else - if(typeof this.options.message === 'object') - if(this.options.message.html) - this.$note.html(this.options.message.html); - else if(this.options.message.text) - this.$note.text(this.options.message.text); + if(!this.options.message && this.$element.data("message") !== '') // dom text + this.$note.html(this.$element.data("message")); else - this.$note.html(this.options.message); + if(typeof this.options.message === 'object') + if(this.options.message.html) + this.$note.html(this.options.message.html); + else if(this.options.message.text) + this.$note.text(this.options.message.text); + else + this.$note.html(this.options.message); - if(this.options.closable) - var link = $('×'); - $(link).on('click', $.proxy(onClose, this)); - this.$note.prepend(link); + if(this.options.closable) { + var link = $('×'); + $(link).on('click', $.proxy(onClose, this)); + this.$note.prepend(link); + } + } + $('a .close').on('click', $.proxy(onClose, this)); return this; }; @@ -78,6 +84,10 @@ return new Notification(this, options); }; + $.fn.toNotify = function (options, node) { + return new Notification(node, options, this); + }; + $.fn.notify.defaults = { type: 'success', closable: true,