Show More
@@ -45,4 +45,48 b' require(["notebook/js/widget"], function(){' | |||||
45 | }); |
|
45 | }); | |
46 |
|
46 | |||
47 | IPython.notebook.widget_manager.register_widget_view('CheckboxView', CheckboxView); |
|
47 | IPython.notebook.widget_manager.register_widget_view('CheckboxView', CheckboxView); | |
|
48 | ||||
|
49 | var ToggleButtonView = IPython.WidgetView.extend({ | |||
|
50 | ||||
|
51 | // Called when view is rendered. | |||
|
52 | render : function(){ | |||
|
53 | this.$el | |||
|
54 | .html('') | |||
|
55 | .addClass(this.model.comm.comm_id); | |||
|
56 | ||||
|
57 | this.$button = $('<button />') | |||
|
58 | .addClass('btn') | |||
|
59 | .attr('type', 'button') | |||
|
60 | .attr('data-toggle', 'button') | |||
|
61 | .appendTo(this.$el); | |||
|
62 | ||||
|
63 | this.update(); // Set defaults. | |||
|
64 | }, | |||
|
65 | ||||
|
66 | // Handles: Backend -> Frontend Sync | |||
|
67 | // Frontent -> Frontend Sync | |||
|
68 | update : function(){ | |||
|
69 | if (!this.user_invoked_update) { | |||
|
70 | if (this.model.get('value')) { | |||
|
71 | this.$button.addClass('active'); | |||
|
72 | } else { | |||
|
73 | this.$button.removeClass('active'); | |||
|
74 | } | |||
|
75 | this.$button.html(this.model.get('description')); | |||
|
76 | } | |||
|
77 | }, | |||
|
78 | ||||
|
79 | events: {"click button" : "handleClick"}, | |||
|
80 | ||||
|
81 | // Handles and validates user input. | |||
|
82 | handleClick: function(e) { | |||
|
83 | this.user_invoked_update = true; | |||
|
84 | this.model.set('value', ! $(e.target).hasClass('active')); | |||
|
85 | this.model.apply(this); | |||
|
86 | this.user_invoked_update = false; | |||
|
87 | }, | |||
|
88 | }); | |||
|
89 | ||||
|
90 | IPython.notebook.widget_manager.register_widget_view('ToggleButtonView', ToggleButtonView); | |||
|
91 | ||||
48 | }); |
|
92 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now