// Copyright (c) IPython Development Team.1// Distributed under the terms of the Modified BSD License.23define([4'jquery',5'base/js/notificationwidget',6], function($, notificationwidget) {7"use strict";89// store reference to the NotificationWidget class10var NotificationWidget = notificationwidget.NotificationWidget;1112/**13* Construct the NotificationArea object. Options are:14* events: $(Events) instance15* save_widget: SaveWidget instance16* notebook: Notebook instance17* keyboard_manager: KeyboardManager instance18*19* @constructor20* @param {string} selector - a jQuery selector string for the21* notification area element22* @param {Object} [options] - a dictionary of keyword arguments.23*/24var NotificationArea = function (selector, options) {25this.selector = selector;26this.events = options.events;27if (this.selector !== undefined) {28this.element = $(selector);29}30this.widget_dict = {};31};3233/**34* Get a widget by name, creating it if it doesn't exist.35*36* @method widget37* @param {string} name - the widget name38*/39NotificationArea.prototype.widget = function (name) {40if (this.widget_dict[name] === undefined) {41return this.new_notification_widget(name);42}43return this.get_widget(name);44};4546/**47* Get a widget by name, throwing an error if it doesn't exist.48*49* @method get_widget50* @param {string} name - the widget name51*/52NotificationArea.prototype.get_widget = function (name) {53if(this.widget_dict[name] === undefined) {54throw('no widgets with this name');55}56return this.widget_dict[name];57};5859/**60* Create a new notification widget with the given name. The61* widget must not already exist.62*63* @method new_notification_widget64* @param {string} name - the widget name65*/66NotificationArea.prototype.new_notification_widget = function (name) {67if (this.widget_dict[name] !== undefined) {68throw('widget with that name already exists!');69}7071// create the element for the notification widget and add it72// to the notification aread element73var div = $('<div/>').attr('id', 'notification_' + name);74$(this.selector).append(div);7576// create the widget object and return it77this.widget_dict[name] = new NotificationWidget('#notification_' + name);78return this.widget_dict[name];79};8081return {'NotificationArea': NotificationArea};82});838485