mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
Make updates more granular for widgets
This commit is contained in:
parent
641a5af70f
commit
7431fa37dd
@ -243,10 +243,12 @@ function(widget_manager, underscore, backbone){
|
||||
|
||||
var WidgetView = BaseWidgetView.extend({
|
||||
initialize: function (options) {
|
||||
this.visible = true;
|
||||
this.model.on('change:visible', function() {this.$el.toggle(this.model.get('visible'))}, this);
|
||||
this.model.on('change', this.update_css, this);
|
||||
BaseWidgetView.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
|
||||
add_class: function (selector, class_list) {
|
||||
var elements = this._get_selector_element(selector);
|
||||
if (elements.length > 0) {
|
||||
@ -261,22 +263,15 @@ function(widget_manager, underscore, backbone){
|
||||
}
|
||||
},
|
||||
|
||||
update: function () {
|
||||
// jng: hook into change:visible trigger
|
||||
var visible = this.model.get('visible');
|
||||
if (visible !== undefined && this.visible !== visible) {
|
||||
this.visible = visible;
|
||||
this.$el.toggle(visible)
|
||||
}
|
||||
|
||||
if (this.model.css !== undefined) {
|
||||
for (var selector in this.model.css) {
|
||||
if (this.model.css.hasOwnProperty(selector)) {
|
||||
|
||||
update_css: function () {
|
||||
var css = this.model.css;
|
||||
if (css === undefined) {return;}
|
||||
for (var selector in css) {
|
||||
if (css.hasOwnProperty(selector)) {
|
||||
// Apply the css traits to all elements that match the selector.
|
||||
var elements = this._get_selector_element(selector);
|
||||
if (elements.length > 0) {
|
||||
var css_traits = this.model.css[selector];
|
||||
var css_traits = css[selector];
|
||||
for (var css_key in css_traits) {
|
||||
if (css_traits.hasOwnProperty(css_key)) {
|
||||
elements.css(css_key, css_traits[css_key]);
|
||||
@ -285,7 +280,6 @@ function(widget_manager, underscore, backbone){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_get_selector_element: function (selector) {
|
||||
@ -293,13 +287,15 @@ function(widget_manager, underscore, backbone){
|
||||
// blank, apply the style to the $el_to_style element. If
|
||||
// the $el_to_style element is not defined, use apply the
|
||||
// style to the view's element.
|
||||
var elements = this.$el.find(selector);
|
||||
var elements;
|
||||
if (selector === undefined || selector === null || selector === '') {
|
||||
if (this.$el_to_style === undefined) {
|
||||
elements = this.$el;
|
||||
} else {
|
||||
elements = this.$el_to_style;
|
||||
}
|
||||
} else {
|
||||
elements = this.$el.find(selector);
|
||||
}
|
||||
return elements;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user