1 /* jQuery Notify UI Widget 1.5 by Eric Hynds
2 * http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/
6 * - jQuery UI 1.8 widget factory
8 * Dual licensed under the MIT and GPL licenses:
9 * http://www.opensource.org/licenses/mit-license.php
10 * http://www.gnu.org/licenses/gpl.html
14 $.widget("ech.notify", {
29 // build and save templates
30 this.element.addClass("ui-notify").children().addClass("ui-notify-message ui-notify-message-style").each(function(i){
31 var key = this.id || i;
33 self.templates[key] = $(this).removeAttr("id").wrap("<div></div>").parent().html(); // because $(this).andSelf().html() no workie
34 }).end().empty().show();
37 create: function(template, msg, opts){
38 if(typeof template === "object"){
44 var tpl = this.templates[ template || this.keys[0]];
46 // remove default styling class if rolling w/ custom classes
47 if(opts && opts.custom){
48 tpl = $(tpl).removeClass("ui-notify-message-style").wrap("<div></div>").parent().html();
51 this.openNotifications = this.openNotifications || 0;
53 // return a new notification instance
54 return new $.ech.notify.instance(this)._create(msg, $.extend({}, this.options, opts), tpl);
58 // instance constructor
59 $.extend($.ech.notify, {
60 instance: function(widget){
61 this.__super = widget;
67 $.extend($.ech.notify.instance.prototype, {
69 _create: function(params, options, template){
70 this.options = options;
74 // build html template
75 html = template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){
76 return ($2 in params) ? params[$2] : '';
80 m = (this.element = $(html)),
83 closelink = m.find(".ui-notify-close");
86 if(typeof this.options.click === "function"){
87 m.addClass("ui-notify-click").bind("click", function(e){
88 self._trigger("click", e, self);
94 closelink.bind("click", function(){
100 this.__super.element.queue("notify", function(){
104 if(typeof options.expires === "number" && options.expires > 0){
105 setTimeout($.proxy(self.close, self), options.expires);
109 if(!this.options.queue || this.__super.openNotifications <= this.options.queue - 1) {
110 this.__super.element.dequeue("notify");
117 var speed = this.options.speed;
119 this.element.fadeTo(speed, 0).slideUp(speed, $.proxy(function(){
120 this._trigger("close");
122 this.element.remove();
123 this.__super.openNotifications -= 1;
124 this.__super.element.dequeue("notify");
131 if(this.isOpen || this._trigger("beforeopen") === false){
137 this.__super.openNotifications += 1;
139 this.element[this.options.stack === "above" ? "prependTo" : "appendTo"](this.__super.element).css({ display:"none", opacity:"" }).fadeIn(this.options.speed, function(){
140 self._trigger("open");
151 _trigger: function(type, e, instance){
152 return this.__super._trigger.call( this, type, e, instance );