##// END OF EJS Templates
jslint /widgets
Jonathan Frederic -
Show More
@@ -54,7 +54,7 b' define(["notebook/js/widget"], function(widget_manager){'
54 this.$checkbox.prop('disabled', disabled);
54 this.$checkbox.prop('disabled', disabled);
55
55
56 var description = this.model.get('description');
56 var description = this.model.get('description');
57 if (description.length == 0) {
57 if (description.length === 0) {
58 this.$label.hide();
58 this.$label.hide();
59 } else {
59 } else {
60 this.$label.html(description);
60 this.$label.html(description);
@@ -98,7 +98,7 b' define(["notebook/js/widget"], function(widget_manager){'
98 this.$button.prop('disabled', disabled);
98 this.$button.prop('disabled', disabled);
99
99
100 var description = this.model.get('description');
100 var description = this.model.get('description');
101 if (description.length == 0) {
101 if (description.length === 0) {
102 this.$button.html(' '); // Preserve button height
102 this.$button.html(' '); // Preserve button height
103 } else {
103 } else {
104 this.$button.html(description);
104 this.$button.html(description);
@@ -36,7 +36,7 b' define(["notebook/js/widget"], function(widget_manager){'
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('&nbsp;'); // Preserve button height
40 this.$el.html('&nbsp;'); // Preserve button height
41 } else {
41 } else {
42 this.$el.html(description);
42 this.$el.html(description);
@@ -87,7 +87,7 b' define(["notebook/js/widget"], function(widget_manager) {'
87 .appendTo(this.$window)
87 .appendTo(this.$window)
88 .mousedown(function(){
88 .mousedown(function(){
89 that.bring_to_front();
89 that.bring_to_front();
90 });;
90 });
91 this.$close = $('<button />')
91 this.$close = $('<button />')
92 .addClass('close icon-remove')
92 .addClass('close icon-remove')
93 .css('margin-left', '5px')
93 .css('margin-left', '5px')
@@ -156,7 +156,7 b' define(["notebook/js/widget"], function(widget_manager) {'
156 this.$window.resizable();
156 this.$window.resizable();
157 this.$window.on('resize', function(){
157 this.$window.on('resize', function(){
158 that.$body.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight());
158 that.$body.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight());
159 })
159 });
160
160
161 this.$el_to_style = this.$body;
161 this.$el_to_style = this.$body;
162 this._shown_once = false;
162 this._shown_once = false;
@@ -173,7 +173,7 b' define(["notebook/js/widget"], function(widget_manager) {'
173
173
174 this.$window.show();
174 this.$window.show();
175 if (this.popped_out) {
175 if (this.popped_out) {
176 this.$window.css("positon", "absolute")
176 this.$window.css("positon", "absolute");
177 this.$window.css("top", "0px");
177 this.$window.css("top", "0px");
178 this.$window.css("left", Math.max(0, (($('body').outerWidth() - this.$window.outerWidth()) / 2) +
178 this.$window.css("left", Math.max(0, (($('body').outerWidth() - this.$window.outerWidth()) / 2) +
179 $(window).scrollLeft()) + "px");
179 $(window).scrollLeft()) + "px");
@@ -192,7 +192,7 b' define(["notebook/js/widget"], function(widget_manager) {'
192 max_zindex = Math.max(max_zindex, 2000);
192 max_zindex = Math.max(max_zindex, 2000);
193
193
194 $widget_modals.each(function (index, el){
194 $widget_modals.each(function (index, el){
195 $el = $(el)
195 $el = $(el);
196 if (max_zindex == parseInt($el.css('z-index'))) {
196 if (max_zindex == parseInt($el.css('z-index'))) {
197 $el.css('z-index', max_zindex - 1);
197 $el.css('z-index', max_zindex - 1);
198 }
198 }
@@ -206,7 +206,7 b' define(["notebook/js/widget"], function(widget_manager) {'
206 var description = this.model.get('description');
206 var description = this.model.get('description');
207 description = description.replace(/ /g, '&nbsp;', 'm');
207 description = description.replace(/ /g, '&nbsp;', 'm');
208 description = description.replace(/\n/g, '<br>\n', 'm');
208 description = description.replace(/\n/g, '<br>\n', 'm');
209 if (description.length == 0) {
209 if (description.length === 0) {
210 this.$title.html('&nbsp;'); // Preserve title height
210 this.$title.html('&nbsp;'); // Preserve title height
211 } else {
211 } else {
212 this.$title.html(description);
212 this.$title.html(description);
@@ -215,7 +215,7 b' define(["notebook/js/widget"], function(widget_manager) {'
215 var button_text = this.model.get('button_text');
215 var button_text = this.model.get('button_text');
216 button_text = button_text.replace(/ /g, '&nbsp;', 'm');
216 button_text = button_text.replace(/ /g, '&nbsp;', 'm');
217 button_text = button_text.replace(/\n/g, '<br>\n', 'm');
217 button_text = button_text.replace(/\n/g, '<br>\n', 'm');
218 if (button_text.length == 0) {
218 if (button_text.length === 0) {
219 this.$show_button.html('&nbsp;'); // Preserve button height
219 this.$show_button.html('&nbsp;'); // Preserve button height
220 } else {
220 } else {
221 this.$show_button.html(button_text);
221 this.$show_button.html(button_text);
@@ -51,7 +51,7 b' define(["notebook/js/widget"], function(widget_manager){'
51 var _keys = ['step', 'max', 'min', 'disabled'];
51 var _keys = ['step', 'max', 'min', 'disabled'];
52 for (var index in _keys) {
52 for (var index in _keys) {
53 var key = _keys[index];
53 var key = _keys[index];
54 if (this.model.get(key) != undefined) {
54 if (this.model.get(key) !== undefined) {
55 this.$slider.slider("option", key, this.model.get(key));
55 this.$slider.slider("option", key, this.model.get(key));
56 }
56 }
57 }
57 }
@@ -68,7 +68,7 b' define(["notebook/js/widget"], function(widget_manager){'
68 var value = this.model.get('min');
68 var value = this.model.get('min');
69 this.$slider.slider('option', 'value', value);
69 this.$slider.slider('option', 'value', value);
70 this.$slider.slider('option', 'orientation', orientation);
70 this.$slider.slider('option', 'orientation', orientation);
71 var value = this.model.get('value');
71 value = this.model.get('value');
72 this.$slider.slider('option', 'value', value);
72 this.$slider.slider('option', 'value', value);
73
73
74 // Use the right CSS classes for vertical & horizontal sliders
74 // Use the right CSS classes for vertical & horizontal sliders
@@ -96,7 +96,7 b' define(["notebook/js/widget"], function(widget_manager){'
96 }
96 }
97
97
98 var description = this.model.get('description');
98 var description = this.model.get('description');
99 if (description.length == 0) {
99 if (description.length === 0) {
100 this.$label.hide();
100 this.$label.hide();
101 } else {
101 } else {
102 this.$label.html(description);
102 this.$label.html(description);
@@ -150,7 +150,7 b' define(["notebook/js/widget"], function(widget_manager){'
150 }
150 }
151
151
152 var description = this.model.get('description');
152 var description = this.model.get('description');
153 if (description.length == 0) {
153 if (description.length === 0) {
154 this.$label.hide();
154 this.$label.hide();
155 } else {
155 } else {
156 this.$label.html(description);
156 this.$label.html(description);
@@ -170,7 +170,7 b' define(["notebook/js/widget"], function(widget_manager){'
170
170
171 // Try to parse value as a float.
171 // Try to parse value as a float.
172 var numericalValue = 0.0;
172 var numericalValue = 0.0;
173 if (e.target.value != '') {
173 if (e.target.value !== '') {
174 numericalValue = parseFloat(e.target.value);
174 numericalValue = parseFloat(e.target.value);
175 }
175 }
176
176
@@ -178,10 +178,10 b' define(["notebook/js/widget"], function(widget_manager){'
178 if (isNaN(numericalValue)) {
178 if (isNaN(numericalValue)) {
179 e.target.value = this.model.get('value');
179 e.target.value = this.model.get('value');
180 } else if (!isNaN(numericalValue)) {
180 } else if (!isNaN(numericalValue)) {
181 if (this.model.get('max') != undefined) {
181 if (this.model.get('max') !== undefined) {
182 numericalValue = Math.min(this.model.get('max'), numericalValue);
182 numericalValue = Math.min(this.model.get('max'), numericalValue);
183 }
183 }
184 if (this.model.get('min') != undefined) {
184 if (this.model.get('min') !== undefined) {
185 numericalValue = Math.max(this.model.get('min'), numericalValue);
185 numericalValue = Math.max(this.model.get('min'), numericalValue);
186 }
186 }
187
187
@@ -240,7 +240,7 b' define(["notebook/js/widget"], function(widget_manager){'
240 this.$bar.css('width', percent + '%');
240 this.$bar.css('width', percent + '%');
241
241
242 var description = this.model.get('description');
242 var description = this.model.get('description');
243 if (description.length == 0) {
243 if (description.length === 0) {
244 this.$label.hide();
244 this.$label.hide();
245 } else {
245 } else {
246 this.$label.html(description);
246 this.$label.html(description);
@@ -51,7 +51,7 b' define(["notebook/js/widget"], function(widget_manager){'
51 var _keys = ['step', 'max', 'min', 'disabled'];
51 var _keys = ['step', 'max', 'min', 'disabled'];
52 for (var index in _keys) {
52 for (var index in _keys) {
53 var key = _keys[index];
53 var key = _keys[index];
54 if (this.model.get(key) != undefined) {
54 if (this.model.get(key) !== undefined) {
55 this.$slider.slider("option", key, this.model.get(key));
55 this.$slider.slider("option", key, this.model.get(key));
56 }
56 }
57 }
57 }
@@ -68,7 +68,7 b' define(["notebook/js/widget"], function(widget_manager){'
68 var value = this.model.get('min');
68 var value = this.model.get('min');
69 this.$slider.slider('option', 'value', value);
69 this.$slider.slider('option', 'value', value);
70 this.$slider.slider('option', 'orientation', orientation);
70 this.$slider.slider('option', 'orientation', orientation);
71 var value = this.model.get('value');
71 value = this.model.get('value');
72 this.$slider.slider('option', 'value', value);
72 this.$slider.slider('option', 'value', value);
73
73
74 // Use the right CSS classes for vertical & horizontal sliders
74 // Use the right CSS classes for vertical & horizontal sliders
@@ -96,7 +96,7 b' define(["notebook/js/widget"], function(widget_manager){'
96 }
96 }
97
97
98 var description = this.model.get('description');
98 var description = this.model.get('description');
99 if (description.length == 0) {
99 if (description.length === 0) {
100 this.$label.hide();
100 this.$label.hide();
101 } else {
101 } else {
102 this.$label.html(description);
102 this.$label.html(description);
@@ -149,7 +149,7 b' define(["notebook/js/widget"], function(widget_manager){'
149 }
149 }
150
150
151 var description = this.model.get('description');
151 var description = this.model.get('description');
152 if (description.length == 0) {
152 if (description.length === 0) {
153 this.$label.hide();
153 this.$label.hide();
154 } else {
154 } else {
155 this.$label.html(description);
155 this.$label.html(description);
@@ -169,7 +169,7 b' define(["notebook/js/widget"], function(widget_manager){'
169
169
170 // Try to parse value as a float.
170 // Try to parse value as a float.
171 var numericalValue = 0;
171 var numericalValue = 0;
172 if (e.target.value != '') {
172 if (e.target.value !== '') {
173 numericalValue = parseInt(e.target.value);
173 numericalValue = parseInt(e.target.value);
174 }
174 }
175
175
@@ -177,10 +177,10 b' define(["notebook/js/widget"], function(widget_manager){'
177 if (isNaN(numericalValue)) {
177 if (isNaN(numericalValue)) {
178 e.target.value = this.model.get('value');
178 e.target.value = this.model.get('value');
179 } else if (!isNaN(numericalValue)) {
179 } else if (!isNaN(numericalValue)) {
180 if (this.model.get('max') != undefined) {
180 if (this.model.get('max') !== undefined) {
181 numericalValue = Math.min(this.model.get('max'), numericalValue);
181 numericalValue = Math.min(this.model.get('max'), numericalValue);
182 }
182 }
183 if (this.model.get('min') != undefined) {
183 if (this.model.get('min') !== undefined) {
184 numericalValue = Math.max(this.model.get('min'), numericalValue);
184 numericalValue = Math.max(this.model.get('min'), numericalValue);
185 }
185 }
186
186
@@ -33,8 +33,8 b' define(["notebook/js/widget"], function(widget_manager){'
33 var titles = this.model.get('_titles');
33 var titles = this.model.get('_titles');
34 for (var page_index in titles) {
34 for (var page_index in titles) {
35
35
36 var accordian = this.containers[page_index]
36 var accordian = this.containers[page_index];
37 if (accordian != undefined) {
37 if (accordian !== undefined) {
38 accordian
38 accordian
39 .find('.accordion-heading')
39 .find('.accordion-heading')
40 .find('.accordion-toggle')
40 .find('.accordion-toggle')
@@ -95,7 +95,7 b' define(["notebook/js/widget"], function(widget_manager){'
95 // open by default even though they don't have the `in` class
95 // open by default even though they don't have the `in` class
96 // attached to them. For some reason a delay is required.
96 // attached to them. For some reason a delay is required.
97 // TODO: Better fix.
97 // TODO: Better fix.
98 setTimeout(function(){that.update()}, 500);
98 setTimeout(function(){ that.update(); }, 500);
99 },
99 },
100 });
100 });
101
101
@@ -121,8 +121,8 b' define(["notebook/js/widget"], function(widget_manager){'
121 // Set tab titles
121 // Set tab titles
122 var titles = this.model.get('_titles');
122 var titles = this.model.get('_titles');
123 for (var page_index in titles) {
123 for (var page_index in titles) {
124 var tab_text = this.containers[page_index]
124 var tab_text = this.containers[page_index];
125 if (tab_text != undefined) {
125 if (tab_text !== undefined) {
126 tab_text.html(titles[page_index]);
126 tab_text.html(titles[page_index]);
127 }
127 }
128 }
128 }
@@ -162,7 +162,7 b' define(["notebook/js/widget"], function(widget_manager){'
162 .append(view.$el)
162 .append(view.$el)
163 .appendTo(this.$tab_contents);
163 .appendTo(this.$tab_contents);
164
164
165 if (index==0) {
165 if (index === 0) {
166 tab_text.tab('show');
166 tab_text.tab('show');
167 }
167 }
168 this.update();
168 this.update();
@@ -62,7 +62,7 b' define(["notebook/js/widget"], function(widget_manager){'
62 var selected_item_text = this.model.get('value');
62 var selected_item_text = this.model.get('value');
63 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
63 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
64 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
64 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
65 if (selected_item_text.length == 0) {
65 if (selected_item_text.length === 0) {
66 this.$droplabel.html('&nbsp;');
66 this.$droplabel.html('&nbsp;');
67 } else {
67 } else {
68 this.$droplabel.html(selected_item_text);
68 this.$droplabel.html(selected_item_text);
@@ -74,12 +74,8 b' define(["notebook/js/widget"], function(widget_manager){'
74 var that = this;
74 var that = this;
75 var item_button = $('<a href="#"/>')
75 var item_button = $('<a href="#"/>')
76 .html(items[index])
76 .html(items[index])
77 .on('click', function(e){
77 .on('click', this.handle_click);
78 that.model.set('value', $(e.target).html(), this);
78 this.$droplist.append($('<li />').append(item_button));
79 that.model.update_other_views(that);
80 })
81
82 this.$droplist.append($('<li />').append(item_button))
83 }
79 }
84
80
85 if (this.model.get('disabled')) {
81 if (this.model.get('disabled')) {
@@ -95,7 +91,7 b' define(["notebook/js/widget"], function(widget_manager){'
95 }
91 }
96
92
97 var description = this.model.get('description');
93 var description = this.model.get('description');
98 if (description.length == 0) {
94 if (description.length === 0) {
99 this.$label.hide();
95 this.$label.hide();
100 } else {
96 } else {
101 this.$label.html(description);
97 this.$label.html(description);
@@ -103,6 +99,12 b' define(["notebook/js/widget"], function(widget_manager){'
103 }
99 }
104 return IPython.WidgetView.prototype.update.call(this);
100 return IPython.WidgetView.prototype.update.call(this);
105 },
101 },
102
103 // Handle when a value is clicked.
104 handle_click: function (e) {
105 this.model.set('value', $(e.target).html(), this);
106 this.model.update_other_views(this);
107 },
106
108
107 });
109 });
108
110
@@ -136,22 +138,18 b' define(["notebook/js/widget"], function(widget_manager){'
136 var disabled = this.model.get('disabled');
138 var disabled = this.model.get('disabled');
137 for (var index in items) {
139 for (var index in items) {
138 var item_query = ' :input[value="' + items[index] + '"]';
140 var item_query = ' :input[value="' + items[index] + '"]';
139 if (this.$el.find(item_query).length == 0) {
141 if (this.$el.find(item_query).length === 0) {
140 var $label = $('<label />')
142 var $label = $('<label />')
141 .addClass('radio')
143 .addClass('radio')
142 .html(items[index])
144 .html(items[index])
143 .appendTo(this.$container);
145 .appendTo(this.$container);
144
146
145 var that = this;
146 $('<input />')
147 $('<input />')
147 .attr('type', 'radio')
148 .attr('type', 'radio')
148 .addClass(this.model)
149 .addClass(this.model)
149 .val(items[index])
150 .val(items[index])
150 .prependTo($label)
151 .prependTo($label)
151 .on('click', function(e){
152 .on('click', this.handle_click);
152 that.model.set('value', $(e.target).val(), this);
153 that.model.update_other_views(that);
154 });
155 }
153 }
156
154
157 var $item_element = this.$container.find(item_query);
155 var $item_element = this.$container.find(item_query);
@@ -180,7 +178,7 b' define(["notebook/js/widget"], function(widget_manager){'
180 });
178 });
181
179
182 var description = this.model.get('description');
180 var description = this.model.get('description');
183 if (description.length == 0) {
181 if (description.length === 0) {
184 this.$label.hide();
182 this.$label.hide();
185 } else {
183 } else {
186 this.$label.html(description);
184 this.$label.html(description);
@@ -188,7 +186,12 b' define(["notebook/js/widget"], function(widget_manager){'
188 }
186 }
189 return IPython.WidgetView.prototype.update.call(this);
187 return IPython.WidgetView.prototype.update.call(this);
190 },
188 },
191
189
190 // Handle when a value is clicked.
191 handle_click: function (e) {
192 this.model.set('value', $(e.target).val(), this);
193 this.model.update_other_views(this);
194 },
192 });
195 });
193
196
194 widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
197 widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
@@ -222,18 +225,13 b' define(["notebook/js/widget"], function(widget_manager){'
222 var disabled = this.model.get('disabled');
225 var disabled = this.model.get('disabled');
223 for (var index in items) {
226 for (var index in items) {
224 var item_query = ' :contains("' + items[index] + '")';
227 var item_query = ' :contains("' + items[index] + '")';
225 if (this.$buttongroup.find(item_query).length == 0) {
228 if (this.$buttongroup.find(item_query).length === 0) {
226
227 var that = this;
228 $('<button />')
229 $('<button />')
229 .attr('type', 'button')
230 .attr('type', 'button')
230 .addClass('btn')
231 .addClass('btn')
231 .html(items[index])
232 .html(items[index])
232 .appendTo(this.$buttongroup)
233 .appendTo(this.$buttongroup)
233 .on('click', function(e){
234 .on('click', this.handle_click);
234 that.model.set('value', $(e.target).html(), this);
235 that.model.update_other_views(that);
236 });
237 }
235 }
238
236
239 var $item_element = this.$buttongroup.find(item_query);
237 var $item_element = this.$buttongroup.find(item_query);
@@ -262,7 +260,7 b' define(["notebook/js/widget"], function(widget_manager){'
262 });
260 });
263
261
264 var description = this.model.get('description');
262 var description = this.model.get('description');
265 if (description.length == 0) {
263 if (description.length === 0) {
266 this.$label.hide();
264 this.$label.hide();
267 } else {
265 } else {
268 this.$label.html(description);
266 this.$label.html(description);
@@ -270,6 +268,12 b' define(["notebook/js/widget"], function(widget_manager){'
270 }
268 }
271 return IPython.WidgetView.prototype.update.call(this);
269 return IPython.WidgetView.prototype.update.call(this);
272 },
270 },
271
272 // Handle when a value is clicked.
273 handle_click: function (e) {
274 this.model.set('value', $(e.target).html(), this);
275 this.model.update_other_views(this);
276 },
273
277
274 });
278 });
275
279
@@ -302,17 +306,12 b' define(["notebook/js/widget"], function(widget_manager){'
302 var items = this.model.get('values');
306 var items = this.model.get('values');
303 for (var index in items) {
307 for (var index in items) {
304 var item_query = ' :contains("' + items[index] + '")';
308 var item_query = ' :contains("' + items[index] + '")';
305 if (this.$listbox.find(item_query).length == 0) {
309 if (this.$listbox.find(item_query).length === 0) {
306
307 var that = this;
308 $('<option />')
310 $('<option />')
309 .html(items[index])
311 .html(items[index])
310 .attr('value', items[index])
312 .attr('value', items[index])
311 .appendTo(this.$listbox)
313 .appendTo(this.$listbox)
312 .on('click', function(e){
314 .on('click', this.handle_click);
313 that.model.set('value', $(e.target).html(), this);
314 that.model.update_other_views(that);
315 });
316 }
315 }
317 }
316 }
318
317
@@ -340,7 +339,7 b' define(["notebook/js/widget"], function(widget_manager){'
340 });
339 });
341
340
342 var description = this.model.get('description');
341 var description = this.model.get('description');
343 if (description.length == 0) {
342 if (description.length === 0) {
344 this.$label.hide();
343 this.$label.hide();
345 } else {
344 } else {
346 this.$label.html(description);
345 this.$label.html(description);
@@ -348,6 +347,12 b' define(["notebook/js/widget"], function(widget_manager){'
348 }
347 }
349 return IPython.WidgetView.prototype.update.call(this);
348 return IPython.WidgetView.prototype.update.call(this);
350 },
349 },
350
351 // Handle when a value is clicked.
352 handle_click: function (e) {
353 this.model.set('value', $(e.target).html(), this);
354 this.model.update_other_views(this);
355 },
351
356
352 });
357 });
353
358
@@ -102,7 +102,7 b' define(["notebook/js/widget"], function(widget_manager){'
102 this.$textbox.prop('disabled', disabled);
102 this.$textbox.prop('disabled', disabled);
103
103
104 var description = this.model.get('description');
104 var description = this.model.get('description');
105 if (description.length == 0) {
105 if (description.length === 0) {
106 this.$label.hide();
106 this.$label.hide();
107 } else {
107 } else {
108 this.$label.html(description);
108 this.$label.html(description);
@@ -156,7 +156,7 b' define(["notebook/js/widget"], function(widget_manager){'
156 this.$textbox.prop('disabled', disabled);
156 this.$textbox.prop('disabled', disabled);
157
157
158 var description = this.model.get('description');
158 var description = this.model.get('description');
159 if (description.length == 0) {
159 if (description.length === 0) {
160 this.$label.hide();
160 this.$label.hide();
161 } else {
161 } else {
162 this.$label.html(description);
162 this.$label.html(description);
General Comments 0
You need to be logged in to leave comments. Login now