Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
// Copyright (c) IPython Development Team.
2
// Distributed under the terms of the Modified BSD License.
3
4
define([
5
"widgets/js/widget",
6
"jquery",
7
], function(widget, $){
8
9
var ImageView = widget.DOMWidgetView.extend({
10
render : function(){
11
/**
12
* Called when view is rendered.
13
*/
14
this.setElement($("<img />"));
15
this.update(); // Set defaults.
16
},
17
18
update : function(){
19
/**
20
* Update the contents of this view
21
*
22
* Called when the model is changed. The model may have been
23
* changed by another view or by a state update from the back-end.
24
*/
25
var image_src = 'data:image/' + this.model.get('format') + ';base64,' + this.model.get('_b64value');
26
this.$el.attr('src', image_src);
27
28
var width = this.model.get('width');
29
if (width !== undefined && width.length > 0) {
30
this.$el.attr('width', width);
31
} else {
32
this.$el.removeAttr('width');
33
}
34
35
var height = this.model.get('height');
36
if (height !== undefined && height.length > 0) {
37
this.$el.attr('height', height);
38
} else {
39
this.$el.removeAttr('height');
40
}
41
return ImageView.__super__.update.apply(this);
42
},
43
});
44
45
return {
46
'ImageView': ImageView,
47
};
48
});
49
50