##// END OF EJS Templates
quick review pass on javascript
MinRK -
Show More
@@ -21,7 +21,7 b' function(WidgetManager, Underscore, Backbone){'
21
21
22 var WidgetModel = Backbone.Model.extend({
22 var WidgetModel = Backbone.Model.extend({
23 constructor: function (widget_manager, model_id, comm) {
23 constructor: function (widget_manager, model_id, comm) {
24 // Construcctor
24 // Constructor
25 //
25 //
26 // Creates a WidgetModel instance.
26 // Creates a WidgetModel instance.
27 //
27 //
@@ -111,7 +111,7 b' function(WidgetManager, Underscore, Backbone){'
111 if (this.msg_buffer !== null &&
111 if (this.msg_buffer !== null &&
112 this.msg_throttle === this.pending_msgs) {
112 this.msg_throttle === this.pending_msgs) {
113 var data = {method: 'backbone', sync_method: 'update', sync_data: this.msg_buffer};
113 var data = {method: 'backbone', sync_method: 'update', sync_data: this.msg_buffer};
114 this.comm.send(data, callbacks);
114 this.comm.send(data, callbacks);
115 this.msg_buffer = null;
115 this.msg_buffer = null;
116 } else {
116 } else {
117 --this.pending_msgs;
117 --this.pending_msgs;
@@ -131,7 +131,7 b' function(WidgetManager, Underscore, Backbone){'
131 var that = this;
131 var that = this;
132 callbacks.iopub.status = function (msg) {
132 callbacks.iopub.status = function (msg) {
133 that._handle_status(msg, callbacks);
133 that._handle_status(msg, callbacks);
134 }
134 };
135 return callbacks;
135 return callbacks;
136 },
136 },
137
137
@@ -141,7 +141,7 b' function(WidgetManager, Underscore, Backbone){'
141 // Make sure a comm exists.
141 // Make sure a comm exists.
142 var error = options.error || function() {
142 var error = options.error || function() {
143 console.error('Backbone sync error:', arguments);
143 console.error('Backbone sync error:', arguments);
144 }
144 };
145 if (this.comm === undefined) {
145 if (this.comm === undefined) {
146 error();
146 error();
147 return false;
147 return false;
@@ -233,7 +233,7 b' function(WidgetManager, Underscore, Backbone){'
233 return unpacked;
233 return unpacked;
234 } else {
234 } else {
235 var model = this.widget_manager.get_model(value);
235 var model = this.widget_manager.get_model(value);
236 if (model !== null) {
236 if (model) {
237 return model;
237 return model;
238 } else {
238 } else {
239 return value;
239 return value;
@@ -279,7 +279,7 b' function(WidgetManager, Underscore, Backbone){'
279 var view = this.child_views[child_model.id];
279 var view = this.child_views[child_model.id];
280 if (view !== undefined) {
280 if (view !== undefined) {
281 delete this.child_views[child_model.id];
281 delete this.child_views[child_model.id];
282 view.remove();
282 view.remove();
283 }
283 }
284 },
284 },
285
285
@@ -373,7 +373,7 b' function(WidgetManager, Underscore, Backbone){'
373 // to render
373 // to render
374 var e = this.$el;
374 var e = this.$el;
375 var visible = this.model.get('visible');
375 var visible = this.model.get('visible');
376 setTimeout(function() {e.toggle(visible)},0);
376 setTimeout(function() {e.toggle(visible);},0);
377
377
378 var css = this.model.get('_css');
378 var css = this.model.get('_css');
379 if (css === undefined) {return;}
379 if (css === undefined) {return;}
@@ -387,17 +387,16 b' function(WidgetManager, Underscore, Backbone){'
387 });
387 });
388 }
388 }
389 });
389 });
390
391 },
390 },
392
391
393 _get_selector_element: function (selector) {
392 _get_selector_element: function (selector) {
394 // Get the elements via the css selector.
393 // Get the elements via the css selector.
395
394
396 // If the selector is blank, apply the style to the $el_to_style
395 // If the selector is blank, apply the style to the $el_to_style
397 // element. If the $el_to_style element is not defined, use apply
396 // element. If the $el_to_style element is not defined, use apply
398 // the style to the view's element.
397 // the style to the view's element.
399 var elements;
398 var elements;
400 if (selector === undefined || selector === null || selector === '') {
399 if (!selector) {
401 if (this.$el_to_style === undefined) {
400 if (this.$el_to_style === undefined) {
402 elements = this.$el;
401 elements = this.$el;
403 } else {
402 } else {
@@ -16,7 +16,7 b''
16
16
17 define(["notebook/js/widgets/widget"], function(WidgetManager){
17 define(["notebook/js/widgets/widget"], function(WidgetManager){
18
18
19 var ButtonView = IPython.DOMWidgetView.extend({
19 var ButtonView = IPython.DOMWidgetView.extend({
20 render : function(){
20 render : function(){
21 // Called when view is rendered.
21 // Called when view is rendered.
22 this.setElement($("<button />")
22 this.setElement($("<button />")
@@ -16,22 +16,21 b''
16
16
17 define(["notebook/js/widgets/widget"], function(WidgetManager) {
17 define(["notebook/js/widgets/widget"], function(WidgetManager) {
18
18
19 var ContainerView = IPython.DOMWidgetView.extend({
19 var ContainerView = IPython.DOMWidgetView.extend({
20 render: function(){
20 render: function(){
21 // Called when view is rendered.
21 // Called when view is rendered.
22 this.$el
22 this.$el.addClass('widget-container');
23 .addClass('widget-container');
24 this.children={};
23 this.children={};
25 this.update_children([], this.model.get('_children'));
24 this.update_children([], this.model.get('_children'));
26 this.model.on('change:_children', function(model, value, options) {
25 this.model.on('change:_children', function(model, value, options) {
27 this.update_children(model.previous('_children'), value);
26 this.update_children(model.previous('_children'), value);
28 }, this);
27 }, this);
29 this.update()
28 this.update();
30 },
29 },
31
30
32 update_children: function(old_list, new_list) {
31 update_children: function(old_list, new_list) {
33 // Called when the children list changes.
32 // Called when the children list changes.
34 this.do_diff(old_list,
33 this.do_diff(old_list,
35 new_list,
34 new_list,
36 $.proxy(this.remove_child_model, this),
35 $.proxy(this.remove_child_model, this),
37 $.proxy(this.add_child_model, this));
36 $.proxy(this.add_child_model, this));
@@ -57,17 +56,16 b' define(["notebook/js/widgets/widget"], function(WidgetManager) {'
57 return ContainerView.__super__.update.apply(this);
56 return ContainerView.__super__.update.apply(this);
58 },
57 },
59 });
58 });
59
60 WidgetManager.register_widget_view('ContainerView', ContainerView);
60 WidgetManager.register_widget_view('ContainerView', ContainerView);
61
61
62
62 var PopupView = IPython.DOMWidgetView.extend({
63 var PopupView = IPython.DOMWidgetView.extend({
64 render: function(){
63 render: function(){
65 // Called when view is rendered.
64 // Called when view is rendered.
66 var that = this;
65 var that = this;
67 this.children={};
66 this.children={};
68
67
69 this.$el
68 this.$el.on("remove", function(){
70 .on("remove", function(){
71 that.$window.remove();
69 that.$window.remove();
72 });
70 });
73 this.$window = $('<div />')
71 this.$window = $('<div />')
@@ -32,7 +32,7 b' define(["notebook/js/widgets/widget",'
32 WidgetManager.register_widget_view('FloatSliderView', FloatSliderView);
32 WidgetManager.register_widget_view('FloatSliderView', FloatSliderView);
33
33
34
34
35 var FloatTextView = IntTextView.extend({
35 var FloatTextView = IntTextView.extend({
36 _parse_value: function(value) {
36 _parse_value: function(value) {
37 // Parse the value stored in a string.
37 // Parse the value stored in a string.
38 return parseFloat(value);
38 return parseFloat(value);
@@ -16,7 +16,7 b''
16
16
17 define(["notebook/js/widgets/widget"], function(WidgetManager){
17 define(["notebook/js/widgets/widget"], function(WidgetManager){
18
18
19 var IntSliderView = IPython.DOMWidgetView.extend({
19 var IntSliderView = IPython.DOMWidgetView.extend({
20 render : function(){
20 render : function(){
21 // Called when view is rendered.
21 // Called when view is rendered.
22 this.$el
22 this.$el
@@ -32,7 +32,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
32 // Put the slider in a container
32 // Put the slider in a container
33 this.$slider_container = $('<div />')
33 this.$slider_container = $('<div />')
34 .addClass('widget-hslider')
34 .addClass('widget-hslider')
35 .append(this.$slider);
35 .append(this.$slider);
36 this.$el_to_style = this.$slider_container; // Set default element to style
36 this.$el_to_style = this.$slider_container; // Set default element to style
37 this.$el.append(this.$slider_container);
37 this.$el.append(this.$slider_container);
38
38
@@ -218,7 +218,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
218 }
218 }
219 },
219 },
220
220
221 handleChanged: function(e) {
221 handleChanged: function(e) {
222 // Applies validated input.
222 // Applies validated input.
223 if (this.model.get('value') != e.target.value) {
223 if (this.model.get('value') != e.target.value) {
224 e.target.value = this.model.get('value');
224 e.target.value = this.model.get('value');
@@ -233,7 +233,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
233 WidgetManager.register_widget_view('IntTextView', IntTextView);
233 WidgetManager.register_widget_view('IntTextView', IntTextView);
234
234
235
235
236 var ProgressView = IPython.DOMWidgetView.extend({
236 var ProgressView = IPython.DOMWidgetView.extend({
237 render : function(){
237 render : function(){
238 // Called when view is rendered.
238 // Called when view is rendered.
239 this.$el
239 this.$el
@@ -18,7 +18,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
18
18
19 var DropdownView = IPython.DOMWidgetView.extend({
19 var DropdownView = IPython.DOMWidgetView.extend({
20 render : function(){
20 render : function(){
21 // Called when view is rendered.
21 // Called when view is rendered.
22 this.$el
22 this.$el
23 .addClass('widget-hbox-single');
23 .addClass('widget-hbox-single');
24 this.$label = $('<div />')
24 this.$label = $('<div />')
General Comments 0
You need to be logged in to leave comments. Login now