diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 4a87ba6..502df10 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -33,9 +33,9 @@ var IPython = (function (IPython) { */ var Cell = function (options) { - options = this.mergeopt(Cell, options) + options = this.mergeopt(Cell, options); // superclass default overwrite our default - + this.placeholder = options.placeholder || ''; this.read_only = options.cm_config.readOnly; this.selected = false; @@ -52,7 +52,7 @@ var IPython = (function (IPython) { // same order. Easiest is to create and set to null in parent class. this.element = null; - this.cell_type = null; + this.cell_type = this.cell_type || null; this.code_mirror = null; @@ -80,6 +80,7 @@ var IPython = (function (IPython) { } Cell.prototype.mergeopt = function(_class, options, overwrite){ + options = options || {}; overwrite = overwrite || {}; return $.extend(true, {}, _class.options_default, options, overwrite) @@ -200,6 +201,7 @@ var IPython = (function (IPython) { Cell.prototype.toJSON = function () { var data = {}; data.metadata = this.metadata; + data.cell_type = this.cell_type; return data; }; diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index 74186b1..e320212 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -37,37 +37,39 @@ var IPython = (function (IPython) { this.inner_element = $('
').addClass('celltoolbar') this.element = $('
').addClass('ctb_hideshow') .append(this.inner_element); + this.show(); }; // The default css style for the outer celltoolbar div - // (ctb_hideshow) is display: none. We add the ctb_show - // class to either 1) the body to show all cell's toolbars - // or 2) to the individual celltoolbar divs to show just one - // cell's toolbar. + // (ctb_hideshow) is display: none. + // To show the cell toolbar, *both* of the following conditions must be met: + // - A parent container has class `ctb_global_show` + // - The celltoolbar has the class `ctb_show` + // This allows global show/hide, as well as per-cell show/hide. CellToolbar.global_hide = function () { - $('body').removeClass('ctb_show'); - } + $('body').removeClass('ctb_global_show'); + }; CellToolbar.global_show = function () { - $('body').addClass('ctb_show'); - } + $('body').addClass('ctb_global_show'); + }; CellToolbar.prototype.hide = function () { this.element.removeClass('ctb_show'); - } + }; CellToolbar.prototype.show = function () { this.element.addClass('ctb_show'); - } + }; /** - * Class variable that should contain a dict of all availlable callback + * Class variable that should contain a dict of all available callback * we need to think of wether or not we allow nested namespace * @property _callback_dict * @private @@ -89,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 @@ -97,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. @@ -180,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}); }; @@ -217,11 +219,11 @@ var IPython = (function (IPython) { 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(); } - } + }; /** @@ -235,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); } - } + }; /** @@ -303,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 = $('