Show More
@@ -91,7 +91,7 b' var IPython = (function (IPython) {' | |||
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | /** |
|
94 |
* Class variable that should contain |
|
|
94 | * Class variable that should contain the CellToolbar instances for each | |
|
95 | 95 | * cell of the notebook |
|
96 | 96 | * |
|
97 | 97 | * @private |
@@ -99,17 +99,17 b' var IPython = (function (IPython) {' | |||
|
99 | 99 | * @static |
|
100 | 100 | * @type List |
|
101 | 101 | */ |
|
102 | CellToolbar._instances =[] | |
|
102 | CellToolbar._instances = []; | |
|
103 | 103 | |
|
104 | 104 | |
|
105 | 105 | /** |
|
106 |
* keep a list of all the avail |
|
|
106 | * keep a list of all the available presets for the toolbar | |
|
107 | 107 | * @private |
|
108 | 108 | * @property _presets |
|
109 | 109 | * @static |
|
110 | 110 | * @type Dict |
|
111 | 111 | */ |
|
112 | CellToolbar._presets ={} | |
|
112 | CellToolbar._presets = {}; | |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | // this is by design not a prototype. |
@@ -182,7 +182,7 b' var IPython = (function (IPython) {' | |||
|
182 | 182 | * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) |
|
183 | 183 | */ |
|
184 | 184 | CellToolbar.register_preset = function(name, preset_list) { |
|
185 | CellToolbar._presets[name] = preset_list | |
|
185 | CellToolbar._presets[name] = preset_list; | |
|
186 | 186 | $([IPython.events]).trigger('preset_added.CellToolbar', {name: name}); |
|
187 | 187 | }; |
|
188 | 188 | |
@@ -216,14 +216,14 b' var IPython = (function (IPython) {' | |||
|
216 | 216 | * |
|
217 | 217 | * CellToolbar.activate_preset('foo.foo_preset1'); |
|
218 | 218 | */ |
|
219 | CellToolbar.activate_preset= function(preset_name){ | |
|
219 | CellToolbar.activate_preset = function(preset_name){ | |
|
220 | 220 | var preset = CellToolbar._presets[preset_name]; |
|
221 | 221 | |
|
222 | if(preset != undefined){ | |
|
222 | if(preset !== undefined){ | |
|
223 | 223 | CellToolbar._ui_controls_list = preset; |
|
224 | 224 | CellToolbar.rebuild_all(); |
|
225 | 225 | } |
|
226 | } | |
|
226 | }; | |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | /** |
@@ -237,29 +237,37 b' var IPython = (function (IPython) {' | |||
|
237 | 237 | for(var i in CellToolbar._instances){ |
|
238 | 238 | CellToolbar._instances[i].rebuild(); |
|
239 | 239 | } |
|
240 | } | |
|
240 | }; | |
|
241 | 241 | |
|
242 | 242 | /** |
|
243 |
* Rebuild all the button on the toolbar to update it |
|
|
243 | * Rebuild all the button on the toolbar to update its state. | |
|
244 | 244 | * @method rebuild |
|
245 | 245 | */ |
|
246 | 246 | CellToolbar.prototype.rebuild = function(){ |
|
247 | 247 | // strip evrything from the div |
|
248 |
// which is probabl |
|
|
248 | // which is probably inner_element | |
|
249 | 249 | // or this.element. |
|
250 | 250 | this.inner_element.empty(); |
|
251 | 251 | |
|
252 |
var c |
|
|
252 | var callbacks = CellToolbar._callback_dict; | |
|
253 | 253 | var preset = CellToolbar._ui_controls_list; |
|
254 |
// Yes we iterate on the class var |
|
|
255 |
for ( |
|
|
254 | // Yes we iterate on the class variable, not the instance one. | |
|
255 | for (var index in preset) { | |
|
256 | var key = preset[index]; | |
|
257 | var callback = callbacks[key]; | |
|
258 | if (!callback) continue; | |
|
259 | ||
|
256 | 260 | var local_div = $('<div/>').addClass('button_container'); |
|
257 |
|
|
|
258 | // do this the other way, wrap in try/catch and don't append if any errors. | |
|
259 | this.inner_element.append(local_div) | |
|
260 | cdict[preset[index]](local_div, this.cell) | |
|
261 | try { | |
|
262 | callback(local_div, this.cell, this); | |
|
263 | } catch (e) { | |
|
264 | console.log("Error in cell toolbar callback " + key, e); | |
|
265 | continue; | |
|
266 | } | |
|
267 | // only append if callback succeeded. | |
|
268 | this.inner_element.append(local_div); | |
|
261 | 269 | } |
|
262 | } | |
|
270 | }; | |
|
263 | 271 | |
|
264 | 272 | |
|
265 | 273 | /** |
@@ -305,8 +313,8 b' var IPython = (function (IPython) {' | |||
|
305 | 313 | * |
|
306 | 314 | */ |
|
307 | 315 | CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){ |
|
308 |
|
|
|
309 | var button_container = $(div) | |
|
316 | return function(div, cell, celltoolbar) { | |
|
317 | var button_container = $(div); | |
|
310 | 318 | |
|
311 | 319 | var chkb = $('<input/>').attr('type', 'checkbox'); |
|
312 | 320 | var lbl = $('<label/>').append($('<span/>').text(name)); |
@@ -317,11 +325,10 b' var IPython = (function (IPython) {' | |||
|
317 | 325 | var v = getter(cell); |
|
318 | 326 | setter(cell, !v); |
|
319 | 327 | chkb.attr("checked", !v); |
|
320 |
|
|
|
321 | button_container.append($('<div/>').append(lbl)); | |
|
322 | ||
|
323 |
|
|
|
324 | } | |
|
328 | }); | |
|
329 | button_container.append($('<div/>').append(lbl)); | |
|
330 | }; | |
|
331 | }; | |
|
325 | 332 | |
|
326 | 333 | |
|
327 | 334 | /** |
@@ -367,16 +374,16 b' var IPython = (function (IPython) {' | |||
|
367 | 374 | * CellToolbar.register_callback('slideshow.select', select_type); |
|
368 | 375 | * |
|
369 | 376 | */ |
|
370 | CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label){ | |
|
371 |
label= label |
|
|
372 | return function(div, cell) { | |
|
373 | var button_container = $(div) | |
|
377 | CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label, cell_types){ | |
|
378 | label = label || ""; | |
|
379 | return function(div, cell, celltoolbar) { | |
|
380 | var button_container = $(div); | |
|
374 | 381 | var lbl = $("<label/>").append($('<span/>').text(label)); |
|
375 | 382 | var select = $('<select/>').addClass('ui-widget ui-widget-content'); |
|
376 | 383 | for(var itemn in list_list){ |
|
377 |
var opt = $('<option/>') |
|
|
378 |
|
|
|
379 |
|
|
|
384 | var opt = $('<option/>') | |
|
385 | .attr('value', list_list[itemn][1]) | |
|
386 | .text(list_list[itemn][0]); | |
|
380 | 387 | select.append(opt); |
|
381 | 388 | } |
|
382 | 389 | select.val(getter(cell)); |
@@ -384,8 +391,13 b' var IPython = (function (IPython) {' | |||
|
384 | 391 | setter(cell, select.val()); |
|
385 | 392 | }); |
|
386 | 393 | button_container.append($('<div/>').append(lbl).append(select)); |
|
394 | if (cell_types && cell_types.indexOf(cell.cell_type) == -1) { | |
|
395 | celltoolbar.hide(); | |
|
396 | } else { | |
|
397 | celltoolbar.show(); | |
|
398 | } | |
|
387 | 399 | |
|
388 | } | |
|
400 | }; | |
|
389 | 401 | }; |
|
390 | 402 | |
|
391 | 403 |
General Comments 0
You need to be logged in to leave comments.
Login now