Show More
@@ -11,16 +11,22 define([ | |||
|
11 | 11 | ], function(IPython, $, utils, dialog, notificationwidget, moment) { |
|
12 | 12 | "use strict"; |
|
13 | 13 | |
|
14 | // store reference to the NotificationWidget class | |
|
15 | var NotificationWidget = notificationwidget.NotificationWidget; | |
|
16 | ||
|
17 | /** | |
|
18 | * Construct the NotificationArea object. Options are: | |
|
19 | * events: $(Events) instance | |
|
20 | * save_widget: SaveWidget instance | |
|
21 | * notebook: Notebook instance | |
|
22 | * keyboard_manager: KeyboardManager instance | |
|
23 | * | |
|
24 | * @constructor | |
|
25 | * @param {string} selector - a jQuery selector string for the | |
|
26 | * notification area element | |
|
27 | * @param {Object} [options] - a dictionary of keyword arguments. | |
|
28 | */ | |
|
14 | 29 | var NotificationArea = function (selector, options) { |
|
15 | // Constructor | |
|
16 | // | |
|
17 | // Parameters: | |
|
18 | // selector: string | |
|
19 | // options: dictionary | |
|
20 | // Dictionary of keyword arguments. | |
|
21 | // notebook: Notebook instance | |
|
22 | // events: $(Events) instance | |
|
23 | // save_widget: SaveWidget instance | |
|
24 | 30 | this.selector = selector; |
|
25 | 31 | this.events = options.events; |
|
26 | 32 | this.save_widget = options.save_widget; |
@@ -32,47 +38,70 define([ | |||
|
32 | 38 | this.widget_dict = {}; |
|
33 | 39 | }; |
|
34 | 40 | |
|
35 | NotificationArea.prototype.temp_message = function (msg, timeout, css_class) { | |
|
36 | var tdiv = $('<div>') | |
|
37 | .addClass('notification_widget') | |
|
38 | .addClass(css_class) | |
|
39 | .hide() | |
|
40 | .text(msg); | |
|
41 | ||
|
42 | $(this.selector).append(tdiv); | |
|
43 | var tmout = Math.max(1500,(timeout||1500)); | |
|
44 | tdiv.fadeIn(100); | |
|
45 | ||
|
46 | setTimeout(function () { | |
|
47 | tdiv.fadeOut(100, function () {tdiv.remove();}); | |
|
48 | }, tmout); | |
|
49 | }; | |
|
50 | ||
|
51 | NotificationArea.prototype.widget = function(name) { | |
|
52 | if(this.widget_dict[name] === undefined) { | |
|
41 | /** | |
|
42 | * Get a widget by name, creating it if it doesn't exist. | |
|
43 | * | |
|
44 | * @method widget | |
|
45 | * @param {string} name - the widget name | |
|
46 | */ | |
|
47 | NotificationArea.prototype.widget = function (name) { | |
|
48 | if (this.widget_dict[name] === undefined) { | |
|
53 | 49 | return this.new_notification_widget(name); |
|
54 | 50 | } |
|
55 | 51 | return this.get_widget(name); |
|
56 | 52 | }; |
|
57 | 53 | |
|
58 | NotificationArea.prototype.get_widget = function(name) { | |
|
54 | /** | |
|
55 | * Get a widget by name, throwing an error if it doesn't exist. | |
|
56 | * | |
|
57 | * @method get_widget | |
|
58 | * @param {string} name - the widget name | |
|
59 | */ | |
|
60 | NotificationArea.prototype.get_widget = function (name) { | |
|
59 | 61 | if(this.widget_dict[name] === undefined) { |
|
60 | 62 | throw('no widgets with this name'); |
|
61 | 63 | } |
|
62 | 64 | return this.widget_dict[name]; |
|
63 | 65 | }; |
|
64 | 66 | |
|
65 | NotificationArea.prototype.new_notification_widget = function(name) { | |
|
66 | if(this.widget_dict[name] !== undefined) { | |
|
67 |
|
|
|
67 | /** | |
|
68 | * Create a new notification widget with the given name. The | |
|
69 | * widget must not already exist. | |
|
70 | * | |
|
71 | * @method new_notification_widget | |
|
72 | * @param {string} name - the widget name | |
|
73 | */ | |
|
74 | NotificationArea.prototype.new_notification_widget = function (name) { | |
|
75 | if (this.widget_dict[name] !== undefined) { | |
|
76 | throw('widget with that name already exists!'); | |
|
68 | 77 | } |
|
69 | var div = $('<div/>').attr('id','notification_'+name); | |
|
78 | ||
|
79 | // create the element for the notification widget and add it | |
|
80 | // to the notification aread element | |
|
81 | var div = $('<div/>').attr('id', 'notification_' + name); | |
|
70 | 82 | $(this.selector).append(div); |
|
71 | this.widget_dict[name] = new notificationwidget.NotificationWidget('#notification_'+name); | |
|
83 | ||
|
84 | // create the widget object and return it | |
|
85 | this.widget_dict[name] = new NotificationWidget('#notification_' + name); | |
|
72 | 86 | return this.widget_dict[name]; |
|
73 | 87 | }; |
|
74 | 88 | |
|
75 | NotificationArea.prototype.init_notification_widgets = function() { | |
|
89 | /** | |
|
90 | * Initialize the default set of notification widgets. | |
|
91 | * | |
|
92 | * @method init_notification_widgets | |
|
93 | */ | |
|
94 | NotificationArea.prototype.init_notification_widgets = function () { | |
|
95 | this.init_kernel_notification_widget(); | |
|
96 | this.init_notebook_notification_widget(); | |
|
97 | }; | |
|
98 | ||
|
99 | /** | |
|
100 | * Initialize the notification widget for kernel status messages. | |
|
101 | * | |
|
102 | * @method init_kernel_notification_widget | |
|
103 | */ | |
|
104 | NotificationArea.prototype.init_kernel_notification_widget = function () { | |
|
76 | 105 | var that = this; |
|
77 | 106 | var knw = this.new_notification_widget('kernel'); |
|
78 | 107 | var $kernel_ind_icon = $("#kernel_indicator_icon"); |
@@ -194,8 +223,14 define([ | |||
|
194 | 223 | } |
|
195 | 224 | }); |
|
196 | 225 | }); |
|
226 | }; | |
|
197 | 227 | |
|
198 | ||
|
228 | /** | |
|
229 | * Initialize the notification widget for notebook status messages. | |
|
230 | * | |
|
231 | * @method init_notebook_notification_widget | |
|
232 | */ | |
|
233 | NotificationArea.prototype.init_notebook_notification_widget = function () { | |
|
199 | 234 | var nnw = this.new_notification_widget('notebook'); |
|
200 | 235 | |
|
201 | 236 | // Notebook events |
@@ -247,7 +282,6 define([ | |||
|
247 | 282 | this.events.on('autosave_enabled.Notebook', function (evt, interval) { |
|
248 | 283 | nnw.set_message("Saving every " + interval / 1000 + "s", 1000); |
|
249 | 284 | }); |
|
250 | ||
|
251 | 285 | }; |
|
252 | 286 | |
|
253 | 287 | IPython.NotificationArea = NotificationArea; |
@@ -7,6 +7,13 define([ | |||
|
7 | 7 | ], function(IPython, $) { |
|
8 | 8 | "use strict"; |
|
9 | 9 | |
|
10 | /** | |
|
11 | * Construct a NotificationWidget object. | |
|
12 | * | |
|
13 | * @constructor | |
|
14 | * @param {string} selector - a jQuery selector string for the | |
|
15 | * notification widget element | |
|
16 | */ | |
|
10 | 17 | var NotificationWidget = function (selector) { |
|
11 | 18 | this.selector = selector; |
|
12 | 19 | this.timeout = null; |
General Comments 0
You need to be logged in to leave comments.
Login now