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