/* * jQuery Pines Notify (pNotify) Plugin 1.0 * * Copyright (c) 2009 Hunter Perrin * * Licensed (along with all of Pines) under the GNU Affero GPL: *  http://www.gnu.org/licenses/agpl.html */(function($) {var history_handle_top, timer;var body;var jwindow;$.extend({pNotify_remove_all: function () {var body_data = body.data("pNotify");if (body_data && body_data.length) {$.each(body_data, function(){if (this.pNotify_remove)this.pNotify_remove();});}},pNotify_position_all: function () {if (timer)clearTimeout(timer);timer = null;var body_data = body.data("pNotify");if (!body_data || !body_data.length)return;$.each(body_data, function(){var s = this.opts.pNotify_stack;if (!s) return;if (!s.nextpos1)s.nextpos1 = s.firstpos1;if (!s.nextpos2)s.nextpos2 = s.firstpos2;if (!s.addpos2)s.addpos2 = 0;if (this.css("display") != "none") {var curpos1, curpos2;var animate = {};switch (s.dir1) {case "down":curpos1 = parseInt(this.css("top"));break;case "up":curpos1 = parseInt(this.css("bottom"));break;case "left":curpos1 = parseInt(this.css("right"));break;case "right":curpos1 = parseInt(this.css("left"));break;}if (isNaN(curpos1))curpos1 = 0;if (typeof s.firstpos1 == "undefined") {s.firstpos1 = curpos1;s.nextpos1 = s.firstpos1;}switch (s.dir2) {case "down":curpos2 = parseInt(this.css("top"));break;case "up":curpos2 = parseInt(this.css("bottom"));break;case "left":curpos2 = parseInt(this.css("right"));break;case "right":curpos2 = parseInt(this.css("left"));break;}if (isNaN(curpos2))curpos2 = 0;if (typeof s.firstpos2 == "undefined") {s.firstpos2 = curpos2;s.nextpos2 = s.firstpos2;}if ((s.dir1 == "down" && s.nextpos1 + this.height() > jwindow.height()) ||(s.dir1 == "up" && s.nextpos1 + this.height() > jwindow.height()) ||(s.dir1 == "left" && s.nextpos1 + this.width() > jwindow.width()) ||(s.dir1 == "right" && s.nextpos1 + this.width() > jwindow.width()) ) {s.nextpos1 = s.firstpos1;s.nextpos2 += s.addpos2 + 10;s.addpos2 = 0;}if (this.pNotify_positioned && s.nextpos2 < curpos2) {switch (s.dir2) {case "down":animate.top = s.nextpos2+"px";break;case "up":animate.bottom = s.nextpos2+"px";break;case "left":animate.right = s.nextpos2+"px";break;case "right":animate.left = s.nextpos2+"px";break;}} else {switch (s.dir2) {case "down":this.css("top", s.nextpos2+"px");break;case "up":this.css("bottom", s.nextpos2+"px");break;case "left":this.css("right", s.nextpos2+"px");break;case "right":this.css("left", s.nextpos2+"px");break;}}switch (s.dir2) {case "down":case "up":if (this.outerHeight(true) > s.addpos2)s.addpos2 = this.height();break;case "left":case "right":if (this.outerWidth(true) > s.addpos2)s.addpos2 = this.width();break;}if (s.nextpos1) {if (this.pNotify_positioned && (curpos1 > s.nextpos1 || animate.top || animate.bottom || animate.right || animate.left)) {switch (s.dir1) {case "down":animate.top = s.nextpos1+"px";break;case "up":animate.bottom = s.nextpos1+"px";break;case "left":animate.right = s.nextpos1+"px";break;case "right":animate.left = s.nextpos1+"px";break;}} else {switch (s.dir1) {case "down":this.css("top", s.nextpos1+"px");break;case "up":this.css("bottom", s.nextpos1+"px");break;case "left":this.css("right", s.nextpos1+"px");break;case "right":this.css("left", s.nextpos1+"px");break;}}}if (animate.top || animate.bottom || animate.right || animate.left)this.animate(animate, {duration: 500, queue: false});switch (s.dir1) {case "down":case "up":s.nextpos1 += this.height() + 10;break;case "left":case "right":s.nextpos1 += this.width() + 10;break;}this.pNotify_positioned = true;}});$.each(body_data, function(){var s = this.opts.pNotify_stack;if (!s) return;s.nextpos1 = s.firstpos1;s.nextpos2 = s.firstpos2;s.addpos2 = 0;});},pNotify: function(options) {if (!body)body = $("body");if (!jwindow)jwindow = $(window);var animating;var opts;if (typeof options == "string") {opts = $.extend({}, $.pNotify.defaults);opts.text = options;} else {opts = $.extend({}, $.pNotify.defaults, options);}if (opts.pNotify_before_init) {if (opts.pNotify_before_init(opts) === false)return null;}var pNotify = $("<div />", {"class": "ui-widget ui-helper-clearfix ui-pnotify "+opts.pNotify_addclass,"css": {"display": "none"},"mouseenter": function(){if (animating == "out") {pNotify.stop(true);pNotify.css("height", "auto").animate({"width": opts.pNotify_width, "opacity": opts.pNotify_opacity}, "fast");}if (opts.pNotify_hide) pNotify.pNotify_cancel_remove();if (opts.pNotify_closer) pNotify.closer.show();},"mouseleave": function(){if (opts.pNotify_hide) pNotify.pNotify_queue_remove();pNotify.closer.hide();$.pNotify_position_all();}});pNotify.opts = opts;if (opts.pNotify_shadow)pNotify.shadow_container = $("<div />", {"class": "ui-widget-shadow ui-pnotify-shadow"}).prependTo(pNotify);pNotify.container = $("<div />", {"class": "ui-corner-all ui-pnotify-container "+(opts.type == "error" ? "ui-state-error" : "ui-state-highlight")}).appendTo(pNotify);pNotify.pNotify_version = "1.0.0";pNotify.pNotify = function(options) {var old_opts = opts;if (typeof options == "string") {opts.text = options;} else {opts = $.extend({}, opts, options);}pNotify.opts = opts;if (opts.pNotify_shadow != old_opts.pNotify_shadow) {if (opts.pNotify_shadow)pNotify.shadow_container = $("<div />", {"class": "ui-widget-shadow ui-pnotify-shadow"}).prependTo(pNotify);elsepNotify.children(".ui-pnotify-shadow").remove();}if (opts.pNotify_addclass === false) {pNotify.removeClass(old_opts.pNotify_addclass);} else if (opts.pNotify_addclass !== old_opts.pNotify_addclass) {pNotify.removeClass(old_opts.pNotify_addclass).addClass(opts.pNotify_addclass);}if (opts.title === false) {pNotify.title_container.hide("fast");} else if (opts.title !== old_opts.title) {pNotify.title_container.html(opts.title).show("fast");}if (opts.text === false) {pNotify.text_container.hide("fast");} else if (opts.text !== old_opts.text) {if (opts.pNotify_insert_brs)opts.text = opts.text.replace("\n", "<br />");pNotify.text_container.html(opts.text).show("fast");}pNotify.pNotify_history = opts.pNotify_history;if (opts.type != old_opts.type)pNotify.container.toggleClass("ui-state-error ui-state-highlight");if ((opts.pNotify_notice_icon != old_opts.pNotify_notice_icon && opts.type == "notice") ||(opts.pNotify_error_icon != old_opts.pNotify_error_icon && opts.type == "error") ||(opts.type != old_opts.type)) {pNotify.container.find("div.ui-pnotify-icon").remove();if ((opts.pNotify_error_icon && opts.type == "error") || (opts.pNotify_notice_icon)) {$("<div />", {"class": "ui-pnotify-icon"}).append($("<span />", {"class": opts.type == "error" ? opts.pNotify_error_icon : opts.pNotify_notice_icon})).prependTo(pNotify.container);}}if (opts.pNotify_width !== old_opts.pNotify_width)pNotify.animate({width: opts.pNotify_width});if (opts.pNotify_min_height !== old_opts.pNotify_min_height)pNotify.container.animate({minHeight: opts.pNotify_min_height});if (opts.pNotify_opacity !== old_opts.pNotify_opacity)pNotify.fadeTo(opts.pNotify_animate_speed, opts.pNotify_opacity);if (!opts.pNotify_hide) {pNotify.pNotify_cancel_remove();} else if (!old_opts.pNotify_hide) {pNotify.pNotify_queue_remove();}pNotify.pNotify_queue_position();return pNotify;};pNotify.pNotify_queue_position = function() {if (timer)clearTimeout(timer);timer = setTimeout($.pNotify_position_all, 10);};pNotify.pNotify_display = function() {if (!pNotify.parent().length)pNotify.appendTo(body);if (opts.pNotify_before_open) {if (opts.pNotify_before_open(pNotify) === false)return;}pNotify.pNotify_queue_position();if (opts.pNotify_animation == "fade" || opts.pNotify_animation.effect_in == "fade") {pNotify.show().fadeTo(0, 0).hide();} else {if (opts.pNotify_opacity != 1)pNotify.show().fadeTo(0, opts.pNotify_opacity).hide();}pNotify.animate_in(function(){if (opts.pNotify_after_open)opts.pNotify_after_open(pNotify);pNotify.pNotify_queue_position();if (opts.pNotify_hide)pNotify.pNotify_queue_remove();});};pNotify.pNotify_remove = function() {if (pNotify.timer) {window.clearTimeout(pNotify.timer);pNotify.timer = null;}if (opts.pNotify_before_close) {if (opts.pNotify_before_close(pNotify) === false)return;}pNotify.animate_out(function(){if (opts.pNotify_after_close) {if (opts.pNotify_after_close(pNotify) === false)return;}pNotify.pNotify_queue_position();if (opts.pNotify_remove)pNotify.detach();});};pNotify.animate_in = function(callback){animating = "in";var animation;if (typeof opts.pNotify_animation.effect_in != "undefined") {animation = opts.pNotify_animation.effect_in;} else {animation = opts.pNotify_animation;}if (animation == "none") {pNotify.show();callback();} else if (animation == "show") {pNotify.show(opts.pNotify_animate_speed, callback);} else if (animation == "fade") {pNotify.show().fadeTo(opts.pNotify_animate_speed, opts.pNotify_opacity, callback);} else if (animation == "slide") {pNotify.slideDown(opts.pNotify_animate_speed, callback);} else if (typeof animation == "function") {animation("in", callback, pNotify);} else {if (pNotify.effect)pNotify.effect(animation, {}, opts.pNotify_animate_speed, callback);}};pNotify.animate_out = function(callback){animating = "out";var animation;if (typeof opts.pNotify_animation.effect_out != "undefined") {animation = opts.pNotify_animation.effect_out;} else {animation = opts.pNotify_animation;}if (animation == "none") {pNotify.hide();callback();} else if (animation == "show") {pNotify.hide(opts.pNotify_animate_speed, callback);} else if (animation == "fade") {pNotify.fadeOut(opts.pNotify_animate_speed, callback);} else if (animation == "slide") {pNotify.slideUp(opts.pNotify_animate_speed, callback);} else if (typeof animation == "function") {animation("out", callback, pNotify);} else {if (pNotify.effect)pNotify.effect(animation, {}, opts.pNotify_animate_speed, callback);}};pNotify.pNotify_cancel_remove = function() {if (pNotify.timer)window.clearTimeout(pNotify.timer);};pNotify.pNotify_queue_remove = function() {pNotify.pNotify_cancel_remove();pNotify.timer = window.setTimeout(function(){pNotify.pNotify_remove();}, (isNaN(opts.delay) ? 0 : opts.delay));};pNotify.closer = $("<div />", {"class": "ui-pnotify-closer","css": {"cursor": "pointer", "display": "none"},"click": function(){pNotify.pNotify_remove();pNotify.closer.hide();}}).append($("<span />", {"class": "ui-icon ui-icon-circle-close"})).appendTo(pNotify.container);if ((opts.pNotify_error_icon && opts.type == "error") || (opts.pNotify_notice_icon)) {$("<div />", {"class": "ui-pnotify-icon"}).append($("<span />", {"class": opts.type == "error" ? opts.pNotify_error_icon : opts.pNotify_notice_icon})).appendTo(pNotify.container);}pNotify.title_container = $("<div />", {"class": "ui-pnotify-title","html": opts.title}).appendTo(pNotify.container);if (typeof opts.title != "string")pNotify.title_container.hide();if (opts.pNotify_insert_brs && typeof opts.text == "string")opts.text = opts.text.replace("\n", "<br />");pNotify.text_container = $("<div />", {"class": "ui-pnotify-text","html": opts.text}).appendTo(pNotify.container);if (typeof opts.text != "string")pNotify.text_container.hide();if (typeof opts.pNotify_width == "string")pNotify.css("width", opts.pNotify_width);if (typeof opts.pNotify_min_height == "string")pNotify.container.css("min-height", opts.pNotify_min_height);pNotify.pNotify_history = opts.pNotify_history;var body_data = body.data("pNotify");if (body_data == null || typeof body_data != "object")body_data = [];body_data = $.merge(body_data, [pNotify]);body.data("pNotify", body_data);if (opts.pNotify_after_init)opts.pNotify_after_init(pNotify);if (opts.pNotify_history) {var body_history = body.data("pNotify_history");if (typeof body_history == "undefined") {body_history = $("<div />", {"class": "ui-pnotify-history-container ui-state-default ui-corner-bottom","mouseleave": function(){body_history.animate({top: "-"+history_handle_top+"px"}, {duration: 100, queue: false});}}).append($("<div />", {"class": "ui-pnotify-history-header", "text": "Redisplay"})).append($("<button />", {"class": "ui-pnotify-history-all ui-state-default ui-corner-all","text": "All","hover": function(){$(this).toggleClass("ui-state-hover");},"click": function(){$.each(body_data, function(){if (this.pNotify_history && this.pNotify_display)this.pNotify_display();});return false;}})).append($("<button />", {"class": "ui-pnotify-history-last ui-state-default ui-corner-all","text": "Last","hover": function(){$(this).toggleClass("ui-state-hover");},"click": function(){var i = 1;while (!body_data[body_data.length - i] || !body_data[body_data.length - i].pNotify_history) {if (body_data.length - i === 0)return false;i++;}if (body_data[body_data.length - i].pNotify_display)body_data[body_data.length - i].pNotify_display();return false;}})).appendTo(body);var handle = $("<span />", {"class": "ui-pnotify-history-pulldown ui-icon ui-icon-grip-dotted-horizontal","mouseenter": function(){body_history.animate({top: "0"}, {duration: 100, queue: false});}}).appendTo(body_history);history_handle_top = handle.offset().top + 2;body_history.css({top: "-"+history_handle_top+"px"});body.data("pNotify_history", body_history);}}pNotify.pNotify_display();return pNotify;}});$.pNotify.defaults = {pNotify_addclass: "",pNotify_history: true,pNotify_width: "300px",pNotify_min_height: "16px",type: "notice",pNotify_notice_icon: "ui-icon ui-icon-info",pNotify_error_icon: "ui-icon ui-icon-alert",pNotify_animation: "fade",pNotify_animate_speed: "slow",pNotify_opacity: 1,pNotify_shadow: false,pNotify_closer: true,pNotify_hide: true,delay: 3000,pNotify_remove: true,pNotify_insert_brs: true,pNotify_stack: {"dir1": "down", "dir2": "left"}};})(jQuery);

