/* * Project: Bootstrap Notify = v3.1.3 * Description: Turns standard Bootstrap alerts into "Growl-like" notifications. * Author: Mouse0270 aka Robert McIntosh * License: MIT License * Website: https://github.com/mouse0270/bootstrap-growl */ (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if (typeof exports === 'object') { // Node/CommonJS factory(require('jquery')); } else { // Browser globals factory(jQuery); } }(function ($) { // Create the defaults once var defaults = { element: 'body', position: null, type: "info", allow_dismiss: true, newest_on_top: false, showProgressbar: false, progressValue: -1, size: 2, placement: { from: "top", align: "right" }, offset: 20, spacing: 10, z_index: 1031, delay: 5000, timer: 1000, url_target: '_blank', mouse_over: null, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' }, onShow: null, onShown: null, onClose: null, onClosed: null, icon_type: 'class', template: '
' }; String.format = function () { var str = arguments[0]; for (var i = 1; i < arguments.length; i++) { str = str.replace(RegExp("\\{" + (i - 1) + "\\}", "gm"), arguments[i]); } return str; }; function Notify(element, content, options) { // Setup Content of Notify var content = { content: { message: typeof content == 'object' ? content.message : content, title: content.title ? content.title : '', icon: content.icon ? content.icon : '', url: content.url ? content.url : '#', target: content.target ? content.target : '-' } }; options = $.extend(true, {}, content, options); this.settings = $.extend(true, {}, defaults, options); this._defaults = defaults; if (this.settings.content.target == "-") { this.settings.content.target = this.settings.url_target; } this.animations = { start: 'webkitAnimationStart oanimationstart MSAnimationStart animationstart', end: 'webkitAnimationEnd oanimationend MSAnimationEnd animationend' } if (typeof this.settings.offset == 'number') { this.settings.offset = { x: this.settings.offset, y: this.settings.offset }; } this.init(); }; $.extend(Notify.prototype, { init: function () { var self = this; this.buildNotify(); if (this.settings.content.icon) { this.setIcon(); } if (this.settings.content.url != "#") { this.styleURL(); } this.styleDismiss(); this.placement(); this.bind(); this.notify = { $ele: this.$ele, update: function (command, update) { var commands = {}; if (typeof command == "string") { commands[command] = update; } else { commands = command; } for (var command in commands) { switch (command) { case "type": this.$ele.removeClass('alert-' + self.settings.type); this.$ele.find('[data-notify="progressbar"] > .progress-bar').removeClass('progress-bar-' + self.settings.type); self.settings.type = commands[command]; this.$ele.addClass('alert-' + commands[command]).find('[data-notify="progressbar"] > .progress-bar').addClass('progress-bar-' + commands[command]); break; case "icon": var $icon = this.$ele.find('[data-notify="icon"]'); if (self.settings.icon_type.toLowerCase() == 'class') { $icon.removeClass(self.settings.content.icon).addClass(commands[command]); } else { if (!$icon.is('img')) { $icon.find('img'); } $icon.attr('src', commands[command]); } break; case "progress": if (commands[command] === -1) { //Ñ»· this.$ele.find('[data-notify="progressbar"]').addClass("marquee"); commands[command] = 50; } else { this.$ele.find('[data-notify="progressbar"]').removeClass("marquee"); } var newDelay = self.settings.delay - (self.settings.delay * (commands[command] / 100)); this.$ele.data('notify-delay', newDelay); this.$ele.find('[data-notify="progressbar"] > div').attr('aria-valuenow', commands[command]).css('width', commands[command] + '%'); break; case "url": this.$ele.find('[data-notify="url"]').attr('href', commands[command]); break; case "target": this.$ele.find('[data-notify="url"]').attr('target', commands[command]); break; default: this.$ele.find('[data-notify="' + command + '"]').html(commands[command]); }; } var posX = this.$ele.outerHeight() + parseInt(self.settings.spacing) + parseInt(self.settings.offset.y); self.reposition(posX); }, close: function () { self.close(); } }; }, buildNotify: function () { var content = this.settings.content; this.$ele = $(String.format(this.settings.template, this.settings.type, content.title, content.message, content.url, content.target, this.settings.size)); this.$ele.attr('data-notify-position', this.settings.placement.from + '-' + this.settings.placement.align); if (!this.settings.allow_dismiss) { this.$ele.find('[data-notify="dismiss"]').css('display', 'none'); } if ((this.settings.delay <= 0 && !this.settings.showProgressbar) || !this.settings.showProgressbar) { this.$ele.find('[data-notify="progressbar"]').hide(); } if (this.settings.progress >= -1) { if (this.settings.progress === -1) { //Ñ»· this.$ele.find('[data-notify="progressbar"]').addClass("marquee"); this.$ele.css("paddingBottom", "+=5px"); } else this.$ele.find('[data-notify="progressbar"] > div').attr('aria-valuenow', 'marquee'); } }, setIcon: function () { if (this.settings.icon_type.toLowerCase() == 'class') { this.$ele.find('[data-notify="icon"]').addClass(this.settings.content.icon); } else { if (this.$ele.find('[data-notify="icon"]').is('img')) { this.$ele.find('[data-notify="icon"]').attr('src', this.settings.content.icon); } else { this.$ele.find('[data-notify="icon"]').append('