diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index ec3daa0..4a87ba6 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -39,18 +39,28 @@ var IPython = (function (IPython) { this.placeholder = options.placeholder || ''; this.read_only = options.cm_config.readOnly; this.selected = false; - this.element = null; this.metadata = {}; // load this from metadata later ? this.user_highlight = 'auto'; this.cm_config = options.cm_config; + this.cell_id = utils.uuid(); + this._options = options; + + // For JS VM engines optimisation, attributes should be all set (even + // to null) in the constructor, and if possible, if different subclass + // have new attributes with same name, they should be created in the + // same order. Easiest is to create and set to null in parent class. + + this.element = null; + this.cell_type = null; + this.code_mirror = null; + + this.create_element(); if (this.element !== null) { this.element.data("cell", this); this.bind_events(); } - this.cell_id = utils.uuid(); - this._options = options; }; Cell.options_default = { @@ -295,6 +305,7 @@ var IPython = (function (IPython) { this.code_mirror.setOption('mode', mode); return; } + var current_mode = this.code_mirror.getOption('mode', mode); var first_line = this.code_mirror.getLine(0); // loop on every pairs for( var mode in modes) { @@ -303,6 +314,9 @@ var IPython = (function (IPython) { for(var reg in regs ) { // here we handle non magic_modes if(first_line.match(regs[reg]) != null) { + if(current_mode == mode){ + return; + } if (mode.search('magic_') != 0) { this.code_mirror.setOption('mode', mode); CodeMirror.autoLoadMode(this.code_mirror, mode); @@ -312,6 +326,9 @@ var IPython = (function (IPython) { var close = modes[mode]['close']|| "%%end"; var mmode = mode; mode = mmode.substr(6); + if(current_mode == mode){ + return; + } CodeMirror.autoLoadMode(this.code_mirror, mode); // create on the fly a mode that swhitch between // plain/text and smth else otherwise `%%` is @@ -339,6 +356,9 @@ var IPython = (function (IPython) { } catch(e) { default_mode = 'text/plain'; } + if( current_mode === default_mode){ + return + } this.code_mirror.setOption('mode', default_mode); }; diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index ea00928..9b32496 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -62,11 +62,17 @@ var IPython = (function (IPython) { */ var CodeCell = function (kernel, options) { this.kernel = kernel || null; - this.code_mirror = null; - this.input_prompt_number = null; this.collapsed = false; this.cell_type = "code"; + // create all attributed in constructor function + // even if null for V8 VM optimisation + this.input_prompt_number = null; + this.celltoolbar = null; + this.output_area = null; + this.last_msg_id = null; + this.completer = null; + var cm_overwrite_options = { onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) @@ -129,13 +135,7 @@ var IPython = (function (IPython) { cell.append(input).append(output); this.element = cell; this.output_area = new IPython.OutputArea(output, true); - - // construct a completer only if class exist - // otherwise no print view - if (IPython.Completer !== undefined) - { - this.completer = new IPython.Completer(this); - } + this.completer = new IPython.Completer(this); }; /** @@ -202,8 +202,10 @@ var IPython = (function (IPython) { return true; } else if (event.keyCode === key.TAB && event.type == 'keydown') { // Tab completion. - //Do not trim here because of tooltip - if (editor.somethingSelected()) { return false; } + IPython.tooltip.remove_and_cancel_tooltip(); + if (editor.somethingSelected()) { + return false; + } var pre_cursor = editor.getRange({line:cur.line,ch:0},cur); if (pre_cursor.trim() === "") { // Don't autocomplete if the part of the line before the cursor @@ -443,7 +445,8 @@ var IPython = (function (IPython) { var data = IPython.Cell.prototype.toJSON.apply(this); data.input = this.get_text(); data.cell_type = 'code'; - if (this.input_prompt_number) { + // is finite protect against undefined and '*' value + if (isFinite(this.input_prompt_number)) { data.prompt_number = this.input_prompt_number; } var outputs = this.output_area.toJSON(); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index ac10cef..67a27a7 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1588,7 +1588,7 @@ var IPython = (function (IPython) { cell_data.cell_type = 'raw'; } - new_cell = this.insert_cell_below(cell_data.cell_type); + new_cell = this.insert_cell_at_bottom(cell_data.cell_type); new_cell.fromJSON(cell_data); }; }; diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 12f219f..912e2ba 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -576,12 +576,13 @@ var IPython = (function (IPython) { OutputArea.prototype.append_png = function (png, md, element) { var toinsert = this.create_output_subarea(md, "output_png"); - var img = $("").attr('src','data:image/png;base64,'+png); + var img = $(""); + img[0].setAttribute('src','data:image/png;base64,'+png); if (md['height']) { - img.attr('height', md['height']); + img[0].setAttribute('height', md['height']); } if (md['width']) { - img.attr('width', md['width']); + img[0].setAttribute('width', md['width']); } this._dblclick_to_reset_size(img); toinsert.append(img);