//---------------------------------------------------------------------------- // Copyright (C) 2013 The IPython Development Team // // Distributed under the terms of the BSD License. The full license is in // the file COPYING, distributed as part of this software. //---------------------------------------------------------------------------- //============================================================================ // ContainerWidget //============================================================================ /** * @module IPython * @namespace IPython **/ define(["notebook/js/widgets/widget"], function(widget_manager) { var set_flex_property = function(element, property_name, enabled) { if (enabled) { element.addClass(property_name); } else { element.removeClass(property_name); } }; var set_flex_properties = function(context, element) { // Apply flexible box model properties by adding and removing // corrosponding CSS classes. // Defined in IPython/html/static/base/less/flexbox.less set_flex_property(element, 'vbox', context.model.get('_vbox')); set_flex_property(element, 'hbox', context.model.get('_hbox')); set_flex_property(element, 'start', context.model.get('_pack_start')); set_flex_property(element, 'center', context.model.get('_pack_center')); set_flex_property(element, 'end', context.model.get('_pack_end')); set_flex_property(element, 'align-start', context.model.get('_align_start')); set_flex_property(element, 'align-center', context.model.get('_align_center')); set_flex_property(element, 'align-end', context.model.get('_align_end')); set_flex_property(element, 'box-flex0', context.model.get('_flex0')); set_flex_property(element, 'box-flex1', context.model.get('_flex1')); set_flex_property(element, 'box-flex2', context.model.get('_flex2')); }; var ContainerModel = IPython.WidgetModel.extend({}); widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel); var ContainerView = IPython.DOMWidgetView.extend({ render: function(){ this.$el .addClass('widget-container'); this.children={}; this.update_children([], this.model.get('children')); this.model.on('change:children', function(model, value, options) { this.update_children(model.previous('children'), value); }, this); this.update() }, update_children: function(old_list, new_list) { this.$el.empty(); this.update_child_views(old_list, new_list); _.each(new_list, function(element, index, list) { this.$el.append(this.child_views[element].$el); }, this) }, update: function(){ // Update the contents of this view // // Called when the model is changed. The model may have been // changed by another view or by a state update from the back-end. set_flex_properties(this, this.$el); return IPython.DOMWidgetView.prototype.update.call(this); }, }); widget_manager.register_widget_view('ContainerView', ContainerView); var ModalView = IPython.DOMWidgetView.extend({ render: function(){ var that = this; this.children={}; this.update_children([], this.model.get('children')); this.model.on('change:children', function(model, value, options) { this.update_children(model.previous('children'), value); }, this); this.$el .html('') .on("remove", function(){ that.$window.remove(); }); this.$window = $('
') .addClass('modal widget-modal') .appendTo($('#notebook-container')) .mousedown(function(){ that.bring_to_front(); }); this.$title_bar = $('
') .addClass('popover-title') .appendTo(this.$window) .mousedown(function(){ that.bring_to_front(); }); this.$close = $('