##// END OF EJS Templates
New HTMl cell working with CodeMirror editing.
Brian E. Granger -
Show More
@@ -201,11 +201,11 b' div.output_html {'
201 div.output_png {
201 div.output_png {
202 }
202 }
203
203
204 div.text_cell {
204 div.html_cell {
205 background-color: white;
205 background-color: white;
206 }
206 }
207
207
208 textarea.text_cell_input {
208 textarea.html_cell_input {
209 /* Slightly bigger than the rest of the notebook */
209 /* Slightly bigger than the rest of the notebook */
210 font-size: 116%;
210 font-size: 116%;
211 font-family: monospace;
211 font-family: monospace;
@@ -218,7 +218,7 b' textarea.text_cell_input {'
218 color: black;
218 color: black;
219 }
219 }
220
220
221 div.text_cell_render {
221 div.html_cell_render {
222 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
222 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
223 /* Slightly bigger than the rest of the notebook */
223 /* Slightly bigger than the rest of the notebook */
224 font-size: 116%;
224 font-size: 116%;
@@ -230,25 +230,25 b' div.text_cell_render {'
230 color: black;
230 color: black;
231 }
231 }
232
232
233 div.text_cell_render em {font-style: italic;}
233 div.html_cell_render em {font-style: italic;}
234 div.text_cell_render strong {font-weight: bold;}
234 div.html_cell_render strong {font-weight: bold;}
235 div.text_cell_render u {text-decoration: underline;}
235 div.html_cell_render u {text-decoration: underline;}
236 div.text_cell_render :link { text-decoration: underline }
236 div.html_cell_render :link { text-decoration: underline }
237 div.text_cell_render :visited { text-decoration: underline }
237 div.html_cell_render :visited { text-decoration: underline }
238 div.text_cell_render h1 {font-size: 197%; margin: .67em 0; font-weight: bold;}
238 div.html_cell_render h1 {font-size: 197%; margin: .67em 0; font-weight: bold;}
239 div.text_cell_render h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;}
239 div.html_cell_render h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;}
240 div.text_cell_render h3 {font-size: 116%; margin: .83em 0; font-weight: bold;}
240 div.html_cell_render h3 {font-size: 116%; margin: .83em 0; font-weight: bold;}
241 div.text_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
241 div.html_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
242 div.text_cell_render h5 {font-size: 85%.; margin: 1.5em 0; font-weight: bold;}
242 div.html_cell_render h5 {font-size: 85%.; margin: 1.5em 0; font-weight: bold;}
243 div.text_cell_render h6 {font-size: 77%; margin: 1.67em 0; font-weight: bold;}
243 div.html_cell_render h6 {font-size: 77%; margin: 1.67em 0; font-weight: bold;}
244 div.text_cell_render ul {list-style:disc; margin-left: 40px;}
244 div.html_cell_render ul {list-style:disc; margin-left: 40px;}
245 div.text_cell_render ul ul {list-style:square; margin-left: 40px;}
245 div.html_cell_render ul ul {list-style:square; margin-left: 40px;}
246 div.text_cell_render ul ul ul {list-style:circle; margin-left: 40px;}
246 div.html_cell_render ul ul ul {list-style:circle; margin-left: 40px;}
247 div.text_cell_render ol {list-style:upper-roman; margin-left: 40px;}
247 div.html_cell_render ol {list-style:upper-roman; margin-left: 40px;}
248 div.text_cell_render ol ol {list-style:upper-alpha;}
248 div.html_cell_render ol ol {list-style:upper-alpha;}
249 div.text_cell_render ol ol ol {list-style:decimal;}
249 div.html_cell_render ol ol ol {list-style:decimal;}
250 div.text_cell_render ol ol ol ol {list-style:lower-alpha;}
250 div.html_cell_render ol ol ol ol {list-style:lower-alpha;}
251 div.text_cell_render ol ol ol ol ol {list-style:lower-roman;}
251 div.html_cell_render ol ol ol ol ol {list-style:lower-roman;}
252
252
253
253
254 .CodeMirror {
254 .CodeMirror {
@@ -1,37 +1,38 b''
1
1
2 //============================================================================
2 //============================================================================
3 // TextCell
3 // HTMLCell
4 //============================================================================
4 //============================================================================
5
5
6 var IPython = (function (IPython) {
6 var IPython = (function (IPython) {
7
7
8 var TextCell = function (notebook) {
8 var HTMLCell = function (notebook) {
9 IPython.Cell.apply(this, arguments);
9 IPython.Cell.apply(this, arguments);
10 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"
10 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"
11 this.rendered = false;
11 this.rendered = false;
12 };
12 };
13
13
14
14
15 TextCell.prototype = new IPython.Cell();
15 HTMLCell.prototype = new IPython.Cell();
16
16
17
17
18 TextCell.prototype.create_element = function () {
18
19 var cell = $("<div>").addClass('cell text_cell border-box-sizing').
19 HTMLCell.prototype.create_element = function () {
20 append(
20 var cell = $("<div>").addClass('cell html_cell border-box-sizing');
21 $("<textarea>" + this.placeholder + "</textarea>").
21 var input_area = $('<div/>').addClass('html_cell_input');
22 addClass('text_cell_input').
22 this.code_mirror = CodeMirror(input_area.get(0), {
23 attr('rows',1).
23 indentUnit : 4,
24 attr('cols',80).
24 enterMode : 'flat',
25 autogrow()
25 tabMode: 'shift',
26 ).append(
26 value: this.placeholder
27 // The tabindex=-1 makes this div focusable.
27 });
28 $('<div></div>').addClass('text_cell_render').attr('tabindex','-1')
28 // The tabindex=-1 makes this div focusable.
29 )
29 var render_area = $('<div/>').addClass('html_cell_render').attr('tabindex','-1');
30 cell.append(input_area).append(render_area);
30 this.element = cell;
31 this.element = cell;
31 };
32 };
32
33
33
34
34 TextCell.prototype.bind_events = function () {
35 HTMLCell.prototype.bind_events = function () {
35 IPython.Cell.prototype.bind_events.apply(this);
36 IPython.Cell.prototype.bind_events.apply(this);
36 var that = this;
37 var that = this;
37 this.element.keydown(function (event) {
38 this.element.keydown(function (event) {
@@ -45,71 +46,71 b' var IPython = (function (IPython) {'
45 };
46 };
46
47
47
48
48 TextCell.prototype.select = function () {
49 HTMLCell.prototype.select = function () {
49 IPython.Cell.prototype.select.apply(this);
50 IPython.Cell.prototype.select.apply(this);
50 var output = this.element.find("div.text_cell_render");
51 var output = this.element.find("div.html_cell_render");
51 output.trigger('focus');
52 output.trigger('focus');
52 };
53 };
53
54
54
55
55 TextCell.prototype.edit = function () {
56 HTMLCell.prototype.edit = function () {
56 if (this.rendered === true) {
57 if (this.rendered === true) {
57 var text_cell = this.element;
58 var html_cell = this.element;
58 var input = text_cell.find("textarea.text_cell_input");
59 var output = html_cell.find("div.html_cell_render");
59 var output = text_cell.find("div.text_cell_render");
60 output.hide();
60 output.hide();
61 input.show().trigger('focus');
61 html_cell.find('div.html_cell_input').show();
62 this.code_mirror.focus();
63 this.code_mirror.refresh();
62 this.rendered = false;
64 this.rendered = false;
63 };
65 };
64 };
66 };
65
67
66
68
67 TextCell.prototype.render = function () {
69 HTMLCell.prototype.render = function () {
68 if (this.rendered === false) {
70 if (this.rendered === false) {
69 var text_cell = this.element;
71 var html_cell = this.element;
70 var input = text_cell.find("textarea.text_cell_input");
72 var output = html_cell.find("div.html_cell_render");
71 var output = text_cell.find("div.text_cell_render");
73 var text = this.get_source();
72 var text = input.val();
74 if (text === "") {text = this.placeholder;};
73 if (text === "") {
75 this.set_render(text);
74 text = this.placeholder;
75 input.val(text);
76 };
77 output.html(text)
78 input.html(text);
79 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
76 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
80 input.hide();
77 html_cell.find('div.html_cell_input').hide();
81 output.show();
78 output.show();
82 this.rendered = true;
79 this.rendered = true;
83 };
80 };
84 };
81 };
85
82
86
83
87 TextCell.prototype.config_mathjax = function () {
84 HTMLCell.prototype.config_mathjax = function () {
88 var text_cell = this.element;
85 var html_cell = this.element;
89 var that = this;
86 var that = this;
90 text_cell.click(function () {
87 html_cell.click(function () {
91 that.edit();
88 that.edit();
92 }).focusout(function () {
89 }).focusout(function () {
93 that.render();
90 that.render();
94 });
91 });
95
92
96 text_cell.trigger("focusout");
93 html_cell.trigger("focusout");
94 };
95
96
97 HTMLCell.prototype.get_source = function() {
98 return this.code_mirror.getValue();
97 };
99 };
98
100
99
101
100 TextCell.prototype.get_text = function() {
102 HTMLCell.prototype.set_source = function(text) {
101 return this.element.find("textarea.text_cell_input").val();
103 this.code_mirror.setValue(text);
104 this.code_mirror.refresh();
102 };
105 };
103
106
104
107
105 TextCell.prototype.set_text = function(text) {
108 HTMLCell.prototype.set_render = function(text) {
106 this.element.find("textarea.text_cell_input").val(text);
109 this.element.find('div.html_cell_render').html(text);
107 this.element.find("textarea.text_cell_input").html(text);
108 this.element.find("div.text_cell_render").html(text);
109 };
110 };
110
111
111
112
112 TextCell.prototype.at_top = function () {
113 HTMLCell.prototype.at_top = function () {
113 if (this.rendered) {
114 if (this.rendered) {
114 return true;
115 return true;
115 } else {
116 } else {
@@ -118,7 +119,7 b' var IPython = (function (IPython) {'
118 };
119 };
119
120
120
121
121 TextCell.prototype.at_bottom = function () {
122 HTMLCell.prototype.at_bottom = function () {
122 if (this.rendered) {
123 if (this.rendered) {
123 return true;
124 return true;
124 } else {
125 } else {
@@ -127,24 +128,24 b' var IPython = (function (IPython) {'
127 };
128 };
128
129
129
130
130 TextCell.prototype.fromJSON = function (data) {
131 HTMLCell.prototype.fromJSON = function (data) {
131 if (data.cell_type === 'text') {
132 if (data.cell_type === 'html') {
132 if (data.text !== undefined) {
133 if (data.source !== undefined) {
133 this.set_text(data.text);
134 this.set_source(data.source);
134 this.grow(this.element.find("textarea.text_cell_input"));
135 this.set_render(data.source);
135 };
136 };
136 };
137 };
137 }
138 }
138
139
139
140
140 TextCell.prototype.toJSON = function () {
141 HTMLCell.prototype.toJSON = function () {
141 var data = {}
142 var data = {}
142 data.cell_type = 'text';
143 data.cell_type = 'html';
143 data.text = this.get_text();
144 data.source = this.get_source();
144 return data;
145 return data;
145 };
146 };
146
147
147 IPython.TextCell = TextCell;
148 IPython.HTMLCell = HTMLCell;
148
149
149 return IPython;
150 return IPython;
150
151
@@ -320,10 +320,10 b' var IPython = (function (IPython) {'
320 }
320 }
321
321
322
322
323 Notebook.prototype.insert_text_cell_before = function (index) {
323 Notebook.prototype.insert_html_cell_before = function (index) {
324 // TODO: Bounds check for i
324 // TODO: Bounds check for i
325 var i = this.index_or_selected(index);
325 var i = this.index_or_selected(index);
326 var cell = new IPython.TextCell(this);
326 var cell = new IPython.HTMLCell(this);
327 cell.config_mathjax();
327 cell.config_mathjax();
328 this.insert_cell_before(cell, i);
328 this.insert_cell_before(cell, i);
329 this.select(this.find_cell_index(cell));
329 this.select(this.find_cell_index(cell));
@@ -331,10 +331,10 b' var IPython = (function (IPython) {'
331 }
331 }
332
332
333
333
334 Notebook.prototype.insert_text_cell_after = function (index) {
334 Notebook.prototype.insert_html_cell_after = function (index) {
335 // TODO: Bounds check for i
335 // TODO: Bounds check for i
336 var i = this.index_or_selected(index);
336 var i = this.index_or_selected(index);
337 var cell = new IPython.TextCell(this);
337 var cell = new IPython.HTMLCell(this);
338 cell.config_mathjax();
338 cell.config_mathjax();
339 this.insert_cell_after(cell, i);
339 this.insert_cell_after(cell, i);
340 this.select(this.find_cell_index(cell));
340 this.select(this.find_cell_index(cell));
@@ -342,31 +342,32 b' var IPython = (function (IPython) {'
342 }
342 }
343
343
344
344
345 Notebook.prototype.text_to_code = function (index) {
345 Notebook.prototype.html_to_code = function (index) {
346 // TODO: Bounds check for i
346 // TODO: Bounds check for i
347 var i = this.index_or_selected(index);
347 var i = this.index_or_selected(index);
348 var source_element = this.cell_elements().eq(i);
348 var source_element = this.cell_elements().eq(i);
349 var source_cell = source_element.data("cell");
349 var source_cell = source_element.data("cell");
350 if (source_cell instanceof IPython.TextCell) {
350 if (source_cell instanceof IPython.HTMLCell) {
351 this.insert_code_cell_after(i);
351 this.insert_code_cell_after(i);
352 var target_cell = this.cells()[i+1];
352 var target_cell = this.cells()[i+1];
353 target_cell.set_code(source_cell.get_text());
353 target_cell.set_code(source_cell.get_source());
354 source_element.remove();
354 source_element.remove();
355 };
355 };
356 };
356 };
357
357
358
358
359 Notebook.prototype.code_to_text = function (index) {
359 Notebook.prototype.code_to_html = function (index) {
360 // TODO: Bounds check for i
360 // TODO: Bounds check for i
361 var i = this.index_or_selected(index);
361 var i = this.index_or_selected(index);
362 var source_element = this.cell_elements().eq(i);
362 var source_element = this.cell_elements().eq(i);
363 var source_cell = source_element.data("cell");
363 var source_cell = source_element.data("cell");
364 if (source_cell instanceof IPython.CodeCell) {
364 if (source_cell instanceof IPython.CodeCell) {
365 this.insert_text_cell_after(i);
365 this.insert_html_cell_after(i);
366 var target_cell = this.cells()[i+1];
366 var target_cell = this.cells()[i+1];
367 var text = source_cell.get_code();
367 var text = source_cell.get_code();
368 if (text === "") {text = target_cell.placeholder;};
368 if (text === "") {text = target_cell.placeholder;};
369 target_cell.set_text(text);
369 target_cell.set_source(text);
370 target_cell.set_render(text);
370 source_element.remove();
371 source_element.remove();
371 target_cell.edit();
372 target_cell.edit();
372 };
373 };
@@ -508,7 +509,7 b' var IPython = (function (IPython) {'
508 var code = cell.get_code();
509 var code = cell.get_code();
509 var msg_id = that.kernel.execute(cell.get_code());
510 var msg_id = that.kernel.execute(cell.get_code());
510 that.msg_cell_map[msg_id] = cell.cell_id;
511 that.msg_cell_map[msg_id] = cell.cell_id;
511 } else if (cell instanceof IPython.TextCell) {
512 } else if (cell instanceof IPython.HTMLCell) {
512 cell.render();
513 cell.render();
513 }
514 }
514 if (default_options.terminal) {
515 if (default_options.terminal) {
@@ -561,8 +562,8 b' var IPython = (function (IPython) {'
561 if (cell_data.cell_type == 'code') {
562 if (cell_data.cell_type == 'code') {
562 new_cell = this.insert_code_cell_after();
563 new_cell = this.insert_code_cell_after();
563 new_cell.fromJSON(cell_data);
564 new_cell.fromJSON(cell_data);
564 } else if (cell_data.cell_type === 'text') {
565 } else if (cell_data.cell_type === 'html') {
565 new_cell = this.insert_text_cell_after();
566 new_cell = this.insert_html_cell_after();
566 new_cell.fromJSON(cell_data);
567 new_cell.fromJSON(cell_data);
567 };
568 };
568 };
569 };
@@ -153,10 +153,10 b' var IPython = (function (IPython) {'
153 IPython.notebook.move_cell_down();
153 IPython.notebook.move_cell_down();
154 });
154 });
155 this.content.find('#to_code').click(function () {
155 this.content.find('#to_code').click(function () {
156 IPython.notebook.text_to_code();
156 IPython.notebook.html_to_code();
157 });
157 });
158 this.content.find('#to_text').click(function () {
158 this.content.find('#to_html').click(function () {
159 IPython.notebook.code_to_text();
159 IPython.notebook.code_to_html();
160 });
160 });
161 this.content.find('#run_selected_cell').click(function () {
161 this.content.find('#run_selected_cell').click(function () {
162 IPython.notebook.execute_selected_cell();
162 IPython.notebook.execute_selected_cell();
@@ -96,7 +96,7 b''
96 <div class="section_row">
96 <div class="section_row">
97 <span id="cell_type" class="section_row_buttons">
97 <span id="cell_type" class="section_row_buttons">
98 <button id="to_code">Code</button>
98 <button id="to_code">Code</button>
99 <button id="to_text">Text</button>
99 <button id="to_html">HTML</button>
100 </span>
100 </span>
101 <span class="button_label">Cell Type</span>
101 <span class="button_label">Cell Type</span>
102 </div>
102 </div>
@@ -174,7 +174,7 b''
174 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
174 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
175 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
175 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
176 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
176 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
177 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
177 <script src="static/js/htmlcell.js" type="text/javascript" charset="utf-8"></script>
178 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
178 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
179 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
179 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
180 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
180 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
General Comments 0
You need to be logged in to leave comments. Login now