##// END OF EJS Templates
Adding Cell.grow back to fix bug....
Brian E. Granger -
Show More
@@ -1,63 +1,79 b''
1 1
2 2 //============================================================================
3 3 // Cell
4 4 //============================================================================
5 5
6 6 var IPython = (function (IPython) {
7 7
8 8 var utils = IPython.utils;
9 9
10 10 var Cell = function (notebook) {
11 11 this.notebook = notebook;
12 12 this.selected = false;
13 13 this.element;
14 14 this.create_element();
15 15 if (this.element !== undefined) {
16 16 this.element.data("cell", this);
17 17 this.bind_events();
18 18 }
19 19 this.cell_id = utils.uuid();
20 20 };
21 21
22 22
23 23 Cell.prototype.select = function () {
24 24 this.element.addClass('ui-widget-content ui-corner-all');
25 25 this.selected = true;
26 26 // TODO: we need t test across browsers to see if both of these are needed.
27 27 // In the meantime, there should not be any harm in having them both.
28 28 this.element.find('textarea').trigger('focusin');
29 29 this.element.find('textarea').trigger('focus');
30 30 };
31 31
32 32
33 33 Cell.prototype.unselect = function () {
34 34 this.element.removeClass('ui-widget-content ui-corner-all');
35 35 this.selected = false;
36 36 };
37 37
38 38
39 39 Cell.prototype.bind_events = function () {
40 40 var that = this;
41 41 var nb = that.notebook
42 42 that.element.click(function (event) {
43 43 if (that.selected === false) {
44 44 nb.select(nb.find_cell_index(that));
45 45 };
46 46 });
47 47 that.element.focusin(function (event) {
48 48 if (that.selected === false) {
49 49 nb.select(nb.find_cell_index(that));
50 50 };
51 51 });
52 52 };
53 53
54 Cell.prototype.grow = function(element) {
55 // Grow the cell by hand. This is used upon reloading from JSON, when the
56 // autogrow handler is not called.
57 var dom = element.get(0);
58 var lines_count = 0;
59 // modified split rule from
60 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
61 var lines = dom.value.split(/\r|\r\n|\n/);
62 lines_count = lines.length;
63 if (lines_count >= 1) {
64 dom.rows = lines_count;
65 } else {
66 dom.rows = 1;
67 }
68 };
69
54 70
55 71 // Subclasses must implement create_element.
56 72 Cell.prototype.create_element = function () {};
57 73
58 74 IPython.Cell = Cell;
59 75
60 76 return IPython;
61 77
62 78 }(IPython));
63 79
General Comments 0
You need to be logged in to leave comments. Login now