##// END OF EJS Templates
review pass on widgetmanager.js
MinRK -
Show More
@@ -82,8 +82,7 b''
82 if (view === null) {
82 if (view === null) {
83 console.error("View creation failed", model);
83 console.error("View creation failed", model);
84 }
84 }
85 if (cell.widget_subarea !== undefined
85 if (cell.widget_subarea) {
86 && cell.widget_subarea !== null) {
87
86
88 cell.widget_area.show();
87 cell.widget_area.show();
89 cell.widget_subarea.append(view.$el);
88 cell.widget_subarea.append(view.$el);
@@ -95,7 +94,7 b''
95 // Creates a view for a particular model.
94 // Creates a view for a particular model.
96 var view_name = model.get('_view_name');
95 var view_name = model.get('_view_name');
97 var ViewType = WidgetManager._view_types[view_name];
96 var ViewType = WidgetManager._view_types[view_name];
98 if (ViewType !== undefined && ViewType !== null) {
97 if (ViewType) {
99
98
100 // If a view is passed into the method, use that view's cell as
99 // If a view is passed into the method, use that view's cell as
101 // the cell for the view that is created.
100 // the cell for the view that is created.
@@ -106,7 +105,7 b''
106
105
107 // Create and render the view...
106 // Create and render the view...
108 var parameters = {model: model, options: options};
107 var parameters = {model: model, options: options};
109 var view = new ViewType(parameters);
108 view = new ViewType(parameters);
110 view.render();
109 view.render();
111 model.views.push(view);
110 model.views.push(view);
112 model.on('destroy', view.remove, view);
111 model.on('destroy', view.remove, view);
@@ -123,31 +122,29 b''
123 // If the view has a well defined element, inform the keyboard
122 // If the view has a well defined element, inform the keyboard
124 // manager about the view's element, so as the element can
123 // manager about the view's element, so as the element can
125 // escape the dreaded command mode.
124 // escape the dreaded command mode.
126 if (view.$el !== undefined && view.$el !== null) {
125 if (view.$el) {
127 IPython.keyboard_manager.register_events(view.$el);
126 IPython.keyboard_manager.register_events(view.$el);
128 }
127 }
129 }
128 };
130
129
131 WidgetManager.prototype.get_msg_cell = function (msg_id) {
130 WidgetManager.prototype.get_msg_cell = function (msg_id) {
132 var cell = null;
131 var cell = null;
133 // First, check to see if the msg was triggered by cell execution.
132 // First, check to see if the msg was triggered by cell execution.
134 if (IPython.notebook !== undefined && IPython.notebook !== null) {
133 if (IPython.notebook) {
135 cell = IPython.notebook.get_msg_cell(msg_id);
134 cell = IPython.notebook.get_msg_cell(msg_id);
136 }
135 }
137 if (cell !== null) {
136 if (cell !== null) {
138 return cell
137 return cell;
139 }
138 }
140 // Second, check to see if a get_cell callback was defined
139 // Second, check to see if a get_cell callback was defined
141 // for the message. get_cell callbacks are registered for
140 // for the message. get_cell callbacks are registered for
142 // widget messages, so this block is actually checking to see if the
141 // widget messages, so this block is actually checking to see if the
143 // message was triggered by a widget.
142 // message was triggered by a widget.
144 var kernel = this.comm_manager.kernel;
143 var kernel = this.comm_manager.kernel;
145 if (kernel !== undefined && kernel !== null) {
144 if (kernel) {
146 var callbacks = kernel.get_callbacks_for_msg(msg_id);
145 var callbacks = kernel.get_callbacks_for_msg(msg_id);
147 if (callbacks !== undefined &&
146 if (callbacks && callbacks.iopub &&
148 callbacks.iopub !== undefined &&
149 callbacks.iopub.get_cell !== undefined) {
147 callbacks.iopub.get_cell !== undefined) {
150
151 return callbacks.iopub.get_cell();
148 return callbacks.iopub.get_cell();
152 }
149 }
153 }
150 }
@@ -160,16 +157,13 b''
160 WidgetManager.prototype.callbacks = function (view) {
157 WidgetManager.prototype.callbacks = function (view) {
161 // callback handlers specific a view
158 // callback handlers specific a view
162 var callbacks = {};
159 var callbacks = {};
163 if (view !== undefined &&
160 if (view && view.options.cell) {
164 view !== null &&
165 view.options.cell !== undefined &&
166 view.options.cell !== null) {
167
161
168 // Try to get output handlers
162 // Try to get output handlers
169 var cell = view.options.cell;
163 var cell = view.options.cell;
170 var handle_output = null;
164 var handle_output = null;
171 var handle_clear_output = null;
165 var handle_clear_output = null;
172 if (cell.output_area !== undefined && cell.output_area !== null) {
166 if (cell.output_area) {
173 handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
167 handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
174 handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
168 handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
175 }
169 }
General Comments 0
You need to be logged in to leave comments. Login now