~openerp-dev/openerp-web/trunk-jquery1.9-ppa

« back to all changes in this revision

Viewing changes to addons/web/static/lib/jquery.ui.notify/js/jquery.notify.js

  • Committer: Prashant Panchal(OpenERP)
  • Date: 2014-04-16 09:24:51 UTC
  • Revision ID: ppa@tinyerp.com-20140416092451-outv36dahgip1860
[IMP] add jquery-migrate-1.1.1.j & jquery-1.9.1.js & change in web

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * jQuery Notify UI Widget 1.4
3
 
 * Copyright (c) 2010 Eric Hynds
4
 
 *
 
1
/* jQuery Notify UI Widget 1.5 by Eric Hynds
5
2
 * http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/
6
3
 *
7
4
 * Depends:
8
 
 *   - jQuery 1.4
 
5
 *   - jQuery 1.4+
9
6
 *   - jQuery UI 1.8 widget factory
10
7
 *
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
14
 
 *
15
11
*/
16
12
(function($){
17
13
 
18
 
$.widget("ech.notify", {
19
 
        options: {
20
 
                speed: 500,
21
 
                expires: 5000,
22
 
                stack: 'below',
23
 
                custom: false
24
 
        },
25
 
        _create: function(){
26
 
                var self = this;
27
 
                this.templates = {};
28
 
                this.keys = [];
29
 
                
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;
33
 
                        self.keys.push(key);
34
 
                        self.templates[key] = $(this).removeAttr("id").wrap("<div></div>").parent().html(); // because $(this).andSelf().html() no workie
35
 
                }).end().empty().show();
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
 
                // return a new notification instance
52
 
                return new $.ech.notify.instance(this)._create(msg, $.extend({}, this.options, opts), tpl);
53
 
        }
54
 
});
55
 
 
56
 
// instance constructor
57
 
$.extend($.ech.notify, {
58
 
        instance: function(widget){
59
 
                this.parent = widget;
60
 
                this.isOpen = false;
61
 
        }
62
 
});
63
 
 
64
 
// instance methods
65
 
$.extend($.ech.notify.instance.prototype, {
66
 
        _create: function(params, options, template){
67
 
                this.options = options;
68
 
                
69
 
                var self = this,
70
 
                        
71
 
                        // build html template
72
 
                        html = template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){
73
 
                                return ($2 in params) ? params[$2] : '';
74
 
                        }),
75
 
                        
76
 
                        // the actual message
77
 
                        m = (this.element = $(html)),
78
 
                        
79
 
                        // close link
80
 
                        closelink = m.find(".ui-notify-close");
81
 
                
82
 
                // clickable?
83
 
                if(typeof this.options.click === "function"){
84
 
                        m.addClass("ui-notify-click").bind("click", function(e){
85
 
                                self._trigger("click", e, self);
86
 
                        });
87
 
                }
88
 
                
89
 
                // show close link?
90
 
                if(closelink.length){
91
 
                        closelink.bind("click", function(){
92
 
                                self.close();
93
 
                                return false;
94
 
                        });
95
 
                }
96
 
                
97
 
                this.open();
98
 
                
99
 
                // auto expire?
100
 
                if(typeof options.expires === "number"){
101
 
                        window.setTimeout(function(){
102
 
                                self.close();
103
 
                        }, options.expires);
104
 
                }
105
 
                
106
 
                return this;
107
 
        },
108
 
        close: function(){
109
 
                var self = this, speed = this.options.speed;
110
 
                
111
 
                this.element.fadeTo(speed, 0).slideUp(speed, function(){
112
 
                        self._trigger("close");
113
 
                        self.isOpen = false;
114
 
                });
115
 
                
116
 
                return this;
117
 
        },
118
 
        open: function(){
119
 
                if(this.isOpen || this._trigger("beforeopen") === false){
120
 
                        return this;
121
 
                }
122
 
 
123
 
                var self = this;
124
 
                
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");
127
 
                        self.isOpen = true;
128
 
                });
129
 
                
130
 
                return this;
131
 
        },
132
 
        widget: function(){
133
 
                return this.element;
134
 
        },
135
 
        _trigger: function(type, e, instance){
136
 
                return this.parent._trigger.call( this, type, e, instance );
137
 
        }
138
 
});
 
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
  });
139
155
 
140
156
})(jQuery);