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