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
'notebook/js/outputarea',
8
], function(widget, $, outputarea) {
9
'use strict';
10
11
var OutputView = widget.DOMWidgetView.extend({
12
/**
13
* Public constructor
14
*/
15
initialize: function (parameters) {
16
OutputView.__super__.initialize.apply(this, [parameters]);
17
this.model.on('msg:custom', this._handle_route_msg, this);
18
},
19
20
/**
21
* Called when view is rendered.
22
*/
23
render: function(){
24
this.output_area = new outputarea.OutputArea({
25
selector: this.$el,
26
prompt_area: false,
27
events: this.model.widget_manager.notebook.events,
28
keyboard_manager: this.model.widget_manager.keyboard_manager });
29
30
// Make output area reactive.
31
var that = this;
32
this.output_area.element.on('changed', function() {
33
that.model.set('contents', that.output_area.element.html());
34
});
35
this.model.on('change:contents', function(){
36
var html = this.model.get('contents');
37
if (this.output_area.element.html() != html) {
38
this.output_area.element.html(html);
39
}
40
}, this);
41
42
// Set initial contents.
43
this.output_area.element.html(this.model.get('contents'));
44
},
45
46
/**
47
* Handles re-routed iopub messages.
48
*/
49
_handle_route_msg: function(msg) {
50
if (msg) {
51
var msg_type = msg.msg_type;
52
if (msg_type=='clear_output') {
53
this.output_area.handle_clear_output(msg);
54
} else {
55
this.output_area.handle_output(msg);
56
}
57
}
58
},
59
});
60
61
return {
62
'OutputView': OutputView,
63
};
64
});
65
66