diff --git a/IPython/html/static/notebook/js/widget.js b/IPython/html/static/notebook/js/widget.js index f4c2bb8d8..d4cecd02e 100644 --- a/IPython/html/static/notebook/js/widget.js +++ b/IPython/html/static/notebook/js/widget.js @@ -20,8 +20,8 @@ // Use require.js 'define' method so that require.js is intelligent enough to // syncronously load everything within this file when it is being 'required' // elsewhere. -define(["../../components/underscore/underscore-min.js", - "../../components/backbone/backbone-min.js", +define(["components/underscore/underscore-min", + "components/backbone/backbone-min", ], function(){ // Only run once on a notebook. @@ -188,6 +188,45 @@ define(["../../components/underscore/underscore-min.js", // Create view that represents the model. display_view: function (view_name, parent_comm_id, cell_index) { + var new_views = []; + + var displayed = false; + if (parent_comm_id != undefined) { + var parent_comm = this.comm_manager.comms[parent_comm_id]; + var parent_model = parent_comm.model; + var parent_views = parent_model.views[cell_index]; + for (var parent_view_index in parent_views) { + var parent_view = parent_views[parent_view_index]; + if (parent_view.display_child != undefined) { + var view = this._create_view(view_name, cell_index); + new_views.push(view); + parent_view.display_child(view); + displayed = true; + } + } + } + + if (!displayed) { + // No parent view is defined or exists. Add the view's + // element to cell's widget div. + var view = this._create_view(view_name, cell_index); + new_views.push(view); + var cell = IPython.notebook.get_cell(cell_index); + cell.element.find('.widget_area').find('.widget_subarea') + .append(view.$el) + .parent().show(); // Show the widget_area (parent of widget_subarea) + + } + + for (var view_index in new_views) { + var view = new_views[view_index]; + view.update(); + } + }, + + + // Create a view + _create_view: function (view_name, cell_index) { var view = new this.widget_view_types[view_name]({model: this}); view.render(); if (this.views[cell_index]==undefined) { @@ -213,30 +252,7 @@ define(["../../components/underscore/underscore-min.js", that.comm.close(); } }); - - var displayed = false; - if (parent_comm_id != undefined) { - var parent_comm = this.comm_manager.comms[parent_comm_id]; - var parent_model = parent_comm.model; - var parent_view = parent_model.views[cell_index]; - if (parent_view.display_child != undefined) { - parent_view.display_child(view); - displayed = true; - } - } - - if (!displayed) { - // No parent view is defined or exists. Add the view's - // element to cell's widget div. - var cell = IPython.notebook.get_cell(cell_index); - cell.element.find('.widget_area').find('.widget_subarea') - .append(view.$el) - .parent().show(); // Show the widget_area (parent of widget_subarea) - - } - - // Update the view based on the model contents. - view.update(); + return view; }, @@ -262,7 +278,7 @@ define(["../../components/underscore/underscore-min.js", // Get the cell index corresponding to the msg_id. _get_cell_index: function (msg_id) { var cells = IPython.notebook.get_cells(); - for (cell_index in cells) { + for (var cell_index in cells) { if (cells[cell_index].last_msg_id == msg_id) { return cell_index; } diff --git a/IPython/html/static/notebook/js/widgets/bool.js b/IPython/html/static/notebook/js/widgets/bool.js index e1ba2cc7d..ebf9d559b 100644 --- a/IPython/html/static/notebook/js/widgets/bool.js +++ b/IPython/html/static/notebook/js/widgets/bool.js @@ -1,5 +1,5 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var BoolWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('BoolWidgetModel', BoolWidgetModel); diff --git a/IPython/html/static/notebook/js/widgets/button.js b/IPython/html/static/notebook/js/widgets/button.js index 78c1e3377..f22367634 100644 --- a/IPython/html/static/notebook/js/widgets/button.js +++ b/IPython/html/static/notebook/js/widgets/button.js @@ -1,5 +1,5 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var ButtonWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('ButtonWidgetModel', ButtonWidgetModel); diff --git a/IPython/html/static/notebook/js/widgets/container.js b/IPython/html/static/notebook/js/widgets/container.js index b763849e7..363d1a090 100644 --- a/IPython/html/static/notebook/js/widgets/container.js +++ b/IPython/html/static/notebook/js/widgets/container.js @@ -1,4 +1,4 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var ContainerModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel); diff --git a/IPython/html/static/notebook/js/widgets/float.js b/IPython/html/static/notebook/js/widgets/float.js index 349b68f43..a793d2af3 100644 --- a/IPython/html/static/notebook/js/widgets/float.js +++ b/IPython/html/static/notebook/js/widgets/float.js @@ -1,4 +1,4 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var FloatWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('FloatWidgetModel', FloatWidgetModel); }); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/int.js b/IPython/html/static/notebook/js/widgets/int.js index 0cb7d8ffd..459586264 100644 --- a/IPython/html/static/notebook/js/widgets/int.js +++ b/IPython/html/static/notebook/js/widgets/int.js @@ -1,4 +1,4 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var IntWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('IntWidgetModel', IntWidgetModel); }); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/selection.js b/IPython/html/static/notebook/js/widgets/selection.js index 40b753dc9..15cfa38c2 100644 --- a/IPython/html/static/notebook/js/widgets/selection.js +++ b/IPython/html/static/notebook/js/widgets/selection.js @@ -1,4 +1,4 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var SelectionWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel); diff --git a/IPython/html/static/notebook/js/widgets/string.js b/IPython/html/static/notebook/js/widgets/string.js index ea11881d3..3baebaec3 100644 --- a/IPython/html/static/notebook/js/widgets/string.js +++ b/IPython/html/static/notebook/js/widgets/string.js @@ -1,4 +1,4 @@ -require(["../static/notebook/js/widget"], function(){ +require(["notebook/js/widget"], function(){ var StringWidgetModel = IPython.WidgetModel.extend({}); IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);