##// END OF EJS Templates
comment model.set, so we know that it triggers update on other views
comment model.set, so we know that it triggers update on other views

File last commit:

r14568:515cf551
r14569:500d8a37
Show More
widget_container.js
287 lines | 11.3 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366 //----------------------------------------------------------------------------
// 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
**/
Jonathan Frederic
Updated require.js references
r14537 define(["notebook/js/widgets/widget"], function(widget_manager) {
Jonathan Frederic
Moved flexible box model attrs out of Container and Modal js...
r14418
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'));
};
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var ContainerModel = IPython.WidgetModel.extend({});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var ContainerView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
Added flexible box model align properties.
r14333 render: function(){
Jonathan Frederic
Fixed typo in container construction.
r14396 this.$el
Jonathan Frederic
Changed underscores in CSS names to dashes
r14293 .addClass('widget-container');
Jason Grout
Live updates for children automatically change container views....
r14503 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)
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Added flexible box model align properties.
r14333 update: function(){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // 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.
Jonathan Frederic
Moved flexible box model attrs out of Container and Modal js...
r14418 set_flex_properties(this, this.$el);
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype.update.call(this);
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('ContainerView', ContainerView);
Jonathan Frederic
Added ModalView
r14409
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var ModalView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Added ModalView
r14409
render: function(){
var that = this;
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 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);
Jonathan Frederic
Added ModalView
r14409 this.$el
.html('')
.on("remove", function(){
that.$window.remove();
});
this.$window = $('<div />')
.addClass('modal widget-modal')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .appendTo($('#notebook-container'))
.mousedown(function(){
that.bring_to_front();
});
Jonathan Frederic
Fixed body container height not stretching to fill remainer of height
r14410 this.$title_bar = $('<div />')
Jonathan Frederic
Added ModalView
r14409 .addClass('popover-title')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .appendTo(this.$window)
.mousedown(function(){
that.bring_to_front();
Jonathan Frederic
jslint /widgets
r14466 });
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 this.$close = $('<button />')
.addClass('close icon-remove')
.css('margin-left', '5px')
Jonathan Frederic
Fixed body container height not stretching to fill remainer of height
r14410 .appendTo(this.$title_bar)
Jonathan Frederic
Added ModalView
r14409 .click(function(){
that.hide();
event.stopPropagation();
});
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 this.$minimize = $('<button />')
.addClass('close icon-arrow-down')
.appendTo(this.$title_bar)
.click(function(){
that.popped_out = !that.popped_out;
if (!that.popped_out) {
that.$minimize
.removeClass('icon-arrow-down')
.addClass('icon-arrow-up');
that.$window
.draggable('destroy')
.resizable('destroy')
.removeClass('widget-modal modal')
.addClass('docked-widget-modal')
.detach()
.insertBefore(that.$show_button);
that.$show_button.hide();
that.$close.hide();
} else {
that.$minimize
.addClass('icon-arrow-down')
.removeClass('icon-arrow-up');
that.$window
.removeClass('docked-widget-modal')
.addClass('widget-modal modal')
.detach()
.appendTo($('#notebook-container'))
.draggable({handle: '.popover-title', snap: '#notebook, .modal', snapMode: 'both'})
.resizable()
.children('.ui-resizable-handle').show();
that.show();
that.$show_button.show();
that.$close.show();
}
event.stopPropagation();
});
Jonathan Frederic
Added ModalView
r14409 this.$title = $('<div />')
.addClass('widget-modal-title')
.html('&nbsp;')
Jonathan Frederic
Fixed body container height not stretching to fill remainer of height
r14410 .appendTo(this.$title_bar);
Jonathan Frederic
Added ModalView
r14409 this.$body = $('<div />')
.addClass('modal-body')
Jonathan Frederic
Removed max height from widget modal body
r14411 .addClass('widget-modal-body')
Jonathan Frederic
Added ModalView
r14409 .addClass('widget-container')
.appendTo(this.$window);
this.$show_button = $('<button />')
.html('&nbsp;')
.addClass('btn btn-info widget-modal-show')
.appendTo(this.$el)
.click(function(){
that.show();
});
this.$window.draggable({handle: '.popover-title', snap: '#notebook, .modal', snapMode: 'both'});
this.$window.resizable();
Jonathan Frederic
Fixed body container height not stretching to fill remainer of height
r14410 this.$window.on('resize', function(){
that.$body.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight());
Jonathan Frederic
jslint /widgets
r14466 });
Jonathan Frederic
Fixed body container height not stretching to fill remainer of height
r14410
Jonathan Frederic
Added custom selector logic to modal view
r14419 this.$el_to_style = this.$body;
Jonathan Frederic
Added ModalView
r14409 this._shown_once = false;
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 this.popped_out = true;
Jonathan Frederic
Added ModalView
r14409 },
hide: function() {
this.$window.hide();
this.$show_button.removeClass('btn-info');
},
show: function() {
this.$show_button.addClass('btn-info');
Jonathan Frederic
Fixed modal centering code
r14425
this.$window.show();
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 if (this.popped_out) {
Jonathan Frederic
jslint /widgets
r14466 this.$window.css("positon", "absolute");
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 this.$window.css("top", "0px");
this.$window.css("left", Math.max(0, (($('body').outerWidth() - this.$window.outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
this.bring_to_front();
}
},
bring_to_front: function() {
var $widget_modals = $(".widget-modal");
var max_zindex = 0;
$widget_modals.each(function (index, el){
max_zindex = Math.max(max_zindex, parseInt($(el).css('z-index')));
});
// Start z-index of widget modals at 2000
max_zindex = Math.max(max_zindex, 2000);
$widget_modals.each(function (index, el){
Jonathan Frederic
jslint /widgets
r14466 $el = $(el);
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 if (max_zindex == parseInt($el.css('z-index'))) {
$el.css('z-index', max_zindex - 1);
}
});
this.$window.css('z-index', max_zindex);
Jonathan Frederic
Added ModalView
r14409 },
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507 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.$body.append(this.child_views[element].$el);
}, this)
},
Jonathan Frederic
Added ModalView
r14409 update: function(){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // 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.
Jonathan Frederic
Moved flexible box model attrs out of Container and Modal js...
r14418 set_flex_properties(this, this.$body);
Jonathan Frederic
Added ModalView
r14409
var description = this.model.get('description');
description = description.replace(/ /g, '&nbsp;', 'm');
description = description.replace(/\n/g, '<br>\n', 'm');
Jonathan Frederic
jslint /widgets
r14466 if (description.length === 0) {
Jonathan Frederic
Added ModalView
r14409 this.$title.html('&nbsp;'); // Preserve title height
} else {
this.$title.html(description);
}
var button_text = this.model.get('button_text');
button_text = button_text.replace(/ /g, '&nbsp;', 'm');
button_text = button_text.replace(/\n/g, '<br>\n', 'm');
Jonathan Frederic
jslint /widgets
r14466 if (button_text.length === 0) {
Jonathan Frederic
Added ModalView
r14409 this.$show_button.html('&nbsp;'); // Preserve button height
} else {
this.$show_button.html(button_text);
}
if (!this._shown_once) {
this._shown_once = true;
this.show();
}
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype.update.call(this);
Jonathan Frederic
Added ModalView
r14409 },
Jonathan Frederic
Added custom selector logic to modal view
r14419 _get_selector_element: function(selector) {
// Since the modal actually isn't within the $el in the DOM, we need to extend
// the selector logic to allow the user to set css on the modal if need be.
// The convention used is:
// "modal" - select the modal div
// "modal [selector]" - select element(s) within the modal div.
// "[selector]" - select elements within $el
// "" - select the $el_to_style
if (selector.substring(0, 5) == 'modal') {
if (selector == 'modal') {
return this.$window;
} else {
return this.$window.find(selector.substring(6));
}
} else {
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype._get_selector_element.call(this, selector);
Jonathan Frederic
Added custom selector logic to modal view
r14419 }
},
Jonathan Frederic
Added ModalView
r14409
});
widget_manager.register_widget_view('ModalView', ModalView);
});