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