diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index 21ad9ac22..e32021219 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -91,7 +91,7 @@ var IPython = (function (IPython) { /** - * Class variable that should contains the CellToolbar instances for each + * Class variable that should contain the CellToolbar instances for each * cell of the notebook * * @private @@ -99,17 +99,17 @@ var IPython = (function (IPython) { * @static * @type List */ - CellToolbar._instances =[] + CellToolbar._instances = []; /** - * keep a list of all the availlabel presets for the toolbar + * keep a list of all the available presets for the toolbar * @private * @property _presets * @static * @type Dict */ - CellToolbar._presets ={} + CellToolbar._presets = {}; // this is by design not a prototype. @@ -182,7 +182,7 @@ var IPython = (function (IPython) { * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) */ CellToolbar.register_preset = function(name, preset_list) { - CellToolbar._presets[name] = preset_list + CellToolbar._presets[name] = preset_list; $([IPython.events]).trigger('preset_added.CellToolbar', {name: name}); }; @@ -216,14 +216,14 @@ var IPython = (function (IPython) { * * CellToolbar.activate_preset('foo.foo_preset1'); */ - CellToolbar.activate_preset= function(preset_name){ + CellToolbar.activate_preset = function(preset_name){ var preset = CellToolbar._presets[preset_name]; - if(preset != undefined){ + if(preset !== undefined){ CellToolbar._ui_controls_list = preset; CellToolbar.rebuild_all(); } - } + }; /** @@ -237,29 +237,37 @@ var IPython = (function (IPython) { for(var i in CellToolbar._instances){ CellToolbar._instances[i].rebuild(); } - } + }; /** - * Rebuild all the button on the toolbar to update it's state. + * Rebuild all the button on the toolbar to update its state. * @method rebuild */ CellToolbar.prototype.rebuild = function(){ // strip evrything from the div - // which is probabli metainner. + // which is probably inner_element // or this.element. this.inner_element.empty(); - var cdict = CellToolbar._callback_dict; + var callbacks = CellToolbar._callback_dict; var preset = CellToolbar._ui_controls_list; - // Yes we iterate on the class varaible, not the instance one. - for ( var index in CellToolbar._ui_controls_list){ + // Yes we iterate on the class variable, not the instance one. + for (var index in preset) { + var key = preset[index]; + var callback = callbacks[key]; + if (!callback) continue; + var local_div = $('
').addClass('button_container'); - // Note, - // do this the other way, wrap in try/catch and don't append if any errors. - this.inner_element.append(local_div) - cdict[preset[index]](local_div, this.cell) + try { + callback(local_div, this.cell, this); + } catch (e) { + console.log("Error in cell toolbar callback " + key, e); + continue; + } + // only append if callback succeeded. + this.inner_element.append(local_div); } - } + }; /** @@ -305,8 +313,8 @@ var IPython = (function (IPython) { * */ CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){ - return function(div, cell) { - var button_container = $(div) + return function(div, cell, celltoolbar) { + var button_container = $(div); var chkb = $('').attr('type', 'checkbox'); var lbl = $('