##// END OF EJS Templates
Added togglebutton group
Jonathan Frederic -
Show More
@@ -63,6 +63,7 var DropdownView = IPython.WidgetView.extend({
63 63 });
64 64
65 65 IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView);
66
66 67 var RadioButtonView = IPython.WidgetView.extend({
67 68
68 69 // Called when view is rendered.
@@ -126,3 +127,68 var RadioButtonView = IPython.WidgetView.extend({
126 127 });
127 128
128 129 IPython.notebook.widget_manager.register_widget_view('RadioButtonView', RadioButtonView);
130
131
132 var ToggleButtonView = IPython.WidgetView.extend({
133
134 // Called when view is rendered.
135 render : function(){
136 this.$el
137 .html('')
138 .addClass(this.model.comm.comm_id);
139 this.$buttongroup = $('<div />')
140 .addClass('btn-group')
141 .attr('data-toggle', 'buttons-radio')
142 .appendTo(this.$el);
143 this.update();
144 },
145
146 // Handles: Backend -> Frontend Sync
147 // Frontent -> Frontend Sync
148 update : function(){
149
150 // Add missing items to the DOM.
151 var items = this.model.get('values');
152 for (var index in items) {
153 var item_query = ' :contains("' + items[index] + '")';
154 if (this.$buttongroup.find(item_query).length == 0) {
155
156 var that = this;
157 $('<button />')
158 .attr('type', 'button')
159 .addClass('btn')
160 .html(items[index])
161 .appendTo(this.$buttongroup)
162 .on('click', function(e){
163 that.model.set('value', $(e.target).html(), this);
164 that.model.apply();
165 });
166 }
167
168 if (this.model.get('value') == items[index]) {
169 this.$buttongroup.find(item_query).addClass('active');
170 } else {
171 this.$buttongroup.find(item_query).removeClass('active');
172 }
173 }
174
175 // Remove items that no longer exist.
176 this.$buttongroup.find('button').each(function(i, obj) {
177 var value = $(obj).html();
178 var found = false;
179 for (var index in items) {
180 if (items[index] == value) {
181 found = true;
182 break;
183 }
184 }
185
186 if (!found) {
187 $(obj).remove();
188 }
189 });
190 },
191
192 });
193
194 IPython.notebook.widget_manager.register_widget_view('ToggleButtonView', ToggleButtonView);
General Comments 0
You need to be logged in to leave comments. Login now