diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js index 3bf37a4..95084c2 100644 --- a/IPython/frontend/html/notebook/static/js/cell.js +++ b/IPython/frontend/html/notebook/static/js/cell.js @@ -3,70 +3,78 @@ // Cell //============================================================================ +var IPython = (function (IPython) { -var Cell = function (notebook) { - this.notebook = notebook; - this.selected = false; - this.element; - this.create_element(); - if (this.element !== undefined) { - this.element.data("cell", this); - this.bind_events(); - } - this.cell_id = uuid(); -}; - - -Cell.prototype.grow = function(element) { - // Grow the cell by hand. This is used upon reloading from JSON, when the - // autogrow handler is not called. - var dom = element.get(0); - var lines_count = 0; - // modified split rule from - // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424 - var lines = dom.value.split(/\r|\r\n|\n/); - lines_count = lines.length; - if (lines_count >= 1) { - dom.rows = lines_count; - } else { - dom.rows = 1; - } -}; - - -Cell.prototype.select = function () { - this.element.addClass('ui-widget-content ui-corner-all'); - this.selected = true; - // TODO: we need t test across browsers to see if both of these are needed. - // In the meantime, there should not be any harm in having them both. - this.element.find('textarea').trigger('focusin'); - this.element.find('textarea').trigger('focus'); -}; - - -Cell.prototype.unselect = function () { - this.element.removeClass('ui-widget-content ui-corner-all'); - this.selected = false; -}; - - -Cell.prototype.bind_events = function () { - var that = this; - var nb = that.notebook - that.element.click(function (event) { - if (that.selected === false) { - nb.select(nb.find_cell_index(that)); - }; - }); - that.element.focusin(function (event) { - if (that.selected === false) { - nb.select(nb.find_cell_index(that)); - }; - }); -}; - - -// Subclasses must implement create_element. -Cell.prototype.create_element = function () {}; + var utils = IPython.utils; + var Cell = function (notebook) { + this.notebook = notebook; + this.selected = false; + this.element; + this.create_element(); + if (this.element !== undefined) { + this.element.data("cell", this); + this.bind_events(); + } + this.cell_id = utils.uuid(); + }; + + + Cell.prototype.grow = function(element) { + // Grow the cell by hand. This is used upon reloading from JSON, when the + // autogrow handler is not called. + var dom = element.get(0); + var lines_count = 0; + // modified split rule from + // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424 + var lines = dom.value.split(/\r|\r\n|\n/); + lines_count = lines.length; + if (lines_count >= 1) { + dom.rows = lines_count; + } else { + dom.rows = 1; + } + }; + + + Cell.prototype.select = function () { + this.element.addClass('ui-widget-content ui-corner-all'); + this.selected = true; + // TODO: we need t test across browsers to see if both of these are needed. + // In the meantime, there should not be any harm in having them both. + this.element.find('textarea').trigger('focusin'); + this.element.find('textarea').trigger('focus'); + }; + + + Cell.prototype.unselect = function () { + this.element.removeClass('ui-widget-content ui-corner-all'); + this.selected = false; + }; + + + Cell.prototype.bind_events = function () { + var that = this; + var nb = that.notebook + that.element.click(function (event) { + if (that.selected === false) { + nb.select(nb.find_cell_index(that)); + }; + }); + that.element.focusin(function (event) { + if (that.selected === false) { + nb.select(nb.find_cell_index(that)); + }; + }); + }; + + + // Subclasses must implement create_element. + Cell.prototype.create_element = function () {}; + + IPython.Cell = Cell; + + return IPython; + +}(IPython)); diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index aba9477..348a43a 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -3,193 +3,199 @@ // CodeCell //============================================================================ +var IPython = (function (IPython) { -var CodeCell = function (notebook) { - this.code_mirror = null; - this.input_prompt_number = ' '; - Cell.apply(this, arguments); -}; - - -CodeCell.prototype = new Cell(); - - -CodeCell.prototype.create_element = function () { - var cell = $('
').addClass('cell code_cell vbox border-box-sizing'); - var input = $('').addClass('input hbox border-box-sizing'); - input.append($('').addClass('prompt input_prompt monospace-font')); - var input_area = $('').addClass('input_area box-flex1 border-box-sizing'); - this.code_mirror = CodeMirror(input_area.get(0), { - indentUnit : 4, - enterMode : 'flat', - tabMode: 'shift' - }); - input.append(input_area); - var output = $('').addClass('output vbox border-box-sizing'); - cell.append(input).append(output); - this.element = cell; - this.collapse() -}; - - -CodeCell.prototype.select = function () { - Cell.prototype.select.apply(this); - this.code_mirror.focus(); -}; - - -CodeCell.prototype.append_pyout = function (data, n) { - var toinsert = $("").addClass("output_area output_pyout hbox monospace-font"); - toinsert.append($(''). - addClass('prompt output_prompt'). - html('Out[' + n + ']:') - ); - this.append_display_data(data, toinsert); - toinsert.children().last().addClass("box_flex1"); - this.element.find("div.output").append(toinsert); - // If we just output latex, typeset it. - if (data["text/latex"] !== undefined) { - MathJax.Hub.Queue(["Typeset",MathJax.Hub]); - }; -}; - - -CodeCell.prototype.append_pyerr = function (ename, evalue, tb) { - var s = ''; - var len = tb.length; - for (var i=0; i