Show More
@@ -1,63 +1,79 b'' | |||||
1 |
|
1 | |||
2 | //============================================================================ |
|
2 | //============================================================================ | |
3 | // Cell |
|
3 | // Cell | |
4 | //============================================================================ |
|
4 | //============================================================================ | |
5 |
|
5 | |||
6 | var IPython = (function (IPython) { |
|
6 | var IPython = (function (IPython) { | |
7 |
|
7 | |||
8 | var utils = IPython.utils; |
|
8 | var utils = IPython.utils; | |
9 |
|
9 | |||
10 | var Cell = function (notebook) { |
|
10 | var Cell = function (notebook) { | |
11 | this.notebook = notebook; |
|
11 | this.notebook = notebook; | |
12 | this.selected = false; |
|
12 | this.selected = false; | |
13 | this.element; |
|
13 | this.element; | |
14 | this.create_element(); |
|
14 | this.create_element(); | |
15 | if (this.element !== undefined) { |
|
15 | if (this.element !== undefined) { | |
16 | this.element.data("cell", this); |
|
16 | this.element.data("cell", this); | |
17 | this.bind_events(); |
|
17 | this.bind_events(); | |
18 | } |
|
18 | } | |
19 | this.cell_id = utils.uuid(); |
|
19 | this.cell_id = utils.uuid(); | |
20 | }; |
|
20 | }; | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | Cell.prototype.select = function () { |
|
23 | Cell.prototype.select = function () { | |
24 | this.element.addClass('ui-widget-content ui-corner-all'); |
|
24 | this.element.addClass('ui-widget-content ui-corner-all'); | |
25 | this.selected = true; |
|
25 | this.selected = true; | |
26 | // TODO: we need t test across browsers to see if both of these are needed. |
|
26 | // TODO: we need t test across browsers to see if both of these are needed. | |
27 | // In the meantime, there should not be any harm in having them both. |
|
27 | // In the meantime, there should not be any harm in having them both. | |
28 | this.element.find('textarea').trigger('focusin'); |
|
28 | this.element.find('textarea').trigger('focusin'); | |
29 | this.element.find('textarea').trigger('focus'); |
|
29 | this.element.find('textarea').trigger('focus'); | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | Cell.prototype.unselect = function () { |
|
33 | Cell.prototype.unselect = function () { | |
34 | this.element.removeClass('ui-widget-content ui-corner-all'); |
|
34 | this.element.removeClass('ui-widget-content ui-corner-all'); | |
35 | this.selected = false; |
|
35 | this.selected = false; | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | Cell.prototype.bind_events = function () { |
|
39 | Cell.prototype.bind_events = function () { | |
40 | var that = this; |
|
40 | var that = this; | |
41 | var nb = that.notebook |
|
41 | var nb = that.notebook | |
42 | that.element.click(function (event) { |
|
42 | that.element.click(function (event) { | |
43 | if (that.selected === false) { |
|
43 | if (that.selected === false) { | |
44 | nb.select(nb.find_cell_index(that)); |
|
44 | nb.select(nb.find_cell_index(that)); | |
45 | }; |
|
45 | }; | |
46 | }); |
|
46 | }); | |
47 | that.element.focusin(function (event) { |
|
47 | that.element.focusin(function (event) { | |
48 | if (that.selected === false) { |
|
48 | if (that.selected === false) { | |
49 | nb.select(nb.find_cell_index(that)); |
|
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 | // Subclasses must implement create_element. |
|
71 | // Subclasses must implement create_element. | |
56 | Cell.prototype.create_element = function () {}; |
|
72 | Cell.prototype.create_element = function () {}; | |
57 |
|
73 | |||
58 | IPython.Cell = Cell; |
|
74 | IPython.Cell = Cell; | |
59 |
|
75 | |||
60 | return IPython; |
|
76 | return IPython; | |
61 |
|
77 | |||
62 | }(IPython)); |
|
78 | }(IPython)); | |
63 |
|
79 |
General Comments 0
You need to be logged in to leave comments.
Login now