##// END OF EJS Templates
HTML/Markdown cells no longer saved their rendered output.
Brian E. Granger -
Show More
@@ -1,250 +1,249 b''
1
1
2 //============================================================================
2 //============================================================================
3 // TextCell
3 // TextCell
4 //============================================================================
4 //============================================================================
5
5
6 var IPython = (function (IPython) {
6 var IPython = (function (IPython) {
7
7
8 // TextCell base class
8 // TextCell base class
9
9
10 var TextCell = function (notebook) {
10 var TextCell = function (notebook) {
11 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
11 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
12 this.placeholder = this.placeholder || '';
12 this.placeholder = this.placeholder || '';
13 IPython.Cell.apply(this, arguments);
13 IPython.Cell.apply(this, arguments);
14 this.rendered = false;
14 this.rendered = false;
15 this.cell_type = this.cell_type || 'text';
15 this.cell_type = this.cell_type || 'text';
16 };
16 };
17
17
18
18
19 TextCell.prototype = new IPython.Cell();
19 TextCell.prototype = new IPython.Cell();
20
20
21
21
22 TextCell.prototype.create_element = function () {
22 TextCell.prototype.create_element = function () {
23 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
23 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
24 var input_area = $('<div/>').addClass('text_cell_input');
24 var input_area = $('<div/>').addClass('text_cell_input');
25 this.code_mirror = CodeMirror(input_area.get(0), {
25 this.code_mirror = CodeMirror(input_area.get(0), {
26 indentUnit : 4,
26 indentUnit : 4,
27 mode: this.code_mirror_mode,
27 mode: this.code_mirror_mode,
28 theme: 'default',
28 theme: 'default',
29 value: this.placeholder
29 value: this.placeholder
30 });
30 });
31 // The tabindex=-1 makes this div focusable.
31 // The tabindex=-1 makes this div focusable.
32 var render_area = $('<div/>').addClass('text_cell_render').
32 var render_area = $('<div/>').addClass('text_cell_render').
33 addClass('rendered_html').attr('tabindex','-1');
33 addClass('rendered_html').attr('tabindex','-1');
34 cell.append(input_area).append(render_area);
34 cell.append(input_area).append(render_area);
35 this.element = cell;
35 this.element = cell;
36 };
36 };
37
37
38
38
39 TextCell.prototype.bind_events = function () {
39 TextCell.prototype.bind_events = function () {
40 IPython.Cell.prototype.bind_events.apply(this);
40 IPython.Cell.prototype.bind_events.apply(this);
41 var that = this;
41 var that = this;
42 this.element.keydown(function (event) {
42 this.element.keydown(function (event) {
43 if (event.which === 13) {
43 if (event.which === 13) {
44 if (that.rendered) {
44 if (that.rendered) {
45 that.edit();
45 that.edit();
46 event.preventDefault();
46 event.preventDefault();
47 };
47 };
48 };
48 };
49 });
49 });
50 };
50 };
51
51
52
52
53 TextCell.prototype.select = function () {
53 TextCell.prototype.select = function () {
54 IPython.Cell.prototype.select.apply(this);
54 IPython.Cell.prototype.select.apply(this);
55 var output = this.element.find("div.text_cell_render");
55 var output = this.element.find("div.text_cell_render");
56 output.trigger('focus');
56 output.trigger('focus');
57 };
57 };
58
58
59
59
60 TextCell.prototype.edit = function () {
60 TextCell.prototype.edit = function () {
61 if (this.rendered === true) {
61 if (this.rendered === true) {
62 var text_cell = this.element;
62 var text_cell = this.element;
63 var output = text_cell.find("div.text_cell_render");
63 var output = text_cell.find("div.text_cell_render");
64 output.hide();
64 output.hide();
65 text_cell.find('div.text_cell_input').show();
65 text_cell.find('div.text_cell_input').show();
66 this.code_mirror.focus();
66 this.code_mirror.focus();
67 this.code_mirror.refresh();
67 this.code_mirror.refresh();
68 this.rendered = false;
68 this.rendered = false;
69 };
69 };
70 };
70 };
71
71
72
72
73 // Subclasses must define render.
73 // Subclasses must define render.
74 TextCell.prototype.render = function () {};
74 TextCell.prototype.render = function () {};
75
75
76
76
77 TextCell.prototype.config_mathjax = function () {
77 TextCell.prototype.config_mathjax = function () {
78 var text_cell = this.element;
78 var text_cell = this.element;
79 var that = this;
79 var that = this;
80 text_cell.click(function () {
80 text_cell.click(function () {
81 that.edit();
81 that.edit();
82 }).focusout(function () {
82 }).focusout(function () {
83 that.render();
83 that.render();
84 });
84 });
85
85
86 text_cell.trigger("focusout");
86 text_cell.trigger("focusout");
87 };
87 };
88
88
89
89
90 TextCell.prototype.get_source = function() {
90 TextCell.prototype.get_source = function() {
91 return this.code_mirror.getValue();
91 return this.code_mirror.getValue();
92 };
92 };
93
93
94
94
95 TextCell.prototype.set_source = function(text) {
95 TextCell.prototype.set_source = function(text) {
96 this.code_mirror.setValue(text);
96 this.code_mirror.setValue(text);
97 this.code_mirror.refresh();
97 this.code_mirror.refresh();
98 };
98 };
99
99
100
100
101 TextCell.prototype.get_rendered = function() {
101 TextCell.prototype.get_rendered = function() {
102 return this.element.find('div.text_cell_render').html();
102 return this.element.find('div.text_cell_render').html();
103 };
103 };
104
104
105
105
106 TextCell.prototype.set_rendered = function(text) {
106 TextCell.prototype.set_rendered = function(text) {
107 this.element.find('div.text_cell_render').html(text);
107 this.element.find('div.text_cell_render').html(text);
108 };
108 };
109
109
110
110
111 TextCell.prototype.at_top = function () {
111 TextCell.prototype.at_top = function () {
112 if (this.rendered) {
112 if (this.rendered) {
113 return true;
113 return true;
114 } else {
114 } else {
115 return false;
115 return false;
116 }
116 }
117 };
117 };
118
118
119
119
120 TextCell.prototype.at_bottom = function () {
120 TextCell.prototype.at_bottom = function () {
121 if (this.rendered) {
121 if (this.rendered) {
122 return true;
122 return true;
123 } else {
123 } else {
124 return false;
124 return false;
125 }
125 }
126 };
126 };
127
127
128
128
129 TextCell.prototype.fromJSON = function (data) {
129 TextCell.prototype.fromJSON = function (data) {
130 console.log(data);
130 console.log(data);
131 if (data.cell_type === this.cell_type) {
131 if (data.cell_type === this.cell_type) {
132 if (data.source !== undefined) {
132 if (data.source !== undefined) {
133 this.set_source(data.source);
133 this.set_source(data.source);
134 this.set_rendered(data.rendered || '');
134 this.set_rendered(data.rendered || '');
135 this.rendered = false;
135 this.rendered = false;
136 this.render();
136 this.render();
137 };
137 };
138 };
138 };
139 };
139 };
140
140
141
141
142 TextCell.prototype.toJSON = function () {
142 TextCell.prototype.toJSON = function () {
143 var data = {}
143 var data = {}
144 data.cell_type = this.cell_type;
144 data.cell_type = this.cell_type;
145 data.source = this.get_source();
145 data.source = this.get_source();
146 data.rendered = this.get_rendered();
147 return data;
146 return data;
148 };
147 };
149
148
150
149
151 // HTMLCell
150 // HTMLCell
152
151
153 var HTMLCell = function (notebook) {
152 var HTMLCell = function (notebook) {
154 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
153 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
155 IPython.TextCell.apply(this, arguments);
154 IPython.TextCell.apply(this, arguments);
156 this.cell_type = 'html';
155 this.cell_type = 'html';
157 };
156 };
158
157
159
158
160 HTMLCell.prototype = new TextCell();
159 HTMLCell.prototype = new TextCell();
161
160
162
161
163 HTMLCell.prototype.render = function () {
162 HTMLCell.prototype.render = function () {
164 if (this.rendered === false) {
163 if (this.rendered === false) {
165 var text = this.get_source();
164 var text = this.get_source();
166 if (text === "") {text = this.placeholder;};
165 if (text === "") {text = this.placeholder;};
167 this.set_rendered(text);
166 this.set_rendered(text);
168 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
167 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
169 this.element.find('div.text_cell_input').hide();
168 this.element.find('div.text_cell_input').hide();
170 this.element.find("div.text_cell_render").show();
169 this.element.find("div.text_cell_render").show();
171 this.rendered = true;
170 this.rendered = true;
172 };
171 };
173 };
172 };
174
173
175
174
176 // MarkdownCell
175 // MarkdownCell
177
176
178 var MarkdownCell = function (notebook) {
177 var MarkdownCell = function (notebook) {
179 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
178 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
180 IPython.TextCell.apply(this, arguments);
179 IPython.TextCell.apply(this, arguments);
181 this.cell_type = 'markdown';
180 this.cell_type = 'markdown';
182 };
181 };
183
182
184
183
185 MarkdownCell.prototype = new TextCell();
184 MarkdownCell.prototype = new TextCell();
186
185
187
186
188 MarkdownCell.prototype.render = function () {
187 MarkdownCell.prototype.render = function () {
189 if (this.rendered === false) {
188 if (this.rendered === false) {
190 var text = this.get_source();
189 var text = this.get_source();
191 if (text === "") {text = this.placeholder;};
190 if (text === "") {text = this.placeholder;};
192 var html = IPython.markdown_converter.makeHtml(text);
191 var html = IPython.markdown_converter.makeHtml(text);
193 this.set_rendered(html);
192 this.set_rendered(html);
194 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
193 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
195 this.element.find('div.text_cell_input').hide();
194 this.element.find('div.text_cell_input').hide();
196 this.element.find("div.text_cell_render").show();
195 this.element.find("div.text_cell_render").show();
197 this.rendered = true;
196 this.rendered = true;
198 };
197 };
199 };
198 };
200
199
201
200
202 // RSTCell
201 // RSTCell
203
202
204 var RSTCell = function (notebook) {
203 var RSTCell = function (notebook) {
205 this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
204 this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
206 IPython.TextCell.apply(this, arguments);
205 IPython.TextCell.apply(this, arguments);
207 this.cell_type = 'rst';
206 this.cell_type = 'rst';
208 };
207 };
209
208
210
209
211 RSTCell.prototype = new TextCell();
210 RSTCell.prototype = new TextCell();
212
211
213
212
214 RSTCell.prototype.render = function () {
213 RSTCell.prototype.render = function () {
215 if (this.rendered === false) {
214 if (this.rendered === false) {
216 var text = this.get_source();
215 var text = this.get_source();
217 if (text === "") {text = this.placeholder;};
216 if (text === "") {text = this.placeholder;};
218 var settings = {
217 var settings = {
219 processData : false,
218 processData : false,
220 cache : false,
219 cache : false,
221 type : "POST",
220 type : "POST",
222 data : text,
221 data : text,
223 headers : {'Content-Type': 'application/x-rst'},
222 headers : {'Content-Type': 'application/x-rst'},
224 success : $.proxy(this.handle_render,this)
223 success : $.proxy(this.handle_render,this)
225 };
224 };
226 $.ajax("/rstservice/render", settings);
225 $.ajax("/rstservice/render", settings);
227 this.element.find('div.text_cell_input').hide();
226 this.element.find('div.text_cell_input').hide();
228 this.element.find("div.text_cell_render").show();
227 this.element.find("div.text_cell_render").show();
229 this.set_rendered("Rendering...");
228 this.set_rendered("Rendering...");
230 };
229 };
231 };
230 };
232
231
233
232
234 RSTCell.prototype.handle_render = function (data, status, xhr) {
233 RSTCell.prototype.handle_render = function (data, status, xhr) {
235 this.set_rendered(data);
234 this.set_rendered(data);
236 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
235 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
237 this.rendered = true;
236 this.rendered = true;
238 };
237 };
239
238
240
239
241 IPython.TextCell = TextCell;
240 IPython.TextCell = TextCell;
242 IPython.HTMLCell = HTMLCell;
241 IPython.HTMLCell = HTMLCell;
243 IPython.MarkdownCell = MarkdownCell;
242 IPython.MarkdownCell = MarkdownCell;
244 IPython.RSTCell = RSTCell;
243 IPython.RSTCell = RSTCell;
245
244
246
245
247 return IPython;
246 return IPython;
248
247
249 }(IPython));
248 }(IPython));
250
249
General Comments 0
You need to be logged in to leave comments. Login now