Show More
@@ -55,8 +55,8 b' define(["components/underscore/underscore-min",' | |||||
55 | this.last_modified_view = caller; |
|
55 | this.last_modified_view = caller; | |
56 | this.save(this.changedAttributes(), {patch: true}); |
|
56 | this.save(this.changedAttributes(), {patch: true}); | |
57 |
|
57 | |||
58 |
for (var |
|
58 | for (var output_area in this.views) { | |
59 |
var views = this.views[ |
|
59 | var views = this.views[output_area]; | |
60 | for (var view_index in views) { |
|
60 | for (var view_index in views) { | |
61 | var view = views[view_index]; |
|
61 | var view = views[view_index]; | |
62 | if (view !== caller) { |
|
62 | if (view !== caller) { | |
@@ -123,7 +123,7 b' define(["components/underscore/underscore-min",' | |||||
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | var data = {sync_method: method, sync_data: send_json}; |
|
125 | var data = {sync_method: method, sync_data: send_json}; | |
126 |
var output_area = this. |
|
126 | var output_area = this.last_modified_view.output_area; | |
127 | var callbacks = this._make_callbacks(output_area); |
|
127 | var callbacks = this._make_callbacks(output_area); | |
128 | this.comm.send(data, callbacks); |
|
128 | this.comm.send(data, callbacks); | |
129 | this.pending_msgs++; |
|
129 | this.pending_msgs++; | |
@@ -143,14 +143,14 b' define(["components/underscore/underscore-min",' | |||||
143 | case 'display': |
|
143 | case 'display': | |
144 |
|
144 | |||
145 | // Try to get the cell index. |
|
145 | // Try to get the cell index. | |
146 |
var |
|
146 | var output_area = this._get_output_area(msg.parent_header.msg_id); | |
147 |
if ( |
|
147 | if (output_area == null) { | |
148 | console.log("Could not determine where the display" + |
|
148 | console.log("Could not determine where the display" + | |
149 | " message was from. Widget will not be displayed") |
|
149 | " message was from. Widget will not be displayed") | |
150 | } else { |
|
150 | } else { | |
151 | this.display_view(msg.content.data.view_name, |
|
151 | this.display_view(msg.content.data.view_name, | |
152 | msg.content.data.parent, |
|
152 | msg.content.data.parent, | |
153 |
|
|
153 | output_area); | |
154 | } |
|
154 | } | |
155 | break; |
|
155 | break; | |
156 | case 'update': |
|
156 | case 'update': | |
@@ -183,8 +183,8 b' define(["components/underscore/underscore-min",' | |||||
183 |
|
183 | |||
184 | // Handle when a widget is closed. |
|
184 | // Handle when a widget is closed. | |
185 | handle_comm_closed: function (msg) { |
|
185 | handle_comm_closed: function (msg) { | |
186 |
for (var |
|
186 | for (var output_area in this.views) { | |
187 |
var views = this.views[ |
|
187 | var views = this.views[output_area]; | |
188 | for (var view_index in views) { |
|
188 | for (var view_index in views) { | |
189 | var view = views[view_index]; |
|
189 | var view = views[view_index]; | |
190 | view.remove(); |
|
190 | view.remove(); | |
@@ -194,18 +194,18 b' define(["components/underscore/underscore-min",' | |||||
194 |
|
194 | |||
195 |
|
195 | |||
196 | // Create view that represents the model. |
|
196 | // Create view that represents the model. | |
197 |
display_view: function (view_name, parent_comm_id, |
|
197 | display_view: function (view_name, parent_comm_id, output_area) { | |
198 | var new_views = []; |
|
198 | var new_views = []; | |
199 |
|
199 | |||
200 | var displayed = false; |
|
200 | var displayed = false; | |
201 | if (parent_comm_id != undefined) { |
|
201 | if (parent_comm_id != undefined) { | |
202 | var parent_comm = this.comm_manager.comms[parent_comm_id]; |
|
202 | var parent_comm = this.comm_manager.comms[parent_comm_id]; | |
203 | var parent_model = parent_comm.model; |
|
203 | var parent_model = parent_comm.model; | |
204 |
var parent_views = parent_model.views[ |
|
204 | var parent_views = parent_model.views[output_area]; | |
205 | for (var parent_view_index in parent_views) { |
|
205 | for (var parent_view_index in parent_views) { | |
206 | var parent_view = parent_views[parent_view_index]; |
|
206 | var parent_view = parent_views[parent_view_index]; | |
207 | if (parent_view.display_child != undefined) { |
|
207 | if (parent_view.display_child != undefined) { | |
208 |
var view = this._create_view(view_name, |
|
208 | var view = this._create_view(view_name, output_area); | |
209 | new_views.push(view); |
|
209 | new_views.push(view); | |
210 | parent_view.display_child(view); |
|
210 | parent_view.display_child(view); | |
211 | displayed = true; |
|
211 | displayed = true; | |
@@ -216,10 +216,9 b' define(["components/underscore/underscore-min",' | |||||
216 | if (!displayed) { |
|
216 | if (!displayed) { | |
217 | // No parent view is defined or exists. Add the view's |
|
217 | // No parent view is defined or exists. Add the view's | |
218 | // element to cell's widget div. |
|
218 | // element to cell's widget div. | |
219 |
var view = this._create_view(view_name, |
|
219 | var view = this._create_view(view_name, output_area); | |
220 | new_views.push(view); |
|
220 | new_views.push(view); | |
221 | var cell = IPython.notebook.get_cell(cell_index); |
|
221 | output_area.element.find('.widget-area').find('.widget-subarea') | |
222 | cell.element.find('.widget-area').find('.widget-subarea') |
|
|||
223 | .append(view.$el) |
|
222 | .append(view.$el) | |
224 | .parent().show(); // Show the widget_area (parent of widget_subarea) |
|
223 | .parent().show(); // Show the widget_area (parent of widget_subarea) | |
225 |
|
224 | |||
@@ -233,25 +232,25 b' define(["components/underscore/underscore-min",' | |||||
233 |
|
232 | |||
234 |
|
233 | |||
235 | // Create a view |
|
234 | // Create a view | |
236 |
_create_view: function (view_name, |
|
235 | _create_view: function (view_name, output_area) { | |
237 | var view = new this.widget_view_types[view_name]({model: this}); |
|
236 | var view = new this.widget_view_types[view_name]({model: this}); | |
238 | view.render(); |
|
237 | view.render(); | |
239 |
if (this.views[ |
|
238 | if (this.views[output_area]==undefined) { | |
240 |
this.views[ |
|
239 | this.views[output_area] = [] | |
241 | } |
|
240 | } | |
242 |
this.views[ |
|
241 | this.views[output_area].push(view); | |
243 | view.cell_index = cell_index; |
|
242 | view.output_area = output_area; | |
244 |
|
243 | |||
245 | // Handle when the view element is remove from the page. |
|
244 | // Handle when the view element is remove from the page. | |
246 | var that = this; |
|
245 | var that = this; | |
247 | view.$el.on("remove", function(){ |
|
246 | view.$el.on("remove", function(){ | |
248 |
var index = that.views[ |
|
247 | var index = that.views[output_area].indexOf(view); | |
249 | if (index > -1) { |
|
248 | if (index > -1) { | |
250 |
that.views[ |
|
249 | that.views[output_area].splice(index, 1); | |
251 | } |
|
250 | } | |
252 | view.remove(); // Clean-up view |
|
251 | view.remove(); // Clean-up view | |
253 |
if (that.views[ |
|
252 | if (that.views[output_area].length()==0) { | |
254 |
delete that.views[ |
|
253 | delete that.views[output_area]; | |
255 | } |
|
254 | } | |
256 |
|
255 | |||
257 | // Close the comm if there are no views left. |
|
256 | // Close the comm if there are no views left. | |
@@ -275,12 +274,12 b' define(["components/underscore/underscore-min",' | |||||
275 | status : function(msg){ |
|
274 | status : function(msg){ | |
276 | that.handle_status(output_area, msg); |
|
275 | that.handle_status(output_area, msg); | |
277 | }, |
|
276 | }, | |
278 |
get_ |
|
277 | get_output_area : function() { | |
279 | if (that.last_modified_view != undefined && |
|
278 | if (that.last_modified_view != undefined && | |
280 |
that.last_modified_view. |
|
279 | that.last_modified_view.output_area != undefined) { | |
281 |
return that.last_modified_view. |
|
280 | return that.last_modified_view.output_area; | |
282 | } else { |
|
281 | } else { | |
283 |
return |
|
282 | return null | |
284 | } |
|
283 | } | |
285 | }, |
|
284 | }, | |
286 | }, |
|
285 | }, | |
@@ -291,41 +290,32 b' define(["components/underscore/underscore-min",' | |||||
291 |
|
290 | |||
292 |
|
291 | |||
293 | // Get the cell index corresponding to the msg_id. |
|
292 | // Get the cell index corresponding to the msg_id. | |
294 | _get_cell_index: function (msg_id) { |
|
293 | // output_area is a JQuery DOM element handle that has widget_area | |
|
294 | // and nested widget_subarea elements. | |||
|
295 | _get_output_area: function (msg_id) { | |||
295 |
|
296 | |||
296 | // First, guess cell.execute triggered |
|
297 | // First, guess cell.execute triggered | |
297 | var cells = IPython.notebook.get_cells(); |
|
298 | var cells = IPython.notebook.get_cells(); | |
298 | for (var cell_index in cells) { |
|
299 | for (var cell_index in cells) { | |
299 | if (cells[cell_index].last_msg_id == msg_id) { |
|
300 | if (cells[cell_index].last_msg_id == msg_id) { | |
300 |
r |
|
301 | var cell = IPython.notebook.get_cell(cell_index) | |
|
302 | return cell.output_area; | |||
301 | } |
|
303 | } | |
302 | } |
|
304 | } | |
303 |
|
305 | |||
304 | // Second, guess widget triggered |
|
306 | // Second, guess widget triggered | |
305 | var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id) |
|
307 | var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id) | |
306 |
if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_ |
|
308 | if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_output_area != undefined) { | |
307 |
var |
|
309 | var output_area = callbacks.iopub.get_output_area(); | |
308 |
if ( |
|
310 | if (output_area != null) { | |
309 |
return |
|
311 | return output_area; | |
310 | } |
|
312 | } | |
311 | } |
|
313 | } | |
312 |
|
314 | |||
313 | // Not triggered by a widget or a cell |
|
315 | // Not triggered by a widget or a cell | |
314 |
return |
|
316 | return null; | |
315 | }, |
|
317 | }, | |
316 |
|
318 | |||
317 |
|
||||
318 | // Get the cell output area corresponding to the view. |
|
|||
319 | _get_view_output_area: function (view) { |
|
|||
320 | return this._get_cell_output_area(view.cell_index); |
|
|||
321 | }, |
|
|||
322 |
|
||||
323 |
|
||||
324 | // Get the cell output area corresponding to the cell index. |
|
|||
325 | _get_cell_output_area: function (cell_index) { |
|
|||
326 | var cell = IPython.notebook.get_cell(cell_index) |
|
|||
327 | return cell.output_area; |
|
|||
328 | }, |
|
|||
329 | }); |
|
319 | }); | |
330 |
|
320 | |||
331 |
|
321 |
General Comments 0
You need to be logged in to leave comments.
Login now