2
* jQuery Notify UI Widget 1.4
3
* Copyright (c) 2010 Eric Hynds
1
/* jQuery Notify UI Widget 1.5 by Eric Hynds
5
2
* http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/
9
6
* - jQuery UI 1.8 widget factory
11
8
* Dual licensed under the MIT and GPL licenses:
12
9
* http://www.opensource.org/licenses/mit-license.php
13
10
* http://www.gnu.org/licenses/gpl.html
18
$.widget("ech.notify", {
30
// build and save templates
31
this.element.addClass("ui-notify").children().addClass("ui-notify-message ui-notify-message-style").each(function(i){
32
var key = this.id || i;
34
self.templates[key] = $(this).removeAttr("id").wrap("<div></div>").parent().html(); // because $(this).andSelf().html() no workie
35
}).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
// return a new notification instance
52
return new $.ech.notify.instance(this)._create(msg, $.extend({}, this.options, opts), tpl);
56
// instance constructor
57
$.extend($.ech.notify, {
58
instance: function(widget){
65
$.extend($.ech.notify.instance.prototype, {
66
_create: function(params, options, template){
67
this.options = options;
71
// build html template
72
html = template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){
73
return ($2 in params) ? params[$2] : '';
77
m = (this.element = $(html)),
80
closelink = m.find(".ui-notify-close");
83
if(typeof this.options.click === "function"){
84
m.addClass("ui-notify-click").bind("click", function(e){
85
self._trigger("click", e, self);
91
closelink.bind("click", function(){
100
if(typeof options.expires === "number"){
101
window.setTimeout(function(){
109
var self = this, speed = this.options.speed;
111
this.element.fadeTo(speed, 0).slideUp(speed, function(){
112
self._trigger("close");
119
if(this.isOpen || this._trigger("beforeopen") === false){
125
this.element[this.options.stack === 'above' ? 'prependTo' : 'appendTo'](this.parent.element).css({ display:"none", opacity:"" }).fadeIn(this.options.speed, function(){
126
self._trigger("open");
135
_trigger: function(type, e, instance){
136
return this.parent._trigger.call( this, type, e, instance );
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 );