// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. define(['jquery', 'base/js/events'], function($, events) { /** * WidgetArea */ var WidgetArea = function(cell) { this.widget_views = []; this._cell = cell; this._widgets_live = true; this.disposed = false; this._create_elements(); this._bind_events(); } /** * Display a widget view in the cell. */ WidgetArea.prototype.display_widget_view = function(view_promise) { // Display a dummy element var dummy = $('
'); this.widget_subarea.append(dummy); // Display the view. var that = this; return view_promise.then(function(view) { that.widget_area.show(); dummy.replaceWith(view.$el); that.widget_views.push(view); // Check the live state of the view's model. if (view.model.comm_live) { that._widget_live(view); } else { that._widget_dead(view); } // Listen to comm live events for the view. view.on('comm:live', that._widget_live, that); view.on('comm:dead', that._widget_dead, that); return view; }); }; /** * Disposes of the widget area and its widgets. */ WidgetArea.prototype.dispose = function() { this._clear(); this.disposed = true; }; /** * Creates the elements of the widget area and appends them * to the associated cell. */ WidgetArea.prototype._create_elements = function() { var widget_area = $('
') .addClass('widget-area') .hide(); this.widget_area = widget_area; var widget_prompt = $('
') .addClass('prompt') .appendTo(widget_area); var widget_subarea = $('
') .addClass('widget-subarea') .appendTo(widget_area); this.widget_subarea = widget_subarea; var that = this; var widget_clear_buton = $('