Skip to content

Commit 2e1c78c

Browse files
committed
Add js default values for widget-image and widget-link
1 parent ec80035 commit 2e1c78c

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

ipywidgets/static/widgets/js/widget_image.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ if (typeof define !== 'function') { var define = require('./requirejs-shim')(mod
77
define([
88
"./widget",
99
"jquery",
10-
], function(widget, $) {
11-
12-
var ImageView = widget.DOMWidgetView.extend({
10+
"underscore",
11+
], function(widget, $, _) {
12+
13+
var ImageModel = widget.DOMWidgetModel.extend({
14+
defaults: _.extend({}, widget.DOMWidgetModel.prototype.defaults, {
15+
_model_name: "ImageModel",
16+
_view_name: "ImageView",
17+
format: "png",
18+
width: "",
19+
height: "",
20+
_b64value: ""
21+
}),
22+
});
23+
24+
var ImageView = widget.DOMWidgetView.extend({
1325
render : function() {
1426
/**
1527
* Called when view is rendered.
@@ -18,24 +30,24 @@ define([
1830
.addClass("ipy-widget widget-image"));
1931
this.update(); // Set defaults.
2032
},
21-
33+
2234
update : function() {
2335
/**
2436
* Update the contents of this view
2537
*
26-
* Called when the model is changed. The model may have been
38+
* Called when the model is changed. The model may have been
2739
* changed by another view or by a state update from the back-end.
2840
*/
2941
var image_src = 'data:image/' + this.model.get('format') + ';base64,' + this.model.get('_b64value');
3042
this.$el.attr('src', image_src);
31-
43+
3244
var width = this.model.get('width');
3345
if (width !== undefined && width.length > 0) {
3446
this.$el.attr('width', width);
3547
} else {
3648
this.$el.removeAttr('width');
3749
}
38-
50+
3951
var height = this.model.get('height');
4052
if (height !== undefined && height.length > 0) {
4153
this.$el.attr('height', height);
@@ -47,6 +59,7 @@ define([
4759
});
4860

4961
return {
50-
'ImageView': ImageView,
62+
ImageView: ImageView,
63+
ImageModel: ImageModel,
5164
};
5265
});

ipywidgets/static/widgets/js/widget_link.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ define([
1212

1313
var BaseLinkModel = widget.WidgetModel.extend({
1414

15+
defaults: _.extend({}, widget.WidgetModel.prototype.defaults, {
16+
target: undefined,
17+
source: undefined,
18+
}),
19+
1520
update_value: function(source, target) {
1621
if (this.updating) {
1722
return;
@@ -50,6 +55,10 @@ define([
5055

5156
var LinkModel = BaseLinkModel.extend({
5257

58+
defaults: _.extend({}, BaseLinkModel.prototype.defaults, {
59+
_model_name, "LinkModel"
60+
}),
61+
5362
initialize: function() {
5463
this.on("change", this.update_bindings, this);
5564
},
@@ -72,11 +81,14 @@ define([
7281
this.listenToOnce(this.target[0], "destroy", this.cleanup, this);
7382
}
7483
},
75-
7684
});
7785

7886
var DirectionalLinkModel = BaseLinkModel.extend({
7987

88+
defaults: _.extend({}, BaseLinkModel.prototype.defaults, {
89+
_model_name, "DirectionalLinkModel"
90+
}),
91+
8092
initialize: function() {
8193
this.on("change", this.update_bindings, this);
8294
},
@@ -100,7 +112,7 @@ define([
100112
});
101113

102114
return {
103-
"LinkModel": LinkModel,
104-
"DirectionalLinkModel": DirectionalLinkModel,
115+
LinkModel: LinkModel,
116+
DirectionalLinkModel: DirectionalLinkModel,
105117
}
106118
});

ipywidgets/widgets/widget_image.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
class Image(DOMWidget):
1818
"""Displays an image as a widget.
1919
20-
The `value` of this widget accepts a byte string. The byte string is the raw
21-
image data that you want the browser to display. You can explicitly define
22-
the format of the byte string using the `format` trait (which defaults to
23-
"png")."""
20+
The `value` of this widget accepts a byte string. The byte string is the
21+
raw image data that you want the browser to display. You can explicitly
22+
define the format of the byte string using the `format` trait (which
23+
defaults to "png").
24+
"""
2425
_view_name = Unicode('ImageView', sync=True)
26+
_model_name = Unicode('ImageModel', sync=True)
2527

2628
# Define the custom state properties to sync with the front-end
2729
format = Unicode('png', sync=True)

0 commit comments

Comments
 (0)