diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js index 140115631..5dbdd3598 100644 --- a/IPython/html/static/notebook/js/widgetmanager.js +++ b/IPython/html/static/notebook/js/widgetmanager.js @@ -82,8 +82,7 @@ if (view === null) { console.error("View creation failed", model); } - if (cell.widget_subarea !== undefined - && cell.widget_subarea !== null) { + if (cell.widget_subarea) { cell.widget_area.show(); cell.widget_subarea.append(view.$el); @@ -95,7 +94,7 @@ // Creates a view for a particular model. var view_name = model.get('_view_name'); var ViewType = WidgetManager._view_types[view_name]; - if (ViewType !== undefined && ViewType !== null) { + if (ViewType) { // If a view is passed into the method, use that view's cell as // the cell for the view that is created. @@ -106,7 +105,7 @@ // Create and render the view... var parameters = {model: model, options: options}; - var view = new ViewType(parameters); + view = new ViewType(parameters); view.render(); model.views.push(view); model.on('destroy', view.remove, view); @@ -123,33 +122,31 @@ // If the view has a well defined element, inform the keyboard // manager about the view's element, so as the element can // escape the dreaded command mode. - if (view.$el !== undefined && view.$el !== null) { + if (view.$el) { IPython.keyboard_manager.register_events(view.$el); } - } + }; WidgetManager.prototype.get_msg_cell = function (msg_id) { var cell = null; // First, check to see if the msg was triggered by cell execution. - if (IPython.notebook !== undefined && IPython.notebook !== null) { + if (IPython.notebook) { cell = IPython.notebook.get_msg_cell(msg_id); } if (cell !== null) { - return cell + return cell; } // Second, check to see if a get_cell callback was defined // for the message. get_cell callbacks are registered for // widget messages, so this block is actually checking to see if the // message was triggered by a widget. var kernel = this.comm_manager.kernel; - if (kernel !== undefined && kernel !== null) { + if (kernel) { var callbacks = kernel.get_callbacks_for_msg(msg_id); - if (callbacks !== undefined && - callbacks.iopub !== undefined && + if (callbacks && callbacks.iopub && callbacks.iopub.get_cell !== undefined) { - return callbacks.iopub.get_cell(); - } + } } // Not triggered by a cell or widget (no get_cell callback @@ -160,16 +157,13 @@ WidgetManager.prototype.callbacks = function (view) { // callback handlers specific a view var callbacks = {}; - if (view !== undefined && - view !== null && - view.options.cell !== undefined && - view.options.cell !== null) { + if (view && view.options.cell) { // Try to get output handlers var cell = view.options.cell; var handle_output = null; var handle_clear_output = null; - if (cell.output_area !== undefined && cell.output_area !== null) { + if (cell.output_area) { handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); } diff --git a/IPython/html/static/notebook/js/widgets/widget.js b/IPython/html/static/notebook/js/widgets/widget.js index ce22e590b..d2857f0e8 100644 --- a/IPython/html/static/notebook/js/widgets/widget.js +++ b/IPython/html/static/notebook/js/widgets/widget.js @@ -21,7 +21,7 @@ function(WidgetManager, Underscore, Backbone){ var WidgetModel = Backbone.Model.extend({ constructor: function (widget_manager, model_id, comm) { - // Construcctor + // Constructor // // Creates a WidgetModel instance. // @@ -111,7 +111,7 @@ function(WidgetManager, Underscore, Backbone){ if (this.msg_buffer !== null && this.msg_throttle === this.pending_msgs) { var data = {method: 'backbone', sync_method: 'update', sync_data: this.msg_buffer}; - this.comm.send(data, callbacks); + this.comm.send(data, callbacks); this.msg_buffer = null; } else { --this.pending_msgs; @@ -131,7 +131,7 @@ function(WidgetManager, Underscore, Backbone){ var that = this; callbacks.iopub.status = function (msg) { that._handle_status(msg, callbacks); - } + }; return callbacks; }, @@ -141,7 +141,7 @@ function(WidgetManager, Underscore, Backbone){ // Make sure a comm exists. var error = options.error || function() { console.error('Backbone sync error:', arguments); - } + }; if (this.comm === undefined) { error(); return false; @@ -233,7 +233,7 @@ function(WidgetManager, Underscore, Backbone){ return unpacked; } else { var model = this.widget_manager.get_model(value); - if (model !== null) { + if (model) { return model; } else { return value; @@ -279,7 +279,7 @@ function(WidgetManager, Underscore, Backbone){ var view = this.child_views[child_model.id]; if (view !== undefined) { delete this.child_views[child_model.id]; - view.remove(); + view.remove(); } }, @@ -373,7 +373,7 @@ function(WidgetManager, Underscore, Backbone){ // to render var e = this.$el; var visible = this.model.get('visible'); - setTimeout(function() {e.toggle(visible)},0); + setTimeout(function() {e.toggle(visible);},0); var css = this.model.get('_css'); if (css === undefined) {return;} @@ -387,17 +387,16 @@ function(WidgetManager, Underscore, Backbone){ }); } }); - }, _get_selector_element: function (selector) { - // Get the elements via the css selector. + // Get the elements via the css selector. // If the selector is blank, apply the style to the $el_to_style // element. If the $el_to_style element is not defined, use apply // the style to the view's element. var elements; - if (selector === undefined || selector === null || selector === '') { + if (!selector) { if (this.$el_to_style === undefined) { elements = this.$el; } else { diff --git a/IPython/html/static/notebook/js/widgets/widget_button.js b/IPython/html/static/notebook/js/widgets/widget_button.js index 50c448cc9..a0b747ebd 100644 --- a/IPython/html/static/notebook/js/widgets/widget_button.js +++ b/IPython/html/static/notebook/js/widgets/widget_button.js @@ -16,7 +16,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){ - var ButtonView = IPython.DOMWidgetView.extend({ + var ButtonView = IPython.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.setElement($("