Show More
@@ -16,11 +16,8 define([ | |||
|
16 | 16 | this.style(); |
|
17 | 17 | } |
|
18 | 18 | this.element.hide(); |
|
19 | var that = this; | |
|
20 | ||
|
21 | 19 | this.inner = $('<span/>'); |
|
22 | 20 | this.element.append(this.inner); |
|
23 | ||
|
24 | 21 | }; |
|
25 | 22 | |
|
26 | 23 | NotificationWidget.prototype.style = function () { |
@@ -34,9 +31,8 define([ | |||
|
34 | 31 | // click_callback : function called if user click on notification |
|
35 | 32 | // could return false to prevent the notification to be dismissed |
|
36 | 33 | NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) { |
|
37 |
|
|
|
38 | var callback = click_callback || function() {return true;}; | |
|
39 | var that = this; | |
|
34 | options = options || {}; | |
|
35 | ||
|
40 | 36 | // unbind potential previous callback |
|
41 | 37 | this.element.unbind('click'); |
|
42 | 38 | this.inner.attr('class', options.icon); |
@@ -48,50 +44,58 define([ | |||
|
48 | 44 | this.element.removeClass(); |
|
49 | 45 | this.style(); |
|
50 | 46 | if (options.class){ |
|
51 | ||
|
52 | this.element.addClass(options.class) | |
|
47 | this.element.addClass(options.class); | |
|
53 | 48 | } |
|
49 | ||
|
50 | // clear previous timer | |
|
54 | 51 | if (this.timeout !== null) { |
|
55 | 52 | clearTimeout(this.timeout); |
|
56 | 53 | this.timeout = null; |
|
57 | 54 | } |
|
58 | if (timeout !== undefined && timeout >=0) { | |
|
55 | ||
|
56 | // set the timer if a timeout is given | |
|
57 | var that = this; | |
|
58 | if (timeout !== undefined && timeout >= 0) { | |
|
59 | 59 | this.timeout = setTimeout(function () { |
|
60 | 60 | that.element.fadeOut(100, function () {that.inner.text('');}); |
|
61 | that.element.unbind('click'); | |
|
61 | 62 | that.timeout = null; |
|
62 | 63 | }, timeout); |
|
63 |
} |
|
|
64 | } | |
|
65 | ||
|
66 | // bind the click callback if it is given | |
|
67 | if (click_callback !== undefined) { | |
|
64 | 68 | this.element.click(function() { |
|
65 |
if( |
|
|
69 | if (click_callback() !== false) { | |
|
66 | 70 | that.element.fadeOut(100, function () {that.inner.text('');}); |
|
67 | 71 | that.element.unbind('click'); |
|
68 | 72 | } |
|
69 |
if (that.timeout !== |
|
|
70 | that.timeout = undefined; | |
|
73 | if (that.timeout !== null) { | |
|
71 | 74 | clearTimeout(that.timeout); |
|
75 | that.timeout = null; | |
|
72 | 76 | } |
|
73 | 77 | }); |
|
74 | 78 | } |
|
75 | 79 | }; |
|
76 | 80 | |
|
77 | ||
|
78 | 81 | NotificationWidget.prototype.info = function (msg, timeout, click_callback, options) { |
|
79 |
|
|
|
80 | options.class = options.class +' info'; | |
|
81 |
|
|
|
82 | options = options || {}; | |
|
83 | options.class = options.class + ' info'; | |
|
84 | timeout = timeout || 3500; | |
|
82 | 85 | this.set_message(msg, timeout, click_callback, options); |
|
83 | } | |
|
86 | }; | |
|
87 | ||
|
84 | 88 | NotificationWidget.prototype.warning = function (msg, timeout, click_callback, options) { |
|
85 |
|
|
|
86 | options.class = options.class +' warning'; | |
|
89 | options = options || {}; | |
|
90 | options.class = options.class + ' warning'; | |
|
87 | 91 | this.set_message(msg, timeout, click_callback, options); |
|
88 | } | |
|
92 | }; | |
|
93 | ||
|
89 | 94 | NotificationWidget.prototype.danger = function (msg, timeout, click_callback, options) { |
|
90 |
|
|
|
91 | options.class = options.class +' danger'; | |
|
95 | options = options || {}; | |
|
96 | options.class = options.class + ' danger'; | |
|
92 | 97 | this.set_message(msg, timeout, click_callback, options); |
|
93 | } | |
|
94 | ||
|
98 | }; | |
|
95 | 99 | |
|
96 | 100 | NotificationWidget.prototype.get_message = function () { |
|
97 | 101 | return this.inner.html(); |
General Comments 0
You need to be logged in to leave comments.
Login now