// 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.update_children([], this.model.get('children')); this.model.on('change:children', function(model, value) { this.update_children(model.previous('children'), value); }, this); }, render: function(){ // Called when view is rendered. this.$box = this.$el; this.$el.addClass('widget-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 view = this.create_child_view(model); this.$box.append(view.$el); // Trigger the displayed event of the child view. this.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(); that.update_orientation(); }, update_orientation: function(){ var orientation = this.model.get("orientation"); if (orientation == "vertical") { this.$el.removeClass("hbox").addClass("vbox"); } else { this.$el.removeClass("vbox").addClass("hbox"); } }, _flex_changed: function(){ if (this.model.previous('flex')) { this.$el.removeClass('box-flex' + this.model.previous('flex')); } this.$el.addClass('box-flex' + this.model.get('flex')); }, _pack_changed: function(){ if (this.model.previous('pack')) { this.$el.removeClass(this.model.previous('pack')); } this.$el.addClass(this.model.get('pack')); }, _align_changed: function(){ if (this.model.previous('align')) { this.$el.removeClass('align-' + this.model.previous('align')); } this.$el.addClass('align-' + this.model.get('align')); }, }); var PopupView = widget.DOMWidgetView.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 = $('