##// END OF EJS Templates
Better fix for empty dropdown button alignment...
Jonathan Frederic -
Show More
@@ -1,251 +1,260
1 1 define(["notebook/js/widget"], function(){
2 2 var SelectionWidgetModel = IPython.WidgetModel.extend({});
3 3 IPython.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel);
4 4
5 5 var DropdownView = IPython.WidgetView.extend({
6 6
7 7 // Called when view is rendered.
8 8 render : function(){
9 9
10 10 this.$el
11 11 .addClass('widget-hbox-single')
12 12 .html('');
13 13 this.$label = $('<div />')
14 14 .appendTo(this.$el)
15 15 .addClass('widget-hlabel')
16 16 .hide();
17 17 this.$buttongroup = $('<div />')
18 18 .addClass('widget_item')
19 19 .addClass('btn-group')
20 20 .appendTo(this.$el);
21 21 this.$el_to_style = this.$buttongroup; // Set default element to style
22 22 this.$droplabel = $('<button />')
23 23 .addClass('btn')
24 24 .addClass('widget-combo-btn')
25 .html('&nbsp;')
25 26 .appendTo(this.$buttongroup);
26 27 this.$dropbutton = $('<button />')
27 28 .addClass('btn')
28 29 .addClass('dropdown-toggle')
30 .addClass('widget-combo-carrot-btn')
29 31 .attr('data-toggle', 'dropdown')
30 32 .html('<span class="caret"></span>')
31 33 .appendTo(this.$buttongroup);
32 34 this.$droplist = $('<ul />')
33 35 .addClass('dropdown-menu')
34 36 .appendTo(this.$buttongroup);
35 37
36 38 // Set defaults.
37 39 this.update();
38 40 },
39 41
40 42 // Handles: Backend -> Frontend Sync
41 43 // Frontent -> Frontend Sync
42 44 update : function(){
45
46 var selected_item_text = this.model.get('value');
47 selected_item_text.replace(' ', '');
48 if (selected_item_text == '') {
49 this.$droplabel.html('&nbsp;');
50 } else {
43 51 this.$droplabel.html(this.model.get('value'));
52 }
44 53
45 54 var items = this.model.get('values');
46 55 this.$droplist.html('');
47 56 for (var index in items) {
48 57 var that = this;
49 58 var item_button = $('<a href="#"/>')
50 59 .html(items[index])
51 60 .on('click', function(e){
52 61 that.model.set('value', $(e.target).html(), this);
53 62 that.model.update_other_views(that);
54 63 })
55 64
56 65 this.$droplist.append($('<li />').append(item_button))
57 66 }
58 67
59 68 if (this.model.get('disabled')) {
60 69 this.$buttongroup.attr('disabled','disabled');
61 70 this.$droplabel.attr('disabled','disabled');
62 71 this.$dropbutton.attr('disabled','disabled');
63 72 this.$droplist.attr('disabled','disabled');
64 73 } else {
65 74 this.$buttongroup.removeAttr('disabled');
66 75 this.$droplabel.removeAttr('disabled');
67 76 this.$dropbutton.removeAttr('disabled');
68 77 this.$droplist.removeAttr('disabled');
69 78 }
70 79
71 80 var description = this.model.get('description');
72 81 if (description.length == 0) {
73 82 this.$label.hide();
74 83 } else {
75 84 this.$label.html(description);
76 85 this.$label.show();
77 86 }
78 87 return IPython.WidgetView.prototype.update.call(this);
79 88 },
80 89
81 90 });
82 91
83 92 IPython.widget_manager.register_widget_view('DropdownView', DropdownView);
84 93
85 94 var RadioButtonsView = IPython.WidgetView.extend({
86 95
87 96 // Called when view is rendered.
88 97 render : function(){
89 98 this.$el
90 99 .addClass('widget-hbox')
91 100 .html('');
92 101 this.$label = $('<div />')
93 102 .appendTo(this.$el)
94 103 .addClass('widget-hlabel')
95 104 .hide();
96 105 this.$container = $('<div />')
97 106 .appendTo(this.$el)
98 107 .addClass('widget-container')
99 108 .addClass('vbox');
100 109 this.$el_to_style = this.$container; // Set default element to style
101 110 this.update();
102 111 },
103 112
104 113 // Handles: Backend -> Frontend Sync
105 114 // Frontent -> Frontend Sync
106 115 update : function(){
107 116
108 117 // Add missing items to the DOM.
109 118 var items = this.model.get('values');
110 119 var disabled = this.model.get('disabled');
111 120 for (var index in items) {
112 121 var item_query = ' :input[value="' + items[index] + '"]';
113 122 if (this.$el.find(item_query).length == 0) {
114 123 var $label = $('<label />')
115 124 .addClass('radio')
116 125 .html(items[index])
117 126 .appendTo(this.$container);
118 127
119 128 var that = this;
120 129 $('<input />')
121 130 .attr('type', 'radio')
122 131 .addClass(this.model)
123 132 .val(items[index])
124 133 .prependTo($label)
125 134 .on('click', function(e){
126 135 that.model.set('value', $(e.target).val(), this);
127 136 that.model.update_other_views(that);
128 137 });
129 138 }
130 139
131 140 var $item_element = this.$container.find(item_query);
132 141 if (this.model.get('value') == items[index]) {
133 142 $item_element.prop('checked', true);
134 143 } else {
135 144 $item_element.prop('checked', false);
136 145 }
137 146 $item_element.prop('disabled', disabled);
138 147 }
139 148
140 149 // Remove items that no longer exist.
141 150 this.$container.find('input').each(function(i, obj) {
142 151 var value = $(obj).val();
143 152 var found = false;
144 153 for (var index in items) {
145 154 if (items[index] == value) {
146 155 found = true;
147 156 break;
148 157 }
149 158 }
150 159
151 160 if (!found) {
152 161 $(obj).parent().remove();
153 162 }
154 163 });
155 164
156 165 var description = this.model.get('description');
157 166 if (description.length == 0) {
158 167 this.$label.hide();
159 168 } else {
160 169 this.$label.html(description);
161 170 this.$label.show();
162 171 }
163 172 return IPython.WidgetView.prototype.update.call(this);
164 173 },
165 174
166 175 });
167 176
168 177 IPython.widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
169 178
170 179
171 180 var ToggleButtonsView = IPython.WidgetView.extend({
172 181
173 182 // Called when view is rendered.
174 183 render : function(){
175 184 this.$el
176 185 .addClass('widget-hbox-single')
177 186 .html('');
178 187 this.$label = $('<div />')
179 188 .appendTo(this.$el)
180 189 .addClass('widget-hlabel')
181 190 .hide();
182 191 this.$buttongroup = $('<div />')
183 192 .addClass('btn-group')
184 193 .attr('data-toggle', 'buttons-radio')
185 194 .appendTo(this.$el);
186 195 this.$el_to_style = this.$buttongroup; // Set default element to style
187 196 this.update();
188 197 },
189 198
190 199 // Handles: Backend -> Frontend Sync
191 200 // Frontent -> Frontend Sync
192 201 update : function(){
193 202
194 203 // Add missing items to the DOM.
195 204 var items = this.model.get('values');
196 205 var disabled = this.model.get('disabled');
197 206 for (var index in items) {
198 207 var item_query = ' :contains("' + items[index] + '")';
199 208 if (this.$buttongroup.find(item_query).length == 0) {
200 209
201 210 var that = this;
202 211 $('<button />')
203 212 .attr('type', 'button')
204 213 .addClass('btn')
205 214 .html(items[index])
206 215 .appendTo(this.$buttongroup)
207 216 .on('click', function(e){
208 217 that.model.set('value', $(e.target).html(), this);
209 218 that.model.update_other_views(that);
210 219 });
211 220 }
212 221
213 222 var $item_element = this.$buttongroup.find(item_query);
214 223 if (this.model.get('value') == items[index]) {
215 224 $item_element.addClass('active');
216 225 } else {
217 226 $item_element.removeClass('active');
218 227 }
219 228 $item_element.prop('disabled', disabled);
220 229 }
221 230
222 231 // Remove items that no longer exist.
223 232 this.$buttongroup.find('button').each(function(i, obj) {
224 233 var value = $(obj).html();
225 234 var found = false;
226 235 for (var index in items) {
227 236 if (items[index] == value) {
228 237 found = true;
229 238 break;
230 239 }
231 240 }
232 241
233 242 if (!found) {
234 243 $(obj).remove();
235 244 }
236 245 });
237 246
238 247 var description = this.model.get('description');
239 248 if (description.length == 0) {
240 249 this.$label.hide();
241 250 } else {
242 251 this.$label.html(description);
243 252 this.$label.show();
244 253 }
245 254 return IPython.WidgetView.prototype.update.call(this);
246 255 },
247 256
248 257 });
249 258
250 259 IPython.widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
251 260 });
@@ -1,130 +1,129
1 1
2 2 .widget-area {
3 3 page-break-inside: avoid;
4 4 .hbox();
5 5
6 6 .widget-subarea {
7 7 padding: 0.44em 0.4em 0.4em 1px;
8 8 margin-left: 6px;
9 9 .border-box-sizing();
10 10 .vbox();
11 11 .box-flex2();
12 12
13 13 .widget-hlabel {
14 14 min-width: 10ex;
15 15 padding-right: 8px;
16 16 text-align: right;
17 17 vertical-align: text-top;
18 18 padding-top: 3px;
19 19 }
20 20
21 21 .widget-vlabel {
22 22 text-align: center;
23 23 vertical-align: text-bottom;
24 24 padding-bottom: 5px;
25 25 }
26 26
27 27 .widget-hslider {
28 28 padding-left: 8px;
29 29 padding-right: 5px;
30 30 margin-top: 11px;
31 31
32 32 width: 348px;
33 33 height: 5px !important;
34 34 overflow: visible !important;
35 35
36 36 border: 1px solid #CCCCCC;
37 37 background: #FFFFFF;
38 38 .corner-all();
39 39
40 40 .ui-slider {
41 41 border: 0px !important;
42 42 background: none !important;
43 43
44 44 .ui-slider-handle {
45 45 width: 14px !important;
46 46 height: 28px !important;
47 47
48 48 margin-top: -8px !important;
49 49 }
50 50 }
51 51 }
52 52
53 53 .widget-vslider {
54 54 border: 1px solid #CCCCCC;
55 55 background: #FFFFFF;
56 56 width: 5px;
57 57 margin-left: 12px;
58 58 padding-bottom: 14px;
59 59 .corner-all();
60 60 height: 250px;
61 61
62 62 .ui-slider {
63 63 border: 0px !important;
64 64 background: none !important;
65 65 margin-left: -4px;
66 66 margin-top: 5px;
67 67 height: 100%;
68 68
69 69 .ui-slider-handle {
70 70 width: 28px !important;
71 71 height: 14px !important;
72 72 margin-left: -9px;
73 73 }
74 74 }
75 75 }
76 76
77 77 .widget-text {
78 78 width: 350px;
79 79 margin-bottom: 0px;
80 80 }
81 81
82 82 .widget-numeric-text {
83 83 width: 150px;
84 84 }
85 85
86 86 .widget-progress {
87 87 width: 363px;
88 88
89 89 /* Disable progress bar animation */
90 90 .bar {
91 91 -webkit-transition: none;
92 92 -moz-transition: none;
93 93 -ms-transition: none;
94 94 -o-transition: none;
95 95 transition: none;
96 96 }
97 97 }
98 98
99 99 .widget-combo-btn {
100 100 min-width: 138px; /* + 26px drop arrow btn = 164px */
101 min-height: 1ex;
102 101 }
103 102
104 103 .widget-container {
105 104 .border-box-sizing();
106 105 }
107 106
108 107 .widget-box {
109 108 .start();
110 109 .widget-container();
111 110 margin: 5px;
112 111 }
113 112
114 113 .widget-hbox {
115 114 .widget-box();
116 115 .hbox();
117 116 }
118 117
119 118 .widget-hbox-single {
120 119 .widget-hbox();
121 120 height: 30px;
122 121 }
123 122
124 123 .widget-vbox-single {
125 124 .widget-box();
126 125 .vbox();
127 126 width: 30px;
128 127 }
129 128 }
130 129 }
General Comments 0
You need to be logged in to leave comments. Login now