Show More
@@ -19,8 +19,10 b'' | |||
|
19 | 19 | // require(['components/underscore/underscore-min.js', |
|
20 | 20 | // 'components/backbone/backbone-min.js'], |
|
21 | 21 | |
|
22 | var IPython = (function (IPython) { | |
|
23 | "use strict"; | |
|
22 | "use strict"; | |
|
23 | ||
|
24 | // Only run once on a notebook. | |
|
25 | if (IPython.notebook.widget_manager == undefined) { | |
|
24 | 26 | |
|
25 | 27 | //----------------------------------------------------------------------- |
|
26 | 28 | // WidgetModel class |
@@ -120,21 +122,21 b' var IPython = (function (IPython) {' | |||
|
120 | 122 | |
|
121 | 123 | // Create the corresponding widget model. |
|
122 | 124 | var widget_model = new this.widget_model_types[widget_type_name]; |
|
123 | ||
|
125 | ||
|
124 | 126 | // Remember comm associated with the model. |
|
125 | 127 | widget_model.comm = comm; |
|
126 | 128 | comm.model = widget_model; |
|
127 | ||
|
129 | ||
|
128 | 130 | // Create an array to remember the views associated with the model. |
|
129 | 131 | widget_model.views = []; |
|
130 | ||
|
132 | ||
|
131 | 133 | // Add a handle to delete the control when the comm is closed. |
|
132 | 134 | var that = this; |
|
133 | 135 | var handle_close = function(msg) { |
|
134 | 136 | that.handle_comm_closed(comm, msg); |
|
135 | 137 | } |
|
136 | 138 | comm.on_close(handle_close); |
|
137 | ||
|
139 | ||
|
138 | 140 | // Handle incomming messages. |
|
139 | 141 | var handle_msg = function(msg) { |
|
140 | 142 | that.handle_comm_msg(comm, msg); |
@@ -147,11 +149,26 b' var IPython = (function (IPython) {' | |||
|
147 | 149 | var widget_view = new this.widget_view_types[widget_view_name]({model: widget_model}); |
|
148 | 150 | widget_view.render(); |
|
149 | 151 | widget_model.views.push(widget_view); |
|
150 | ||
|
152 | ||
|
153 | // Handle when the view element is remove from the page. | |
|
154 | widget_view.$el.on("remove", function(){ | |
|
155 | var index = widget_model.views.indexOf(widget_view); | |
|
156 | if (index > -1) { | |
|
157 | widget_model.views.splice(index, 1); | |
|
158 | } | |
|
159 | widget_view.remove(); // Clean-up view | |
|
160 | ||
|
161 | // Close the comm if there are no views left. | |
|
162 | if (widget_model.views.length()==0) { | |
|
163 | widget_model.comm.close(); | |
|
164 | } | |
|
165 | }); | |
|
166 | ||
|
151 | 167 | // Add the view's element to cell's widget div. |
|
152 | 168 | widget_area |
|
153 |
.append($("<div />").append(widget_view.$el)) |
|
|
154 | ||
|
169 | .append($("<div />").append(widget_view.$el)) | |
|
170 | .parent().show(); // Show the widget_area (parent of widget_subarea) | |
|
171 | ||
|
155 | 172 | // Update the view based on the model contents. |
|
156 | 173 | widget_view.refresh(); |
|
157 | 174 | } |
@@ -162,18 +179,18 b' var IPython = (function (IPython) {' | |||
|
162 | 179 | var method = msg.content.data.method; |
|
163 | 180 | switch (method){ |
|
164 | 181 | case 'show': |
|
165 | ||
|
182 | ||
|
166 | 183 | // TODO: Get cell from registered output handler. |
|
167 | 184 | var cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1); |
|
168 | 185 | var widget_subarea = cell.element.find('.widget_area').find('.widget_subarea'); |
|
169 | ||
|
186 | ||
|
170 | 187 | if (msg.content.data.parent != undefined) { |
|
171 | 188 | var find_results = widget_subarea.find("." + msg.content.data.parent); |
|
172 | 189 | if (find_results.length > 0) { |
|
173 | 190 | widget_subarea = find_results; |
|
174 | 191 | } |
|
175 | 192 | } |
|
176 | ||
|
193 | ||
|
177 | 194 | this.show_view(widget_subarea, comm.model, msg.content.data.view_name); |
|
178 | 195 | break; |
|
179 | 196 | case 'update': |
@@ -235,7 +252,6 b' var IPython = (function (IPython) {' | |||
|
235 | 252 | IPython.WidgetModel = WidgetModel; |
|
236 | 253 | IPython.WidgetView = WidgetView; |
|
237 | 254 | |
|
238 | ||
|
239 | return IPython; | |
|
255 | IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager); | |
|
240 | 256 | |
|
241 | }(IPython)); | |
|
257 | } |
General Comments 0
You need to be logged in to leave comments.
Login now