fixed static file collection for third party components: now relying on symlinks
[myslice.git] / third-party / jquery-notify-1.5 / jquery.notify.js
1 /* jQuery Notify UI Widget 1.5 by Eric Hynds
2  * http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/
3  *
4  * Depends:
5  *   - jQuery 1.4+
6  *   - jQuery UI 1.8 widget factory
7  *
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
11 */
12 (function($){
13
14   $.widget("ech.notify", {
15
16     options: {
17       speed: 500,
18       expires: 5000,
19       stack: "below",
20       custom: false,
21       queue: false
22     },
23
24     _create: function(){
25       var self = this;
26       this.templates = {};
27       this.keys = [];
28
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;
32         self.keys.push(key);
33         self.templates[key] = $(this).removeAttr("id").wrap("<div></div>").parent().html(); // because $(this).andSelf().html() no workie
34       }).end().empty().show();
35     },
36
37     create: function(template, msg, opts){
38       if(typeof template === "object"){
39         opts = msg;
40         msg = template;
41         template = null;
42       }
43
44       var tpl = this.templates[ template || this.keys[0]];
45
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();
49       }
50
51       this.openNotifications = this.openNotifications || 0;
52
53       // return a new notification instance
54       return new $.ech.notify.instance(this)._create(msg, $.extend({}, this.options, opts), tpl);            
55     }
56   });
57
58   // instance constructor
59   $.extend($.ech.notify, {
60     instance: function(widget){
61       this.__super = widget;
62       this.isOpen = false;
63     }
64   });
65
66   // instance methods
67   $.extend($.ech.notify.instance.prototype, {
68
69     _create: function(params, options, template){
70       this.options = options;
71
72       var self = this,
73
74       // build html template
75       html = template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){
76         return ($2 in params) ? params[$2] : '';
77       }),
78
79       // the actual message
80       m = (this.element = $(html)),
81
82       // close link
83       closelink = m.find(".ui-notify-close");
84
85       // clickable?
86       if(typeof this.options.click === "function"){
87         m.addClass("ui-notify-click").bind("click", function(e){
88           self._trigger("click", e, self);
89         });
90       }
91
92       // show close link?
93       if(closelink.length){
94         closelink.bind("click", function(){
95           self.close();
96           return false;
97         });
98       }
99
100       this.__super.element.queue("notify", function(){
101         self.open();
102
103         // auto expire?
104         if(typeof options.expires === "number" && options.expires > 0){
105           setTimeout($.proxy(self.close, self), options.expires);
106         }
107       });
108
109       if(!this.options.queue || this.__super.openNotifications <= this.options.queue - 1) {
110         this.__super.element.dequeue("notify");
111       }
112
113       return this;
114     },
115
116     close: function(){
117       var speed = this.options.speed;
118
119       this.element.fadeTo(speed, 0).slideUp(speed, $.proxy(function(){
120         this._trigger("close");
121         this.isOpen = false;
122         this.element.remove();
123         this.__super.openNotifications -= 1;
124         this.__super.element.dequeue("notify");
125       }, this));
126
127       return this;
128     },
129
130     open: function(){
131       if(this.isOpen || this._trigger("beforeopen") === false){
132         return this;
133       }
134
135       var self = this;
136
137       this.__super.openNotifications += 1;
138
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");
141         self.isOpen = true;
142       });
143
144       return this;
145     },
146
147     widget: function(){
148       return this.element;
149     },
150
151     _trigger: function(type, e, instance){
152       return this.__super._trigger.call( this, type, e, instance );
153     }
154   });
155
156 })(jQuery);