##// END OF EJS Templates
small CSS adjustments in notebook...
MinRK -
Show More
@@ -1,324 +1,334 b''
1 1
2 2 /**
3 3 * Primary styles
4 4 *
5 5 * Author: IPython Development Team
6 6 */
7 7
8 8
9 9 body {
10 10 background-color: white;
11 11 /* This makes sure that the body covers the entire window and needs to
12 12 be in a different element than the display: box in wrapper below */
13 13 position: absolute;
14 14 left: 0px;
15 15 right: 0px;
16 16 top: 0px;
17 17 bottom: 0px;
18 18 overflow: hidden;
19 19 }
20 20
21 21 span#save_widget {
22 22 position: absolute;
23 23 left: 0px;
24 24 padding: 5px 0px;
25 25 margin: 0px 0px 0px 0px;
26 26 }
27 27
28 28 input#notebook_name {
29 29 height: 1em;
30 30 line-height: 1em;
31 31 padding: 5px;
32 32 }
33 33
34 34 span#kernel_status {
35 35 position: absolute;
36 36 padding: 8px 5px 5px 5px;
37 37 right: 10px;
38 38 font-weight: bold;
39 39 }
40 40
41 41 .status_idle {
42 42 color: gray;
43 43 }
44 44
45 45 .status_busy {
46 46 color: red;
47 47 }
48 48
49 49 .status_restarting {
50 50 color: black;
51 51 }
52 52
53 53 div#left_panel {
54 54 overflow-y: auto;
55 55 top: 0px;
56 56 left: 0px;
57 57 margin: 0px;
58 58 padding: 0px;
59 59 position: absolute;
60 60 }
61 61
62 62 h3.section_header {
63 63 padding: 5px;
64 64 }
65 65
66 66 div.section_content {
67 67 padding: 5px;
68 68 }
69 69
70 70 span.section_row_buttons button {
71 71 width: 70px;
72 72 }
73 73
74 74 span.section_row_buttons a {
75 75 width: 70px;
76 76 }
77 77
78 78 .section_row {
79 79 margin: 5px 0px;
80 80 }
81 81
82 82 .section_row_buttons {
83 83 float: right;
84 84 }
85 85
86 86 #kernel_persist {
87 87 float: right;
88 88 }
89 89
90 90 .help_string {
91 91 float: right;
92 92 width: 170px;
93 93 padding: 0px 5px;
94 94 text-align: left;
95 95 font-size: 85%;
96 96 }
97 97
98 98 .help_string_label {
99 99 float: right;
100 100 font-size: 85%;
101 101 }
102 102
103 103 #autoindent_span {
104 104 float: right;
105 105 }
106 106
107 107 .checkbox_label {
108 108 font-size: 85%;
109 109 float: right;
110 110 padding: 0.3em;
111 111 }
112 112
113 113 .section_row_header {
114 114 float: left;
115 115 font-size: 85%;
116 116 padding: 0.4em 0em;
117 117 font-weight: bold;
118 118 }
119 119
120 120 span.button_label {
121 121 padding: 0.2em 1em;
122 122 font-size: 77%;
123 123 float: right;
124 124 }
125 125
126 126 /* This is needed because FF was adding a 2px margin top and bottom. */
127 127 .section_row .ui-button {
128 128 margin-top: 0px;
129 129 margin-bottom: 0px;
130 130 }
131 131
132 132 #download_format {
133 133 float: right;
134 134 font-size: 85%;
135 135 width: 62px;
136 136 margin: 1px 5px;
137 137 }
138 138
139 139 div#left_panel_splitter {
140 140 width: 8px;
141 141 top: 0px;
142 142 left: 202px;
143 143 margin: 0px;
144 144 padding: 0px;
145 145 position: absolute;
146 146 }
147 147
148 148 div#notebook_panel {
149 149 /* The L margin will be set in the Javascript code*/
150 150 margin: 0px 0px 0px 0px;
151 151 padding: 0px;
152 152 }
153 153
154 154 div#notebook {
155 155 overflow-y: scroll;
156 156 overflow-x: auto;
157 157 width: 100%;
158 158 /* This spaces the cell away from the edge of the notebook area */
159 159 padding: 15px 15px 15px 15px;
160 160 margin: 0px
161 161 background-color: white;
162 162 }
163 163
164 164 div#pager_splitter {
165 165 height: 8px;
166 166 }
167 167
168 168 div#pager {
169 169 padding: 15px;
170 170 overflow: auto;
171 171 }
172 172
173 173 div.cell {
174 174 width: 100%;
175 175 padding: 5px;
176 176 /* This acts as a spacer between cells, that is outside the border */
177 177 margin: 5px 0px 5px 0px;
178 178 }
179 179
180 180 div.code_cell {
181 181 background-color: white;
182 182 }
183 183
184 184 div.prompt {
185 185 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
186 186 width: 11ex;
187 187 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
188 188 padding: 0.4em;
189 189 margin: 0px;
190 190 font-family: monospace;
191 191 text-align:right;
192 192 }
193 193
194 194 div.input {
195 195 page-break-inside: avoid;
196 196 }
197 197
198 198 div.input_area {
199 199 color: black;
200 border: 1px solid #ddd;
200 201 }
201 202
202 203 div.input_prompt {
203 204 color: navy;
204 205 }
205 206
206 207 div.output {
207 208 /* This is a spacer between the input and output of each cell */
208 209 margin-top: 5px;
209 210 }
210 211
211 212 div.output_prompt {
212 213 color: darkred;
213 214 }
214 215
215 216 /* This class is the outer container of all output sections. */
216 217 div.output_area {
217 218 padding: 0px;
218 219 page-break-inside: avoid;
219 220 }
220 221
221 222 /* This class is for the output subarea inside the output_area and after
222 223 the prompt div. */
223 224 div.output_subarea {
224 225 padding: 0.4em;
225 226 }
226 227
227 228 /* The rest of the output_* classes are for special styling of the different
228 229 output types */
229 230
230 div.output_stream {
231 /* all text output has this class: */
232 div.output_text {
231 233 text-align: left;
232 234 color: black;
233 235 font-family: monospace;
234 236 }
237
238 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
239 div.output_stream {
240 padding-top: 0.0em;
241 padding-bottom: 0.0em;
242 }
243 div.output_stdout {
244 }
235 245 div.output_stderr {
236 color: darkred;
246 background: #fdd; /* very light red background for stderr */
237 247 }
238 248
239 249 div.output_latex {
240 250 text-align: left;
241 251 color: black;
242 252 }
243 253
244 254 div.output_html {
245 255 }
246 256
247 257 div.output_png {
248 258 }
249 259
250 260 div.output_jpeg {
251 261 }
252 262
253 263 div.text_cell {
254 264 background-color: white;
255 265 }
256 266
257 267 div.text_cell_input {
258 268 color: black;
259 269 }
260 270
261 271 div.text_cell_render {
262 272 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
263 273 outline: none;
264 274 resize: none;
265 275 width: inherit;
266 276 border-style: none;
267 277 padding: 5px;
268 278 color: black;
269 279 }
270 280
271 281 .CodeMirror {
272 282 line-height: 1.231; /* Changed from 1em to our global default */
273 283 }
274 284
275 285 .CodeMirror-scroll {
276 286 height: auto; /* Changed to auto to autogrow */
277 287 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
278 288 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
279 289 overflow-y: hidden;
280 290 overflow-x: auto; /* Changed from auto to remove scrollbar */
281 291 }
282 292
283 293 /* CSS font colors for translated ANSI colors. */
284 294
285 295
286 296 .ansiblack {color: black;}
287 297 .ansired {color: darkred;}
288 298 .ansigreen {color: darkgreen;}
289 299 .ansiyellow {color: brown;}
290 300 .ansiblue {color: darkblue;}
291 301 .ansipurple {color: darkviolet;}
292 302 .ansicyan {color: steelblue;}
293 303 .ansigrey {color: grey;}
294 304 .ansibold {font-weight: bold;}
295 305
296 306 .completions {
297 307 position: absolute;
298 308 z-index: 10;
299 309 overflow: auto;
300 310 border: 1px solid black;
301 311 }
302 312
303 313 .completions select {
304 314 background: white;
305 315 outline: none;
306 316 border: none;
307 317 padding: 0px;
308 318 margin: 0px;
309 319 font-family: monospace;
310 320 }
311 321
312 322 @media print {
313 323 body { overflow: visible !important; }
314 324 .ui-widget-content { border: 0px; }
315 325 }
316 326
317 327 .shortcut_key {
318 328 display: inline-block;
319 329 width: 10ex;
320 330 text-align: right;
321 331 }
322 332
323 333 .shortcut_descr {
324 334 } No newline at end of file
@@ -1,473 +1,473 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // CodeCell
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13
14 14 var utils = IPython.utils;
15 15
16 16 var CodeCell = function (notebook) {
17 17 this.code_mirror = null;
18 18 this.input_prompt_number = ' ';
19 19 this.is_completing = false;
20 20 this.completion_cursor = null;
21 21 this.outputs = [];
22 22 this.collapsed = false;
23 23 IPython.Cell.apply(this, arguments);
24 24 };
25 25
26 26
27 27 CodeCell.prototype = new IPython.Cell();
28 28
29 29
30 30 CodeCell.prototype.create_element = function () {
31 31 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
32 32 cell.attr('tabindex','2');
33 33 var input = $('<div></div>').addClass('input hbox');
34 34 input.append($('<div/>').addClass('prompt input_prompt'));
35 35 var input_area = $('<div/>').addClass('input_area box-flex1');
36 36 this.code_mirror = CodeMirror(input_area.get(0), {
37 37 indentUnit : 4,
38 38 mode: 'python',
39 39 theme: 'ipython',
40 40 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
41 41 });
42 42 input.append(input_area);
43 43 var output = $('<div></div>').addClass('output vbox');
44 44 cell.append(input).append(output);
45 45 this.element = cell;
46 46 this.collapse()
47 47 };
48 48
49 49
50 50 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
51 51 // This method gets called in CodeMirror's onKeyDown/onKeyPress handlers and
52 52 // is used to provide custom key handling. Its return value is used to determine
53 53 // if CodeMirror should ignore the event: true = ignore, false = don't ignore.
54 54 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
55 55 // Always ignore shift-enter in CodeMirror as we handle it.
56 56 return true;
57 57 } else if (event.keyCode === 9 && event.type == 'keydown') {
58 58 // Tab completion.
59 59 var cur = editor.getCursor();
60 60 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
61 61 if (pre_cursor === "") {
62 62 // Don't autocomplete if the part of the line before the cursor is empty.
63 63 // In this case, let CodeMirror handle indentation.
64 64 return false;
65 65 } else {
66 66 // Autocomplete the current line.
67 67 event.stop();
68 68 var line = editor.getLine(cur.line);
69 69 this.is_completing = true;
70 70 this.completion_cursor = cur;
71 71 IPython.notebook.complete_cell(this, line, cur.ch);
72 72 return true;
73 73 }
74 74 } else if (event.keyCode === 8 && event.type == 'keydown') {
75 75 // If backspace and the line ends with 4 spaces, remove them.
76 76 var cur = editor.getCursor();
77 77 var line = editor.getLine(cur.line);
78 78 var ending = line.slice(-4);
79 79 if (ending === ' ') {
80 80 editor.replaceRange('',
81 81 {line: cur.line, ch: cur.ch-4},
82 82 {line: cur.line, ch: cur.ch}
83 83 );
84 84 event.stop();
85 85 return true;
86 86 } else {
87 87 return false;
88 88 };
89 89 } else {
90 90 // keypress/keyup also trigger on TAB press, and we don't want to use those
91 91 // to disable tab completion.
92 92 if (this.is_completing && event.keyCode !== 9) {
93 93 var ed_cur = editor.getCursor();
94 94 var cc_cur = this.completion_cursor;
95 95 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
96 96 this.is_completing = false;
97 97 this.completion_cursor = null;
98 98 };
99 99 };
100 100 return false;
101 101 };
102 102 };
103 103
104 104
105 105 CodeCell.prototype.finish_completing = function (matched_text, matches) {
106 106 // console.log("Got matches", matched_text, matches);
107 107 if (!this.is_completing || matches.length === 0) {return;}
108 108
109 109 var that = this;
110 110 var cur = this.completion_cursor;
111 111
112 112 var insert = function (selected_text) {
113 113 that.code_mirror.replaceRange(
114 114 selected_text,
115 115 {line: cur.line, ch: (cur.ch-matched_text.length)},
116 116 {line: cur.line, ch: cur.ch}
117 117 );
118 118 };
119 119
120 120 if (matches.length === 1) {
121 121 insert(matches[0]);
122 122 setTimeout(function(){that.code_mirror.focus();}, 50);
123 123 return;
124 124 };
125 125
126 126 var complete = $('<div/>').addClass('completions');
127 127 var select = $('<select/>').attr('multiple','true');
128 128 for (var i=0; i<matches.length; ++i) {
129 129 select.append($('<option/>').text(matches[i]));
130 130 }
131 131 select.children().first().attr('selected','true');
132 132 select.attr('size',Math.min(10,matches.length));
133 133 var pos = this.code_mirror.cursorCoords();
134 134 complete.css('left',pos.x+'px');
135 135 complete.css('top',pos.yBot+'px');
136 136 complete.append(select);
137 137
138 138 $('body').append(complete);
139 139 var done = false;
140 140
141 141 var close = function () {
142 142 if (done) return;
143 143 done = true;
144 144 complete.remove();
145 145 that.is_completing = false;
146 146 that.completion_cursor = null;
147 147 };
148 148
149 149 var pick = function () {
150 150 insert(select.val()[0]);
151 151 close();
152 152 setTimeout(function(){that.code_mirror.focus();}, 50);
153 153 };
154 154
155 155 select.blur(close);
156 156 select.keydown(function (event) {
157 157 var code = event.which;
158 158 if (code === 13 || code === 32) {
159 159 // Pressing SPACE or ENTER will cause a pick
160 160 event.stopPropagation();
161 161 event.preventDefault();
162 162 pick();
163 163 } else if (code === 38 || code === 40) {
164 164 // We don't want the document keydown handler to handle UP/DOWN,
165 165 // but we want the default action.
166 166 event.stopPropagation();
167 167 } else {
168 168 // All other key presses exit completion.
169 169 event.stopPropagation();
170 170 event.preventDefault();
171 171 close();
172 172 that.code_mirror.focus();
173 173 }
174 174 });
175 175 // Double click also causes a pick.
176 176 select.dblclick(pick);
177 177 select.focus();
178 178 };
179 179
180 180
181 181 CodeCell.prototype.select = function () {
182 182 IPython.Cell.prototype.select.apply(this);
183 183 // Todo: this dance is needed because as of CodeMirror 2.12, focus is
184 184 // not causing the cursor to blink if the editor is empty initially.
185 185 // While this seems to fix the issue, this should be fixed
186 186 // in CodeMirror proper.
187 187 var s = this.code_mirror.getValue();
188 188 this.code_mirror.focus();
189 189 if (s === '') this.code_mirror.setValue('');
190 190 };
191 191
192 192
193 193 CodeCell.prototype.select_all = function () {
194 194 var start = {line: 0, ch: 0};
195 195 var nlines = this.code_mirror.lineCount();
196 196 var last_line = this.code_mirror.getLine(nlines-1);
197 197 var end = {line: nlines-1, ch: last_line.length};
198 198 this.code_mirror.setSelection(start, end);
199 199 };
200 200
201 201
202 202 CodeCell.prototype.append_output = function (json) {
203 203 this.expand();
204 204 if (json.output_type === 'pyout') {
205 205 this.append_pyout(json);
206 206 } else if (json.output_type === 'pyerr') {
207 207 this.append_pyerr(json);
208 208 } else if (json.output_type === 'display_data') {
209 209 this.append_display_data(json);
210 210 } else if (json.output_type === 'stream') {
211 211 this.append_stream(json);
212 212 };
213 213 this.outputs.push(json);
214 214 };
215 215
216 216
217 217 CodeCell.prototype.create_output_area = function () {
218 218 var oa = $("<div/>").addClass("hbox output_area");
219 219 oa.append($('<div/>').addClass('prompt'));
220 220 return oa;
221 221 };
222 222
223 223
224 224 CodeCell.prototype.append_pyout = function (json) {
225 225 n = json.prompt_number || ' ';
226 226 var toinsert = this.create_output_area();
227 227 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
228 228 this.append_mime_type(json, toinsert);
229 229 this.element.find('div.output').append(toinsert);
230 230 // If we just output latex, typeset it.
231 231 if (json.latex !== undefined) {
232 232 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
233 233 };
234 234 };
235 235
236 236
237 237 CodeCell.prototype.append_pyerr = function (json) {
238 238 var tb = json.traceback;
239 239 if (tb !== undefined && tb.length > 0) {
240 240 var s = '';
241 241 var len = tb.length;
242 242 for (var i=0; i<len; i++) {
243 243 s = s + tb[i] + '\n';
244 244 }
245 245 s = s + '\n';
246 246 var toinsert = this.create_output_area();
247 247 this.append_text(s, toinsert);
248 248 this.element.find('div.output').append(toinsert);
249 249 };
250 250 };
251 251
252 252
253 253 CodeCell.prototype.append_stream = function (json) {
254 254 // temporary fix: if stream undefined (json file written prior to this patch),
255 255 // default to most likely stdout:
256 256 if (json.stream == undefined){
257 257 json.stream = 'stdout';
258 258 }
259 259 var subclass = "output_"+json.stream;
260 260 if (this.outputs.length > 0){
261 261 // have at least one output to consider
262 262 var last = this.outputs[this.outputs.length-1];
263 263 if (last.output_type == 'stream' && json.stream == last.stream){
264 264 // latest output was in the same stream,
265 265 // so append directly into its pre tag
266 266 this.element.find('div.'+subclass).last().find('pre').append(json.text);
267 267 return;
268 268 }
269 269 }
270 270
271 271 // If we got here, attach a new div
272 272 var toinsert = this.create_output_area();
273 this.append_text(json.text, toinsert, subclass);
273 this.append_text(json.text, toinsert, "output_stream "+subclass);
274 274 this.element.find('div.output').append(toinsert);
275 275 };
276 276
277 277
278 278 CodeCell.prototype.append_display_data = function (json) {
279 279 var toinsert = this.create_output_area();
280 280 this.append_mime_type(json, toinsert)
281 281 this.element.find('div.output').append(toinsert);
282 282 // If we just output latex, typeset it.
283 283 if (json.latex !== undefined) {
284 284 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
285 285 };
286 286 };
287 287
288 288
289 289 CodeCell.prototype.append_mime_type = function (json, element) {
290 290 if (json.html !== undefined) {
291 291 this.append_html(json.html, element);
292 292 } else if (json.latex !== undefined) {
293 293 this.append_latex(json.latex, element);
294 294 } else if (json.svg !== undefined) {
295 295 this.append_svg(json.svg, element);
296 296 } else if (json.png !== undefined) {
297 297 this.append_png(json.png, element);
298 298 } else if (json.jpeg !== undefined) {
299 299 this.append_jpeg(json.jpeg, element);
300 300 } else if (json.text !== undefined) {
301 301 this.append_text(json.text, element);
302 302 };
303 303 };
304 304
305 305
306 306 CodeCell.prototype.append_html = function (html, element) {
307 307 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
308 308 toinsert.append(html);
309 309 element.append(toinsert);
310 310 }
311 311
312 312
313 313 CodeCell.prototype.append_text = function (data, element, extra_class) {
314 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_stream");
314 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
315 315 if (extra_class){
316 316 toinsert.addClass(extra_class);
317 317 }
318 318 toinsert.append($("<pre/>").html(data));
319 319 element.append(toinsert);
320 320 };
321 321
322 322
323 323 CodeCell.prototype.append_svg = function (svg, element) {
324 324 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_svg");
325 325 toinsert.append(svg);
326 326 element.append(toinsert);
327 327 };
328 328
329 329
330 330 CodeCell.prototype.append_png = function (png, element) {
331 331 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_png");
332 332 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
333 333 element.append(toinsert);
334 334 };
335 335
336 336
337 337 CodeCell.prototype.append_jpeg = function (jpeg, element) {
338 338 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_jpeg");
339 339 toinsert.append($("<img/>").attr('src','data:image/jpeg;base64,'+jpeg));
340 340 element.append(toinsert);
341 341 };
342 342
343 343
344 344 CodeCell.prototype.append_latex = function (latex, element) {
345 345 // This method cannot do the typesetting because the latex first has to
346 346 // be on the page.
347 347 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
348 348 toinsert.append(latex);
349 349 element.append(toinsert);
350 350 }
351 351
352 352
353 353 CodeCell.prototype.clear_output = function () {
354 354 this.element.find("div.output").html("");
355 355 this.outputs = [];
356 356 };
357 357
358 358
359 359 CodeCell.prototype.clear_input = function () {
360 360 this.code_mirror.setValue('');
361 361 };
362 362
363 363
364 364 CodeCell.prototype.collapse = function () {
365 365 if (!this.collapsed) {
366 366 this.element.find('div.output').hide();
367 367 this.collapsed = true;
368 368 };
369 369 };
370 370
371 371
372 372 CodeCell.prototype.expand = function () {
373 373 if (this.collapsed) {
374 374 this.element.find('div.output').show();
375 375 this.collapsed = false;
376 376 };
377 377 };
378 378
379 379
380 380 CodeCell.prototype.toggle_output = function () {
381 381 if (this.collapsed) {
382 382 this.expand();
383 383 } else {
384 384 this.collapse();
385 385 };
386 386 };
387 387
388 388 CodeCell.prototype.set_input_prompt = function (number) {
389 389 var n = number || ' ';
390 390 this.input_prompt_number = n
391 391 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
392 392 };
393 393
394 394
395 395 CodeCell.prototype.get_code = function () {
396 396 return this.code_mirror.getValue();
397 397 };
398 398
399 399
400 400 CodeCell.prototype.set_code = function (code) {
401 401 return this.code_mirror.setValue(code);
402 402 };
403 403
404 404
405 405 CodeCell.prototype.at_top = function () {
406 406 var cursor = this.code_mirror.getCursor();
407 407 if (cursor.line === 0) {
408 408 return true;
409 409 } else {
410 410 return false;
411 411 }
412 412 };
413 413
414 414
415 415 CodeCell.prototype.at_bottom = function () {
416 416 var cursor = this.code_mirror.getCursor();
417 417 if (cursor.line === (this.code_mirror.lineCount()-1)) {
418 418 return true;
419 419 } else {
420 420 return false;
421 421 }
422 422 };
423 423
424 424
425 425 CodeCell.prototype.fromJSON = function (data) {
426 426 console.log('Import from JSON:', data);
427 427 if (data.cell_type === 'code') {
428 428 if (data.input !== undefined) {
429 429 this.set_code(data.input);
430 430 }
431 431 if (data.prompt_number !== undefined) {
432 432 this.set_input_prompt(data.prompt_number);
433 433 } else {
434 434 this.set_input_prompt();
435 435 };
436 436 var len = data.outputs.length;
437 437 for (var i=0; i<len; i++) {
438 438 this.append_output(data.outputs[i]);
439 439 };
440 440 if (data.collapsed !== undefined) {
441 441 if (data.collapsed) {
442 442 this.collapse();
443 443 };
444 444 };
445 445 };
446 446 };
447 447
448 448
449 449 CodeCell.prototype.toJSON = function () {
450 450 var data = {};
451 451 data.input = this.get_code();
452 452 data.cell_type = 'code';
453 453 if (this.input_prompt_number !== ' ') {
454 454 data.prompt_number = this.input_prompt_number
455 455 };
456 456 var outputs = [];
457 457 var len = this.outputs.length;
458 458 for (var i=0; i<len; i++) {
459 459 outputs[i] = this.outputs[i];
460 460 };
461 461 data.outputs = outputs;
462 462 data.language = 'python';
463 463 data.collapsed = this.collapsed;
464 464 // console.log('Export to JSON:',data);
465 465 return data;
466 466 };
467 467
468 468
469 469 IPython.CodeCell = CodeCell;
470 470
471 471 return IPython;
472 472 }(IPython));
473 473
General Comments 0
You need to be logged in to leave comments. Login now