Show More
@@ -1,59 +1,65 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2013 The IPython Development Team |
|
2 | // Copyright (C) 2013 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // ButtonWidget |
|
9 | // ButtonWidget | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | /** |
|
12 | /** | |
13 | * @module IPython |
|
13 | * @module IPython | |
14 | * @namespace IPython |
|
14 | * @namespace IPython | |
15 | **/ |
|
15 | **/ | |
16 |
|
16 | |||
17 | define(["notebook/js/widget"], function(widget_manager){ |
|
17 | define(["notebook/js/widget"], function(widget_manager){ | |
18 |
|
18 | |||
19 | var ButtonWidgetModel = IPython.WidgetModel.extend({}); |
|
19 | var ButtonWidgetModel = IPython.WidgetModel.extend({}); | |
20 | widget_manager.register_widget_model('ButtonWidgetModel', ButtonWidgetModel); |
|
20 | widget_manager.register_widget_model('ButtonWidgetModel', ButtonWidgetModel); | |
21 |
|
21 | |||
22 | var ButtonView = IPython.WidgetView.extend({ |
|
22 | var ButtonView = IPython.WidgetView.extend({ | |
23 |
|
23 | |||
24 | // Called when view is rendered. |
|
24 | // Called when view is rendered. | |
25 | render : function(){ |
|
25 | render : function(){ | |
26 | var that = this; |
|
26 | var that = this; | |
27 | this.setElement($("<button />") |
|
27 | this.setElement($("<button />") | |
28 | .addClass('btn')); |
|
28 | .addClass('btn')); | |
29 |
|
29 | |||
30 | this.update(); // Set defaults. |
|
30 | this.update(); // Set defaults. | |
31 | }, |
|
31 | }, | |
32 |
|
32 | |||
33 | // Handles: Backend -> Frontend Sync |
|
33 | // Handles: Backend -> Frontend Sync | |
34 | // Frontent -> Frontend Sync |
|
34 | // Frontent -> Frontend Sync | |
35 | update : function(){ |
|
35 | update : function(){ | |
36 | var description = this.model.get('description'); |
|
36 | var description = this.model.get('description'); | |
37 | description = description.replace(/ /g, ' ', 'm'); |
|
37 | description = description.replace(/ /g, ' ', 'm'); | |
38 | description = description.replace(/\n/g, '<br>\n', 'm'); |
|
38 | description = description.replace(/\n/g, '<br>\n', 'm'); | |
39 | if (description.length == 0) { |
|
39 | if (description.length == 0) { | |
40 | this.$el.html(' '); // Preserve button height |
|
40 | this.$el.html(' '); // Preserve button height | |
41 | } else { |
|
41 | } else { | |
42 | this.$el.html(description); |
|
42 | this.$el.html(description); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
|
45 | if (this.model.get('disabled')) { | |||
|
46 | this.$el.attr('disabled','disabled'); | |||
|
47 | } else { | |||
|
48 | this.$el.removeAttr('disabled'); | |||
|
49 | } | |||
|
50 | ||||
45 | return IPython.WidgetView.prototype.update.call(this); |
|
51 | return IPython.WidgetView.prototype.update.call(this); | |
46 | }, |
|
52 | }, | |
47 |
|
53 | |||
48 | events: { |
|
54 | events: { | |
49 | 'click': '_handle_click', |
|
55 | 'click': '_handle_click', | |
50 | }, |
|
56 | }, | |
51 |
|
57 | |||
52 | _handle_click: function(){ |
|
58 | _handle_click: function(){ | |
53 | this.send({event: 'click'}); |
|
59 | this.send({event: 'click'}); | |
54 | }, |
|
60 | }, | |
55 | }); |
|
61 | }); | |
56 |
|
62 | |||
57 | widget_manager.register_widget_view('ButtonView', ButtonView); |
|
63 | widget_manager.register_widget_view('ButtonView', ButtonView); | |
58 |
|
64 | |||
59 | }); |
|
65 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now