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
// ButtonWidget
10
//============================================================================
11
12
/**
13
* @module IPython
14
* @namespace IPython
15
**/
16
17
define(["widgets/js/widget"], function(WidgetManager){
18
19
var ButtonView = IPython.DOMWidgetView.extend({
20
render : function(){
21
// Called when view is rendered.
22
this.setElement($("<button />")
23
.addClass('btn'));
24
25
this.update(); // Set defaults.
26
},
27
28
update : function(){
29
// Update the contents of this view
30
//
31
// Called when the model is changed. The model may have been
32
// changed by another view or by a state update from the back-end.
33
var description = this.model.get('description');
34
if (description.length === 0) {
35
this.$el.html("&nbsp;"); // Preserve button height
36
} else {
37
this.$el.text(description);
38
}
39
40
if (this.model.get('disabled')) {
41
this.$el.attr('disabled','disabled');
42
} else {
43
this.$el.removeAttr('disabled');
44
}
45
46
return ButtonView.__super__.update.apply(this);
47
},
48
49
events: {
50
// Dictionary of events and their handlers.
51
'click': '_handle_click',
52
},
53
54
_handle_click: function(){
55
// Handles when the button is clicked.
56
this.send({event: 'click'});
57
},
58
});
59
WidgetManager.register_widget_view('ButtonView', ButtonView);
60
});
61
62