diff --git a/IPython/html/static/base/js/notificationarea.js b/IPython/html/static/base/js/notificationarea.js new file mode 100644 index 000000000..53607fea1 --- /dev/null +++ b/IPython/html/static/base/js/notificationarea.js @@ -0,0 +1,83 @@ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'base/js/notificationwidget', +], function($, notificationwidget) { + "use strict"; + + // store reference to the NotificationWidget class + var NotificationWidget = notificationwidget.NotificationWidget; + + /** + * Construct the NotificationArea object. Options are: + * events: $(Events) instance + * save_widget: SaveWidget instance + * notebook: Notebook instance + * keyboard_manager: KeyboardManager instance + * + * @constructor + * @param {string} selector - a jQuery selector string for the + * notification area element + * @param {Object} [options] - a dictionary of keyword arguments. + */ + var NotificationArea = function (selector, options) { + this.selector = selector; + this.events = options.events; + if (this.selector !== undefined) { + this.element = $(selector); + } + this.widget_dict = {}; + }; + + /** + * Get a widget by name, creating it if it doesn't exist. + * + * @method widget + * @param {string} name - the widget name + */ + NotificationArea.prototype.widget = function (name) { + if (this.widget_dict[name] === undefined) { + return this.new_notification_widget(name); + } + return this.get_widget(name); + }; + + /** + * Get a widget by name, throwing an error if it doesn't exist. + * + * @method get_widget + * @param {string} name - the widget name + */ + NotificationArea.prototype.get_widget = function (name) { + if(this.widget_dict[name] === undefined) { + throw('no widgets with this name'); + } + return this.widget_dict[name]; + }; + + /** + * Create a new notification widget with the given name. The + * widget must not already exist. + * + * @method new_notification_widget + * @param {string} name - the widget name + */ + NotificationArea.prototype.new_notification_widget = function (name) { + if (this.widget_dict[name] !== undefined) { + throw('widget with that name already exists!'); + } + + // create the element for the notification widget and add it + // to the notification aread element + var div = $('
').attr('id', 'notification_' + name); + $(this.selector).append(div); + + // create the widget object and return it + this.widget_dict[name] = new NotificationWidget('#notification_' + name); + return this.widget_dict[name]; + }; + + return {'NotificationArea': NotificationArea}; +}); diff --git a/IPython/html/static/notebook/js/notificationwidget.js b/IPython/html/static/base/js/notificationwidget.js similarity index 100% rename from IPython/html/static/notebook/js/notificationwidget.js rename to IPython/html/static/base/js/notificationwidget.js diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 6c4a6a663..3006ab4c4 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -98,7 +98,7 @@ require([ save_widget: save_widget, quick_help: quick_help}, common_options)); - var notification_area = new notificationarea.NotificationArea( + var notification_area = new notificationarea.NotebookNotificationArea( '#notification_area', { events: events, save_widget: save_widget, diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 93ad8a054..2cc43718e 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -1,97 +1,29 @@ -// Copyright (c) IPython Development Team. -// Distributed under the terms of the Modified BSD License. - define([ 'base/js/namespace', 'jquery', 'base/js/utils', 'base/js/dialog', - 'notebook/js/notificationwidget', + 'base/js/notificationarea', 'moment' -], function(IPython, $, utils, dialog, notificationwidget, moment) { +], function(IPython, $, utils, dialog, notificationarea, moment) { "use strict"; - - // store reference to the NotificationWidget class - var NotificationWidget = notificationwidget.NotificationWidget; - - /** - * Construct the NotificationArea object. Options are: - * events: $(Events) instance - * save_widget: SaveWidget instance - * notebook: Notebook instance - * keyboard_manager: KeyboardManager instance - * - * @constructor - * @param {string} selector - a jQuery selector string for the - * notification area element - * @param {Object} [options] - a dictionary of keyword arguments. - */ - var NotificationArea = function (selector, options) { - this.selector = selector; - this.events = options.events; + var NotificationArea = notificationarea.NotificationArea; + + var NotebookNotificationArea = function(selector, options) { + NotificationArea.apply(this, [selector, options]); this.save_widget = options.save_widget; this.notebook = options.notebook; this.keyboard_manager = options.keyboard_manager; - if (this.selector !== undefined) { - this.element = $(selector); - } - this.widget_dict = {}; - }; - - /** - * Get a widget by name, creating it if it doesn't exist. - * - * @method widget - * @param {string} name - the widget name - */ - NotificationArea.prototype.widget = function (name) { - if (this.widget_dict[name] === undefined) { - return this.new_notification_widget(name); - } - return this.get_widget(name); - }; - - /** - * Get a widget by name, throwing an error if it doesn't exist. - * - * @method get_widget - * @param {string} name - the widget name - */ - NotificationArea.prototype.get_widget = function (name) { - if(this.widget_dict[name] === undefined) { - throw('no widgets with this name'); - } - return this.widget_dict[name]; - }; - - /** - * Create a new notification widget with the given name. The - * widget must not already exist. - * - * @method new_notification_widget - * @param {string} name - the widget name - */ - NotificationArea.prototype.new_notification_widget = function (name) { - if (this.widget_dict[name] !== undefined) { - throw('widget with that name already exists!'); - } - - // create the element for the notification widget and add it - // to the notification aread element - var div = $('').attr('id', 'notification_' + name); - $(this.selector).append(div); - - // create the widget object and return it - this.widget_dict[name] = new NotificationWidget('#notification_' + name); - return this.widget_dict[name]; - }; - + } + + NotebookNotificationArea.prototype = Object.create(NotificationArea.prototype); + /** * Initialize the default set of notification widgets. * * @method init_notification_widgets */ - NotificationArea.prototype.init_notification_widgets = function () { + NotebookNotificationArea.prototype.init_notification_widgets = function () { this.init_kernel_notification_widget(); this.init_notebook_notification_widget(); }; @@ -101,7 +33,7 @@ define([ * * @method init_kernel_notification_widget */ - NotificationArea.prototype.init_kernel_notification_widget = function () { + NotebookNotificationArea.prototype.init_kernel_notification_widget = function () { var that = this; var knw = this.new_notification_widget('kernel'); var $kernel_ind_icon = $("#kernel_indicator_icon"); @@ -324,7 +256,7 @@ define([ * * @method init_notebook_notification_widget */ - NotificationArea.prototype.init_notebook_notification_widget = function () { + NotebookNotificationArea.prototype.init_notebook_notification_widget = function () { var nnw = this.new_notification_widget('notebook'); // Notebook events @@ -381,7 +313,8 @@ define([ }); }; - IPython.NotificationArea = NotificationArea; - - return {'NotificationArea': NotificationArea}; + // Backwards compatibility. + IPython.NotificationArea = NotebookNotificationArea; + + return {'NotebookNotificationArea': NotebookNotificationArea}; }); diff --git a/IPython/html/static/texteditor/js/editor.js b/IPython/html/static/texteditor/js/editor.js index 2efc6f084..686181957 100644 --- a/IPython/html/static/texteditor/js/editor.js +++ b/IPython/html/static/texteditor/js/editor.js @@ -63,10 +63,8 @@ function($, content: this.codemirror.getValue(), }; var that = this; - this.contents.save(this.file_path, model, { - success: function() { - that.events.trigger("save_succeeded.TextEditor"); - } + this.contents.save(this.file_path, model).then(function() { + that.events.trigger("save_succeeded.TextEditor"); }); }; diff --git a/IPython/html/static/texteditor/js/main.js b/IPython/html/static/texteditor/js/main.js index 330f3140c..5580bbb96 100644 --- a/IPython/html/static/texteditor/js/main.js +++ b/IPython/html/static/texteditor/js/main.js @@ -10,6 +10,7 @@ require([ 'contents', 'texteditor/js/editor', 'texteditor/js/menubar', + 'texteditor/js/notificationarea', 'custom/custom', ], function( $, @@ -19,7 +20,8 @@ require([ events, contents, editor, - menubar + menubar, + notificationarea ){ page = new page.Page(); @@ -41,6 +43,12 @@ require([ base_url: base_url, editor: editor, }); + + var notification_area = new notificationarea.EditorNotificationArea( + '#notification_area', { + events: events, + }); + notification_area.init_notification_widgets(); editor.load(); page.show(); diff --git a/IPython/html/static/texteditor/js/notificationarea.js b/IPython/html/static/texteditor/js/notificationarea.js new file mode 100644 index 000000000..ee7e2c9f4 --- /dev/null +++ b/IPython/html/static/texteditor/js/notificationarea.js @@ -0,0 +1,34 @@ +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'base/js/notificationarea', + 'moment' +], function(IPython, $, utils, dialog, notificationarea, moment) { + "use strict"; + var NotificationArea = notificationarea.NotificationArea; + + var EditorNotificationArea = function(selector, options) { + NotificationArea.apply(this, [selector, options]); + } + + EditorNotificationArea.prototype = Object.create(NotificationArea.prototype); + + /** + * Initialize the default set of notification widgets. + * + * @method init_notification_widgets + */ + EditorNotificationArea.prototype.init_notification_widgets = function () { + var that = this; + var enw = this.new_notification_widget('editor'); + + this.events.on("save_succeeded.TextEditor", function() { + enw.set_message("File saved", 2000); + }); + }; + + + return {EditorNotificationArea: EditorNotificationArea}; +}); diff --git a/IPython/html/templates/texteditor.html b/IPython/html/templates/texteditor.html index 5078a39e1..4e6f5af5a 100644 --- a/IPython/html/templates/texteditor.html +++ b/IPython/html/templates/texteditor.html @@ -27,12 +27,6 @@ data-file-path="{{file_path}}"