##// END OF EJS Templates
Merge pull request #7159 from takluyver/hooks-invoke...
Merge pull request #7159 from takluyver/hooks-invoke Git hooks need to use invoke, not fab

File last commit:

r19196:51b39c31
r19411:e32d41f6 merge
Show More
widget_box.js
369 lines | 13.6 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Almost done!...
r17198 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 define([
"widgets/js/widget",
Jonathan Frederic
Fix all the tests
r17216 "jqueryui",
Jonathan Frederic
Add a WrappedError class
r18895 "base/js/utils",
MinRK
add bootstrap shim for require...
r17312 "bootstrap",
Jonathan Frederic
Add a WrappedError class
r18895 ], function(widget, $, utils){
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
s/Container/Box
r17637 var BoxView = widget.DOMWidgetView.extend({
sylvain.corlay
widget simplification continued
r17349 initialize: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Public constructor
*/
Jonathan Frederic
s/Container/Box
r17637 BoxView.__super__.initialize.apply(this, arguments);
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.children_views = new widget.ViewList(this.add_child_model, null, this);
this.listenTo(this.model, 'change:children', function(model, value) {
this.children_views.update(value);
Jason Grout
Live updates for children automatically change container views....
r14503 }, this);
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.listenTo(this.model, 'change:overflow_x', function(model, value) {
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 this.update_overflow_x();
}, this);
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.listenTo(this.model, 'change:overflow_y', function(model, value) {
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 this.update_overflow_y();
}, this);
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.listenTo(this.model, 'change:box_style', function(model, value) {
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 this.update_box_style();
}, this);
Jason Grout
Live updates for children automatically change container views....
r14503 },
sylvain.corlay
widget simplification continued
r17349
Jonathan Frederic
Initial crack at using specific traits for styling.
r17722 update_attr: function(name, value) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Set a css attr of the widget view.
*/
Jonathan Frederic
Initial crack at using specific traits for styling.
r17722 this.$box.css(name, value);
},
sylvain.corlay
widget simplification continued
r17349 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Fixed typo
r17663 this.$box = this.$el;
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.addClass('widget-box');
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.children_views.update(this.model.get('children'));
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 this.update_overflow_x();
this.update_overflow_y();
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 this.update_box_style('');
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 },
update_overflow_x: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when the x-axis overflow setting is changed.
*/
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 this.$box.css('overflow-x', this.model.get('overflow_x'));
},
update_overflow_y: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when the y-axis overflow setting is changed.
*/
Jonathan Frederic
Fix some bugs found by the widget examples,...
r17727 this.$box.css('overflow-y', this.model.get('overflow_y'));
Jason Grout
Live updates for children automatically change container views....
r14503 },
Jonathan Frederic
Added Bootstrap specific classes,...
r17728
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);
},
Jason Grout
Live updates for children automatically change container views....
r14503
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 add_child_model: function(model) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when a model is added to the children list.
*/
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142 var that = this;
Jonathan Frederic
Fix view rendering order.
r18883 var dummy = $('<div/>');
that.$box.append(dummy);
Jonathan Frederic
Finished adding error handling.
r18896 return this.create_child_view(model).then(function(view) {
Jason Grout
More simplifications due to promises
r18888 dummy.replaceWith(view.el);
Jonathan Frederic
Fixed bugs in displayed event triggering for containers
r16660
Thomas Kluyver
Allow widget views to be loaded from require modules...
r18142 // Trigger the displayed event of the child view.
that.after_displayed(function() {
view.trigger('displayed');
});
Jonathan Frederic
Finished adding error handling.
r18896 return view;
Jason Grout
Catch errors after our then()s, instead of in parallel with them (this missing exceptions)...
r19080 }).catch(utils.reject("Couldn't add child view to box", true));
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996
remove: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* We remove this widget before removing the children as an optimization
* we want to remove the entire container from the DOM first before
* removing each individual child separately.
*/
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 BoxView.__super__.remove.apply(this, arguments);
this.children_views.remove();
},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Embrace flexible box model
r17596
Jonathan Frederic
s/Container/Box
r17637 var FlexBoxView = BoxView.extend({
Jonathan Frederic
Embrace flexible box model
r17596 render: function(){
Jonathan Frederic
s/Container/Box
r17637 FlexBoxView.__super__.render.apply(this);
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.listenTo(this.model, 'change:orientation', this.update_orientation, this);
this.listenTo(this.model, 'change:flex', this._flex_changed, this);
this.listenTo(this.model, 'change:pack', this._pack_changed, this);
this.listenTo(this.model, 'change:align', this._align_changed, this);
Jonathan Frederic
Embrace flexible box model
r17596 this._flex_changed();
this._pack_changed();
this._align_changed();
Jonathan Frederic
s/that/this bug
r17688 this.update_orientation();
Sylvain Corlay
adding hbox and vbox...
r17600 },
update_orientation: function(){
var orientation = this.model.get("orientation");
if (orientation == "vertical") {
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.removeClass("hbox").addClass("vbox");
Sylvain Corlay
adding hbox and vbox...
r17600 } else {
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.removeClass("vbox").addClass("hbox");
Sylvain Corlay
adding hbox and vbox...
r17600 }
Jonathan Frederic
Embrace flexible box model
r17596 },
_flex_changed: function(){
if (this.model.previous('flex')) {
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.removeClass('box-flex' + this.model.previous('flex'));
Jonathan Frederic
Embrace flexible box model
r17596 }
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.addClass('box-flex' + this.model.get('flex'));
Jonathan Frederic
Embrace flexible box model
r17596 },
_pack_changed: function(){
if (this.model.previous('pack')) {
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.removeClass(this.model.previous('pack'));
Jonathan Frederic
Embrace flexible box model
r17596 }
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.addClass(this.model.get('pack'));
Jonathan Frederic
Embrace flexible box model
r17596 },
_align_changed: function(){
if (this.model.previous('align')) {
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.removeClass('align-' + this.model.previous('align'));
Jonathan Frederic
Embrace flexible box model
r17596 }
Jonathan Frederic
Fix logic, use box where applicable
r17661 this.$box.addClass('align-' + this.model.get('align'));
Jonathan Frederic
Embrace flexible box model
r17596 },
});
Jonathan Frederic
Make popup inherit from widget box
r17660 var PopupView = BoxView.extend({
Jonathan Frederic
Fix logic, use box where applicable
r17661
Jonathan Frederic
Added ModalView
r14409 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Added ModalView
r14409 var that = this;
Jonathan Frederic
Added `update_children` pattern to remaining parent widgets
r14507
MinRK
quick review pass on javascript
r14792 this.$el.on("remove", function(){
Jonathan Frederic
Modal fixes for BS3
r16955 that.$backdrop.remove();
Jonathan Frederic
Added ModalView
r14409 });
Jonathan Frederic
Modal fixes for BS3
r16955 this.$backdrop = $('<div />')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .appendTo($('#notebook-container'))
Jonathan Frederic
Modal fixes for BS3
r16955 .addClass('modal-dialog')
.css('position', 'absolute')
.css('left', '0px')
.css('top', '0px');
this.$window = $('<div />')
.appendTo(this.$backdrop)
.addClass('modal-content widget-modal')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .mousedown(function(){
that.bring_to_front();
});
Jonathan Frederic
Fix command mode & popup view bug...
r15022
// 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.
Jonathan Frederic
Fixed bugs in displayed event triggering for containers
r16660 this.additional_elements = [this.$window];
Jonathan Frederic
Fix command mode & popup view bug...
r15022
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 />')
Thomas Spura
Port more icons to fontawesome-4
r17413 .addClass('close fa fa-remove')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .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 />')
Thomas Spura
Port more icons to fontawesome-4
r17413 .addClass('close fa fa-arrow-down')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .appendTo(this.$title_bar)
.click(function(){
that.popped_out = !that.popped_out;
if (!that.popped_out) {
that.$minimize
Jonathan Frederic
Address problems found in in-person review
r17947 .removeClass('fa-arrow-down')
.addClass('fa-arrow-up');
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443
that.$window
.draggable('destroy')
.resizable('destroy')
Jonathan Frederic
Modal fixes for BS3
r16955 .removeClass('widget-modal modal-content')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .addClass('docked-widget-modal')
.detach()
.insertBefore(that.$show_button);
that.$show_button.hide();
that.$close.hide();
} else {
that.$minimize
Jonathan Frederic
Address problems found in in-person review
r17947 .addClass('fa-arrow-down')
.removeClass('fa-arrow-up');
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443
that.$window
.removeClass('docked-widget-modal')
Jonathan Frederic
Modal fixes for BS3
r16955 .addClass('widget-modal modal-content')
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .detach()
Jonathan Frederic
Modal fixes for BS3
r16955 .appendTo(that.$backdrop)
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 .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')
MinRK
use non-breaking space for button with no description...
r15329 .html("&nbsp;")
Jonathan Frederic
Fix logic, use box where applicable
r17661 .appendTo(this.$title_bar);
this.$box = $('<div />')
Jonathan Frederic
Added ModalView
r14409 .addClass('modal-body')
Jonathan Frederic
Removed max height from widget modal body
r14411 .addClass('widget-modal-body')
Jonathan Frederic
Address Sylvain's comments.
r17658 .addClass('widget-box')
Jonathan Frederic
Container classes should default with 'vbox' css
r15015 .addClass('vbox')
Jonathan Frederic
Added ModalView
r14409 .appendTo(this.$window);
this.$show_button = $('<button />')
MinRK
use non-breaking space for button with no description...
r15329 .html("&nbsp;")
Jonathan Frederic
Fix automation errors.
r16914 .addClass('btn btn-info widget-modal-show')
Jonathan Frederic
Added ModalView
r14409 .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(){
Jonathan Frederic
Fix logic, use box where applicable
r17661 that.$box.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 ModalView
r14409 this._shown_once = false;
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 this.popped_out = true;
Jonathan Frederic
Fixed bug that prevented popup widget from displaying
r14754
Jason Grout
Refactor the do_diff and manual child view lists into a separate ViewList object
r18996 this.children_views.update(this.model.get('children'))
Jonathan Frederic
Added ModalView
r14409 },
hide: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when the modal hide button is clicked.
*/
Jonathan Frederic
Added ModalView
r14409 this.$window.hide();
this.$show_button.removeClass('btn-info');
},
show: function() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when the modal show button is clicked.
*/
Jonathan Frederic
Added ModalView
r14409 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() {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Make the modal top-most, z-ordered about the other modals.
*/
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 var $widget_modals = $(".widget-modal");
var max_zindex = 0;
$widget_modals.each(function (index, el){
Jonathan Frederic
Modal fixes for BS3
r16955 var zindex = parseInt($(el).css('z-index'));
if (!isNaN(zindex)) {
max_zindex = Math.max(max_zindex, zindex);
}
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 });
// Start z-index of widget modals at 2000
max_zindex = Math.max(max_zindex, 2000);
Jonathan Frederic
Modal fixes for BS3
r16955
Jonathan Frederic
- ModalView can now be docked and undocked...
r14443 $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 },
update: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* 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
Added ModalView
r14409 var description = this.model.get('description');
MinRK
handle space-only strings, not just zero-length
r15330 if (description.trim().length === 0) {
MinRK
use non-breaking space for button with no description...
r15329 this.$title.html("&nbsp;"); // Preserve title height
Jonathan Frederic
Added ModalView
r14409 } else {
Nicholas Bollweg (Nick)
reversing order of arguments, as text may already exist
r19196 this.typeset(this.$title, description);
Jonathan Frederic
Added ModalView
r14409 }
var button_text = this.model.get('button_text');
MinRK
handle space-only strings, not just zero-length
r15330 if (button_text.trim().length === 0) {
MinRK
use non-breaking space for button with no description...
r15329 this.$show_button.html("&nbsp;"); // Preserve button height
Jonathan Frederic
Added ModalView
r14409 } else {
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$show_button.text(button_text);
Jonathan Frederic
Added ModalView
r14409 }
if (!this._shown_once) {
this._shown_once = true;
this.show();
}
Jonathan Frederic
s/ModalView/PopupView
r14676 return PopupView.__super__.update.apply(this);
Jonathan Frederic
Added ModalView
r14409 },
Jonathan Frederic
Added custom selector logic to modal view
r14419 _get_selector_element: function(selector) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Get an element view a 'special' jquery selector. (see widget.js)
*
* 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
*/
Jonathan Frederic
Added custom selector logic to modal view
r14419 if (selector.substring(0, 5) == 'modal') {
if (selector == 'modal') {
return this.$window;
} else {
return this.$window.find(selector.substring(6));
}
} else {
Jonathan Frederic
s/ModalView/PopupView
r14676 return PopupView.__super__._get_selector_element.apply(this, [selector]);
Jonathan Frederic
Added custom selector logic to modal view
r14419 }
},
Jonathan Frederic
Added ModalView
r14409 });
Jonathan Frederic
Almost done!...
r17198
return {
Jonathan Frederic
s/Container/Box
r17637 'BoxView': BoxView,
Jonathan Frederic
Almost done!...
r17198 'PopupView': PopupView,
Jonathan Frederic
s/Container/Box
r17637 'FlexBoxView': FlexBoxView,
Jonathan Frederic
Almost done!...
r17198 };
Jonathan Frederic
Added ModalView
r14409 });