Show More
@@ -1,82 +1,82 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // Notification widget |
|
9 | // Notification widget | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var utils = IPython.utils; |
|
14 | var utils = IPython.utils; | |
15 |
|
15 | |||
16 |
|
16 | |||
17 | var NotificationWidget = function (selector) { |
|
17 | var NotificationWidget = function (selector) { | |
18 | this.selector = selector; |
|
18 | this.selector = selector; | |
19 | this.timeout = null; |
|
19 | this.timeout = null; | |
20 | this.busy = false; |
|
20 | this.busy = false; | |
21 | if (this.selector !== undefined) { |
|
21 | if (this.selector !== undefined) { | |
22 | this.element = $(selector); |
|
22 | this.element = $(selector); | |
23 | this.style(); |
|
23 | this.style(); | |
24 | } |
|
24 | } | |
25 | this.element.button(); |
|
25 | this.element.button(); | |
26 | this.element.hide(); |
|
26 | this.element.hide(); | |
27 | var that = this; |
|
27 | var that = this; | |
28 |
|
28 | |||
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | NotificationWidget.prototype.style = function () { |
|
32 | NotificationWidget.prototype.style = function () { | |
33 | this.element.addClass('notification_widget ui-widget ui-widget-content ui-corner-all'); |
|
33 | this.element.addClass('notification_widget ui-widget ui-widget-content ui-corner-all'); | |
34 | this.element.addClass('border-box-sizing'); |
|
34 | this.element.addClass('border-box-sizing'); | |
35 | }; |
|
35 | }; | |
36 |
|
36 | |||
37 | // msg : message to display |
|
37 | // msg : message to display | |
38 | // timeout : time in ms before diseapearing |
|
38 | // timeout : time in ms before diseapearing | |
39 | // |
|
39 | // | |
40 | // if timeout <= 0 |
|
40 | // if timeout <= 0 | |
41 | // click_callback : function called if user click on notification |
|
41 | // click_callback : function called if user click on notification | |
42 | // could return false to prevent the notification to be dismissed |
|
42 | // could return false to prevent the notification to be dismissed | |
43 | NotificationWidget.prototype.set_message = function (msg, timeout, click_callback) { |
|
43 | NotificationWidget.prototype.set_message = function (msg, timeout, click_callback) { | |
44 | var callback = click_callback || function(){return false}; |
|
44 | var callback = click_callback || function() {return false;}; | |
45 | var that = this; |
|
45 | var that = this; | |
46 | this.element.html(msg); |
|
46 | this.element.html(msg); | |
47 | this.element.fadeIn(100); |
|
47 | this.element.fadeIn(100); | |
48 | if (this.timeout !== null) { |
|
48 | if (this.timeout !== null) { | |
49 | clearTimeout(this.timeout); |
|
49 | clearTimeout(this.timeout); | |
50 | this.timeout = null; |
|
50 | this.timeout = null; | |
51 |
} |
|
51 | } | |
52 | if (timeout !== undefined && timeout >=0) { |
|
52 | if (timeout !== undefined && timeout >=0) { | |
53 | this.timeout = setTimeout(function () { |
|
53 | this.timeout = setTimeout(function () { | |
54 | that.element.fadeOut(100, function () {that.element.html('');}); |
|
54 | that.element.fadeOut(100, function () {that.element.html('');}); | |
55 | that.timeout = null; |
|
55 | that.timeout = null; | |
56 | }, timeout); |
|
56 | }, timeout); | |
57 | } else { |
|
57 | } else { | |
58 | this.element.click(function(){ |
|
58 | this.element.click(function() { | |
59 | if( callback() != false){ |
|
59 | if( callback() != false ) { | |
60 | that.element.fadeOut(100, function () {that.element.html('');}); |
|
60 | that.element.fadeOut(100, function () {that.element.html('');}); | |
61 | that.element.unbind('click') |
|
61 | that.element.unbind('click'); | |
62 | } |
|
62 | } | |
63 | if (that.timeout !== undefined) { |
|
63 | if (that.timeout !== undefined) { | |
64 | that.timeout = undefined |
|
64 | that.timeout = undefined; | |
65 | clearTimeout(that.timeout); |
|
65 | clearTimeout(that.timeout); | |
66 | } |
|
66 | } | |
67 | }); |
|
67 | }); | |
68 | } |
|
68 | } | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | NotificationWidget.prototype.get_message = function () { |
|
72 | NotificationWidget.prototype.get_message = function () { | |
73 | return this.element.html(); |
|
73 | return this.element.html(); | |
74 | }; |
|
74 | }; | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | IPython.NotificationWidget = NotificationWidget; |
|
77 | IPython.NotificationWidget = NotificationWidget; | |
78 |
|
78 | |||
79 | return IPython; |
|
79 | return IPython; | |
80 |
|
80 | |||
81 | }(IPython)); |
|
81 | }(IPython)); | |
82 |
|
82 |
General Comments 0
You need to be logged in to leave comments.
Login now