Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50650 views
1
// Copyright (c) IPython Development Team.
2
// Distributed under the terms of the Modified BSD License.
3
4
define([
5
'jquery',
6
'base/js/notificationwidget',
7
], function($, notificationwidget) {
8
"use strict";
9
10
// store reference to the NotificationWidget class
11
var NotificationWidget = notificationwidget.NotificationWidget;
12
13
/**
14
* Construct the NotificationArea object. Options are:
15
* events: $(Events) instance
16
* save_widget: SaveWidget instance
17
* notebook: Notebook instance
18
* keyboard_manager: KeyboardManager instance
19
*
20
* @constructor
21
* @param {string} selector - a jQuery selector string for the
22
* notification area element
23
* @param {Object} [options] - a dictionary of keyword arguments.
24
*/
25
var NotificationArea = function (selector, options) {
26
this.selector = selector;
27
this.events = options.events;
28
if (this.selector !== undefined) {
29
this.element = $(selector);
30
}
31
this.widget_dict = {};
32
};
33
34
/**
35
* Get a widget by name, creating it if it doesn't exist.
36
*
37
* @method widget
38
* @param {string} name - the widget name
39
*/
40
NotificationArea.prototype.widget = function (name) {
41
if (this.widget_dict[name] === undefined) {
42
return this.new_notification_widget(name);
43
}
44
return this.get_widget(name);
45
};
46
47
/**
48
* Get a widget by name, throwing an error if it doesn't exist.
49
*
50
* @method get_widget
51
* @param {string} name - the widget name
52
*/
53
NotificationArea.prototype.get_widget = function (name) {
54
if(this.widget_dict[name] === undefined) {
55
throw('no widgets with this name');
56
}
57
return this.widget_dict[name];
58
};
59
60
/**
61
* Create a new notification widget with the given name. The
62
* widget must not already exist.
63
*
64
* @method new_notification_widget
65
* @param {string} name - the widget name
66
*/
67
NotificationArea.prototype.new_notification_widget = function (name) {
68
if (this.widget_dict[name] !== undefined) {
69
throw('widget with that name already exists!');
70
}
71
72
// create the element for the notification widget and add it
73
// to the notification aread element
74
var div = $('<div/>').attr('id', 'notification_' + name);
75
$(this.selector).append(div);
76
77
// create the widget object and return it
78
this.widget_dict[name] = new NotificationWidget('#notification_' + name);
79
return this.widget_dict[name];
80
};
81
82
return {'NotificationArea': NotificationArea};
83
});
84
85