﻿// --------------------------------
//  Script author: Robert Koritnik
// --------------------------------
$.ns("Viva.Notify"); $.extend(Viva.Notify, { InformationType: { Info: 0, Warning: 1, Error: 2, _strings: ["info", "warning", "error"], toString: function(a) { return this._strings[a % 3] } }, notification: function(a, c, b) { this.type = a % 3; this.title = c; this.message = b } }); $.extend(Viva.Notify, { windowEl: null, titleEl: null, messageEl: null, queue: [], processing: false, show: function(a, d, b) { if (typeof (a) == "number" && a >= 0 && a < 4) { var c = new Viva.Notify.notification(a, d, b); if (a == Viva.Notify.InformationType.Error) { this.queue.unshift(c) } else { this.queue.push(c) } if (this.processing === false) { this.processing = true; setTimeout(function() { Viva.Notify.processQueue.call(Viva.Notify) }, 10) } } }, hide: function() { if (this.windowEl.is(":visible")) { this.windowEl.stop(); this.windowEl.hide(); if (this.queue.length > 0) { setTimeout(function() { Viva.Notify.processQueue.call(Viva.Notify) }, 10) } } }, clearAll: function() { this.queue = []; this.hide() }, processQueue: function() { if (this.queue.length > 0) { this.processing = true; var c = this.queue.shift(); var b = 1000; if (c.title && c.title.length > 0) { b += c.title.split(" ").length * 250; this.titleEl.text(c.title); this.titleEl.show() } else { this.titleEl.hide() } b += c.message.split(" ").length * 250; b = b > 10000 ? 10000 : b; this.messageEl.html(c.message); var a = this.windowEl.attr("related-selector"); if (a) { a = this.windowEl.closest(a) || this.windowEl } a.removeClass("info warning error"); a.addClass(Viva.Notify.InformationType.toString(c.type)); this.windowEl.slideDown("normal").delay(b).slideUp("normal", function() { setTimeout(function() { Viva.Notify.processQueue.call(Viva.Notify) }, 250) }) } else { this.processing = false } } }); $.extend(jQuery.fn, { notifier: function() { var a = Viva.Notify; a.windowEl = this.eq(0); a.titleEl = $("#notify_window_title", this); a.messageEl = $("#notify_window_message", this) } }); $(function() { $("#notify_window").notifier() });
