// Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. define([ "widgets/js/widget", "jqueryui", "bootstrap", ], function(widget, $){ var BoxView = widget.DOMWidgetView.extend({ initialize: function(){ // Public constructor BoxView.__super__.initialize.apply(this, arguments); this.model.on('change:children', function(model, value) { this.update_children(model.previous('children'), value); }, this); this.model.on('change:overflow_x', function(model, value) { this.update_overflow_x(); }, this); this.model.on('change:overflow_y', function(model, value) { this.update_overflow_y(); }, this); this.model.on('change:box_style', function(model, value) { this.update_box_style(); }, this); }, update_attr: function(name, value) { // Set a css attr of the widget view. this.$box.css(name, value); }, render: function(){ // Called when view is rendered. this.$box = this.$el; this.$box.addClass('widget-box'); this.update_children([], this.model.get('children')); this.update_overflow_x(); this.update_overflow_y(); this.update_box_style(''); }, update_overflow_x: function() { // Called when the x-axis overflow setting is changed. this.$box.css('overflow-x', this.model.get('overflow_x')); }, update_overflow_y: function() { // Called when the y-axis overflow setting is changed. this.$box.css('overflow-y', this.model.get('overflow_y')); }, update_box_style: function(previous_trait_value) { var class_map = { success: ['alert', 'alert-success'], info: ['alert', 'alert-info'], warning: ['alert', 'alert-warning'], danger: ['alert', 'alert-danger'] }; this.update_mapped_classes(class_map, 'box_style', previous_trait_value, this.$box); }, update_children: function(old_list, new_list) { // Called when the children list changes. this.do_diff(old_list, new_list, $.proxy(this.remove_child_model, this), $.proxy(this.add_child_model, this)); }, remove_child_model: function(model) { // Called when a model is removed from the children list. this.pop_child_view(model).remove(); }, add_child_model: function(model) { // Called when a model is added to the children list. var that = this; this.create_child_view(model, {callback: function(view) { that.$box.append(view.$el); // Trigger the displayed event of the child view. that.after_displayed(function() { view.trigger('displayed'); }); }}); }, }); var FlexBoxView = BoxView.extend({ render: function(){ FlexBoxView.__super__.render.apply(this); this.model.on('change:orientation', this.update_orientation, this); this.model.on('change:flex', this._flex_changed, this); this.model.on('change:pack', this._pack_changed, this); this.model.on('change:align', this._align_changed, this); this._flex_changed(); this._pack_changed(); this._align_changed(); this.update_orientation(); }, update_orientation: function(){ var orientation = this.model.get("orientation"); if (orientation == "vertical") { this.$box.removeClass("hbox").addClass("vbox"); } else { this.$box.removeClass("vbox").addClass("hbox"); } }, _flex_changed: function(){ if (this.model.previous('flex')) { this.$box.removeClass('box-flex' + this.model.previous('flex')); } this.$box.addClass('box-flex' + this.model.get('flex')); }, _pack_changed: function(){ if (this.model.previous('pack')) { this.$box.removeClass(this.model.previous('pack')); } this.$box.addClass(this.model.get('pack')); }, _align_changed: function(){ if (this.model.previous('align')) { this.$box.removeClass('align-' + this.model.previous('align')); } this.$box.addClass('align-' + this.model.get('align')); }, }); var PopupView = BoxView.extend({ render: function(){ // Called when view is rendered. var that = this; this.$el.on("remove", function(){ that.$backdrop.remove(); }); this.$backdrop = $('
') .appendTo($('#notebook-container')) .addClass('modal-dialog') .css('position', 'absolute') .css('left', '0px') .css('top', '0px'); this.$window = $('
') .appendTo(this.$backdrop) .addClass('modal-content widget-modal') .mousedown(function(){ that.bring_to_front(); }); // Set the elements array since the this.$window element is not child // of this.$el and the parent widget manager or other widgets may // need to know about all of the top-level widgets. The IPython // widget manager uses this to register the elements with the // keyboard manager. this.additional_elements = [this.$window]; this.$title_bar = $('
') .addClass('popover-title') .appendTo(this.$window) .mousedown(function(){ that.bring_to_front(); }); this.$close = $('