##// END OF EJS Templates
use on-load event to trigger resizable images...
MinRK -
Show More
@@ -1,864 +1,862 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008 The IPython Development Team
2 // Copyright (C) 2008 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // OutputArea
9 // OutputArea
10 //============================================================================
10 //============================================================================
11
11
12 /**
12 /**
13 * @module IPython
13 * @module IPython
14 * @namespace IPython
14 * @namespace IPython
15 * @submodule OutputArea
15 * @submodule OutputArea
16 */
16 */
17 var IPython = (function (IPython) {
17 var IPython = (function (IPython) {
18 "use strict";
18 "use strict";
19
19
20 var utils = IPython.utils;
20 var utils = IPython.utils;
21
21
22 /**
22 /**
23 * @class OutputArea
23 * @class OutputArea
24 *
24 *
25 * @constructor
25 * @constructor
26 */
26 */
27
27
28 var OutputArea = function (selector, prompt_area) {
28 var OutputArea = function (selector, prompt_area) {
29 this.selector = selector;
29 this.selector = selector;
30 this.wrapper = $(selector);
30 this.wrapper = $(selector);
31 this.outputs = [];
31 this.outputs = [];
32 this.collapsed = false;
32 this.collapsed = false;
33 this.scrolled = false;
33 this.scrolled = false;
34 this.trusted = true;
34 this.trusted = true;
35 this.clear_queued = null;
35 this.clear_queued = null;
36 if (prompt_area === undefined) {
36 if (prompt_area === undefined) {
37 this.prompt_area = true;
37 this.prompt_area = true;
38 } else {
38 } else {
39 this.prompt_area = prompt_area;
39 this.prompt_area = prompt_area;
40 }
40 }
41 this.create_elements();
41 this.create_elements();
42 this.style();
42 this.style();
43 this.bind_events();
43 this.bind_events();
44 };
44 };
45
45
46
46
47 /**
47 /**
48 * Class prototypes
48 * Class prototypes
49 **/
49 **/
50
50
51 OutputArea.prototype.create_elements = function () {
51 OutputArea.prototype.create_elements = function () {
52 this.element = $("<div/>");
52 this.element = $("<div/>");
53 this.collapse_button = $("<div/>");
53 this.collapse_button = $("<div/>");
54 this.prompt_overlay = $("<div/>");
54 this.prompt_overlay = $("<div/>");
55 this.wrapper.append(this.prompt_overlay);
55 this.wrapper.append(this.prompt_overlay);
56 this.wrapper.append(this.element);
56 this.wrapper.append(this.element);
57 this.wrapper.append(this.collapse_button);
57 this.wrapper.append(this.collapse_button);
58 };
58 };
59
59
60
60
61 OutputArea.prototype.style = function () {
61 OutputArea.prototype.style = function () {
62 this.collapse_button.hide();
62 this.collapse_button.hide();
63 this.prompt_overlay.hide();
63 this.prompt_overlay.hide();
64
64
65 this.wrapper.addClass('output_wrapper');
65 this.wrapper.addClass('output_wrapper');
66 this.element.addClass('output');
66 this.element.addClass('output');
67
67
68 this.collapse_button.addClass("btn output_collapsed");
68 this.collapse_button.addClass("btn output_collapsed");
69 this.collapse_button.attr('title', 'click to expand output');
69 this.collapse_button.attr('title', 'click to expand output');
70 this.collapse_button.text('. . .');
70 this.collapse_button.text('. . .');
71
71
72 this.prompt_overlay.addClass('out_prompt_overlay prompt');
72 this.prompt_overlay.addClass('out_prompt_overlay prompt');
73 this.prompt_overlay.attr('title', 'click to expand output; double click to hide output');
73 this.prompt_overlay.attr('title', 'click to expand output; double click to hide output');
74
74
75 this.collapse();
75 this.collapse();
76 };
76 };
77
77
78 /**
78 /**
79 * Should the OutputArea scroll?
79 * Should the OutputArea scroll?
80 * Returns whether the height (in lines) exceeds a threshold.
80 * Returns whether the height (in lines) exceeds a threshold.
81 *
81 *
82 * @private
82 * @private
83 * @method _should_scroll
83 * @method _should_scroll
84 * @param [lines=100]{Integer}
84 * @param [lines=100]{Integer}
85 * @return {Bool}
85 * @return {Bool}
86 *
86 *
87 */
87 */
88 OutputArea.prototype._should_scroll = function (lines) {
88 OutputArea.prototype._should_scroll = function (lines) {
89 if (lines <=0 ){ return }
89 if (lines <=0 ){ return }
90 if (!lines) {
90 if (!lines) {
91 lines = 100;
91 lines = 100;
92 }
92 }
93 // line-height from http://stackoverflow.com/questions/1185151
93 // line-height from http://stackoverflow.com/questions/1185151
94 var fontSize = this.element.css('font-size');
94 var fontSize = this.element.css('font-size');
95 var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5);
95 var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5);
96
96
97 return (this.element.height() > lines * lineHeight);
97 return (this.element.height() > lines * lineHeight);
98 };
98 };
99
99
100
100
101 OutputArea.prototype.bind_events = function () {
101 OutputArea.prototype.bind_events = function () {
102 var that = this;
102 var that = this;
103 this.prompt_overlay.dblclick(function () { that.toggle_output(); });
103 this.prompt_overlay.dblclick(function () { that.toggle_output(); });
104 this.prompt_overlay.click(function () { that.toggle_scroll(); });
104 this.prompt_overlay.click(function () { that.toggle_scroll(); });
105
105
106 this.element.resize(function () {
106 this.element.resize(function () {
107 // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
107 // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
108 if ( IPython.utils.browser[0] === "Firefox" ) {
108 if ( IPython.utils.browser[0] === "Firefox" ) {
109 return;
109 return;
110 }
110 }
111 // maybe scroll output,
111 // maybe scroll output,
112 // if it's grown large enough and hasn't already been scrolled.
112 // if it's grown large enough and hasn't already been scrolled.
113 if ( !that.scrolled && that._should_scroll(OutputArea.auto_scroll_threshold)) {
113 if ( !that.scrolled && that._should_scroll(OutputArea.auto_scroll_threshold)) {
114 that.scroll_area();
114 that.scroll_area();
115 }
115 }
116 });
116 });
117 this.collapse_button.click(function () {
117 this.collapse_button.click(function () {
118 that.expand();
118 that.expand();
119 });
119 });
120 };
120 };
121
121
122
122
123 OutputArea.prototype.collapse = function () {
123 OutputArea.prototype.collapse = function () {
124 if (!this.collapsed) {
124 if (!this.collapsed) {
125 this.element.hide();
125 this.element.hide();
126 this.prompt_overlay.hide();
126 this.prompt_overlay.hide();
127 if (this.element.html()){
127 if (this.element.html()){
128 this.collapse_button.show();
128 this.collapse_button.show();
129 }
129 }
130 this.collapsed = true;
130 this.collapsed = true;
131 }
131 }
132 };
132 };
133
133
134
134
135 OutputArea.prototype.expand = function () {
135 OutputArea.prototype.expand = function () {
136 if (this.collapsed) {
136 if (this.collapsed) {
137 this.collapse_button.hide();
137 this.collapse_button.hide();
138 this.element.show();
138 this.element.show();
139 this.prompt_overlay.show();
139 this.prompt_overlay.show();
140 this.collapsed = false;
140 this.collapsed = false;
141 }
141 }
142 };
142 };
143
143
144
144
145 OutputArea.prototype.toggle_output = function () {
145 OutputArea.prototype.toggle_output = function () {
146 if (this.collapsed) {
146 if (this.collapsed) {
147 this.expand();
147 this.expand();
148 } else {
148 } else {
149 this.collapse();
149 this.collapse();
150 }
150 }
151 };
151 };
152
152
153
153
154 OutputArea.prototype.scroll_area = function () {
154 OutputArea.prototype.scroll_area = function () {
155 this.element.addClass('output_scroll');
155 this.element.addClass('output_scroll');
156 this.prompt_overlay.attr('title', 'click to unscroll output; double click to hide');
156 this.prompt_overlay.attr('title', 'click to unscroll output; double click to hide');
157 this.scrolled = true;
157 this.scrolled = true;
158 };
158 };
159
159
160
160
161 OutputArea.prototype.unscroll_area = function () {
161 OutputArea.prototype.unscroll_area = function () {
162 this.element.removeClass('output_scroll');
162 this.element.removeClass('output_scroll');
163 this.prompt_overlay.attr('title', 'click to scroll output; double click to hide');
163 this.prompt_overlay.attr('title', 'click to scroll output; double click to hide');
164 this.scrolled = false;
164 this.scrolled = false;
165 };
165 };
166
166
167 /**
167 /**
168 *
168 *
169 * Scroll OutputArea if height supperior than a threshold (in lines).
169 * Scroll OutputArea if height supperior than a threshold (in lines).
170 *
170 *
171 * Threshold is a maximum number of lines. If unspecified, defaults to
171 * Threshold is a maximum number of lines. If unspecified, defaults to
172 * OutputArea.minimum_scroll_threshold.
172 * OutputArea.minimum_scroll_threshold.
173 *
173 *
174 * Negative threshold will prevent the OutputArea from ever scrolling.
174 * Negative threshold will prevent the OutputArea from ever scrolling.
175 *
175 *
176 * @method scroll_if_long
176 * @method scroll_if_long
177 *
177 *
178 * @param [lines=20]{Number} Default to 20 if not set,
178 * @param [lines=20]{Number} Default to 20 if not set,
179 * behavior undefined for value of `0`.
179 * behavior undefined for value of `0`.
180 *
180 *
181 **/
181 **/
182 OutputArea.prototype.scroll_if_long = function (lines) {
182 OutputArea.prototype.scroll_if_long = function (lines) {
183 var n = lines | OutputArea.minimum_scroll_threshold;
183 var n = lines | OutputArea.minimum_scroll_threshold;
184 if(n <= 0){
184 if(n <= 0){
185 return
185 return
186 }
186 }
187
187
188 if (this._should_scroll(n)) {
188 if (this._should_scroll(n)) {
189 // only allow scrolling long-enough output
189 // only allow scrolling long-enough output
190 this.scroll_area();
190 this.scroll_area();
191 }
191 }
192 };
192 };
193
193
194
194
195 OutputArea.prototype.toggle_scroll = function () {
195 OutputArea.prototype.toggle_scroll = function () {
196 if (this.scrolled) {
196 if (this.scrolled) {
197 this.unscroll_area();
197 this.unscroll_area();
198 } else {
198 } else {
199 // only allow scrolling long-enough output
199 // only allow scrolling long-enough output
200 this.scroll_if_long();
200 this.scroll_if_long();
201 }
201 }
202 };
202 };
203
203
204
204
205 // typeset with MathJax if MathJax is available
205 // typeset with MathJax if MathJax is available
206 OutputArea.prototype.typeset = function () {
206 OutputArea.prototype.typeset = function () {
207 if (window.MathJax){
207 if (window.MathJax){
208 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
208 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
209 }
209 }
210 };
210 };
211
211
212
212
213 OutputArea.prototype.handle_output = function (msg) {
213 OutputArea.prototype.handle_output = function (msg) {
214 var json = {};
214 var json = {};
215 var msg_type = json.output_type = msg.header.msg_type;
215 var msg_type = json.output_type = msg.header.msg_type;
216 var content = msg.content;
216 var content = msg.content;
217 if (msg_type === "stream") {
217 if (msg_type === "stream") {
218 json.text = content.data;
218 json.text = content.data;
219 json.stream = content.name;
219 json.stream = content.name;
220 } else if (msg_type === "display_data") {
220 } else if (msg_type === "display_data") {
221 json = content.data;
221 json = content.data;
222 json.output_type = msg_type;
222 json.output_type = msg_type;
223 json.metadata = content.metadata;
223 json.metadata = content.metadata;
224 } else if (msg_type === "pyout") {
224 } else if (msg_type === "pyout") {
225 json = content.data;
225 json = content.data;
226 json.output_type = msg_type;
226 json.output_type = msg_type;
227 json.metadata = content.metadata;
227 json.metadata = content.metadata;
228 json.prompt_number = content.execution_count;
228 json.prompt_number = content.execution_count;
229 } else if (msg_type === "pyerr") {
229 } else if (msg_type === "pyerr") {
230 json.ename = content.ename;
230 json.ename = content.ename;
231 json.evalue = content.evalue;
231 json.evalue = content.evalue;
232 json.traceback = content.traceback;
232 json.traceback = content.traceback;
233 }
233 }
234 this.append_output(json);
234 this.append_output(json);
235 };
235 };
236
236
237
237
238 OutputArea.prototype.rename_keys = function (data, key_map) {
238 OutputArea.prototype.rename_keys = function (data, key_map) {
239 var remapped = {};
239 var remapped = {};
240 for (var key in data) {
240 for (var key in data) {
241 var new_key = key_map[key] || key;
241 var new_key = key_map[key] || key;
242 remapped[new_key] = data[key];
242 remapped[new_key] = data[key];
243 }
243 }
244 return remapped;
244 return remapped;
245 };
245 };
246
246
247
247
248 OutputArea.output_types = [
248 OutputArea.output_types = [
249 'application/javascript',
249 'application/javascript',
250 'text/html',
250 'text/html',
251 'text/latex',
251 'text/latex',
252 'image/svg+xml',
252 'image/svg+xml',
253 'image/png',
253 'image/png',
254 'image/jpeg',
254 'image/jpeg',
255 'application/pdf',
255 'application/pdf',
256 'text/plain'
256 'text/plain'
257 ];
257 ];
258
258
259 OutputArea.prototype.validate_output = function (json) {
259 OutputArea.prototype.validate_output = function (json) {
260 // scrub invalid outputs
260 // scrub invalid outputs
261 // TODO: right now everything is a string, but JSON really shouldn't be.
261 // TODO: right now everything is a string, but JSON really shouldn't be.
262 // nbformat 4 will fix that.
262 // nbformat 4 will fix that.
263 $.map(OutputArea.output_types, function(key){
263 $.map(OutputArea.output_types, function(key){
264 if (json[key] !== undefined && typeof json[key] !== 'string') {
264 if (json[key] !== undefined && typeof json[key] !== 'string') {
265 console.log("Invalid type for " + key, json[key]);
265 console.log("Invalid type for " + key, json[key]);
266 delete json[key];
266 delete json[key];
267 }
267 }
268 });
268 });
269 return json;
269 return json;
270 };
270 };
271
271
272 OutputArea.prototype.append_output = function (json) {
272 OutputArea.prototype.append_output = function (json) {
273 this.expand();
273 this.expand();
274 // Clear the output if clear is queued.
274 // Clear the output if clear is queued.
275 var needs_height_reset = false;
275 var needs_height_reset = false;
276 if (this.clear_queued) {
276 if (this.clear_queued) {
277 this.clear_output(false);
277 this.clear_output(false);
278 needs_height_reset = true;
278 needs_height_reset = true;
279 }
279 }
280
280
281 // validate output data types
281 // validate output data types
282 json = this.validate_output(json);
282 json = this.validate_output(json);
283
283
284 if (json.output_type === 'pyout') {
284 if (json.output_type === 'pyout') {
285 this.append_pyout(json);
285 this.append_pyout(json);
286 } else if (json.output_type === 'pyerr') {
286 } else if (json.output_type === 'pyerr') {
287 this.append_pyerr(json);
287 this.append_pyerr(json);
288 } else if (json.output_type === 'display_data') {
288 } else if (json.output_type === 'display_data') {
289 this.append_display_data(json);
289 this.append_display_data(json);
290 } else if (json.output_type === 'stream') {
290 } else if (json.output_type === 'stream') {
291 this.append_stream(json);
291 this.append_stream(json);
292 }
292 }
293
293
294 this.outputs.push(json);
294 this.outputs.push(json);
295
295
296 // Only reset the height to automatic if the height is currently
296 // Only reset the height to automatic if the height is currently
297 // fixed (done by wait=True flag on clear_output).
297 // fixed (done by wait=True flag on clear_output).
298 if (needs_height_reset) {
298 if (needs_height_reset) {
299 this.element.height('');
299 this.element.height('');
300 }
300 }
301
301
302 var that = this;
302 var that = this;
303 setTimeout(function(){that.element.trigger('resize');}, 100);
303 setTimeout(function(){that.element.trigger('resize');}, 100);
304 };
304 };
305
305
306
306
307 OutputArea.prototype.create_output_area = function () {
307 OutputArea.prototype.create_output_area = function () {
308 var oa = $("<div/>").addClass("output_area");
308 var oa = $("<div/>").addClass("output_area");
309 if (this.prompt_area) {
309 if (this.prompt_area) {
310 oa.append($('<div/>').addClass('prompt'));
310 oa.append($('<div/>').addClass('prompt'));
311 }
311 }
312 return oa;
312 return oa;
313 };
313 };
314
314
315
315
316 function _get_metadata_key(metadata, key, mime) {
316 function _get_metadata_key(metadata, key, mime) {
317 var mime_md = metadata[mime];
317 var mime_md = metadata[mime];
318 // mime-specific higher priority
318 // mime-specific higher priority
319 if (mime_md && mime_md[key] !== undefined) {
319 if (mime_md && mime_md[key] !== undefined) {
320 return mime_md[key];
320 return mime_md[key];
321 }
321 }
322 // fallback on global
322 // fallback on global
323 return metadata[key];
323 return metadata[key];
324 }
324 }
325
325
326 OutputArea.prototype.create_output_subarea = function(md, classes, mime) {
326 OutputArea.prototype.create_output_subarea = function(md, classes, mime) {
327 var subarea = $('<div/>').addClass('output_subarea').addClass(classes);
327 var subarea = $('<div/>').addClass('output_subarea').addClass(classes);
328 if (_get_metadata_key(md, 'isolated', mime)) {
328 if (_get_metadata_key(md, 'isolated', mime)) {
329 // Create an iframe to isolate the subarea from the rest of the
329 // Create an iframe to isolate the subarea from the rest of the
330 // document
330 // document
331 var iframe = $('<iframe/>').addClass('box-flex1');
331 var iframe = $('<iframe/>').addClass('box-flex1');
332 iframe.css({'height':1, 'width':'100%', 'display':'block'});
332 iframe.css({'height':1, 'width':'100%', 'display':'block'});
333 iframe.attr('frameborder', 0);
333 iframe.attr('frameborder', 0);
334 iframe.attr('scrolling', 'auto');
334 iframe.attr('scrolling', 'auto');
335
335
336 // Once the iframe is loaded, the subarea is dynamically inserted
336 // Once the iframe is loaded, the subarea is dynamically inserted
337 iframe.on('load', function() {
337 iframe.on('load', function() {
338 // Workaround needed by Firefox, to properly render svg inside
338 // Workaround needed by Firefox, to properly render svg inside
339 // iframes, see http://stackoverflow.com/questions/10177190/
339 // iframes, see http://stackoverflow.com/questions/10177190/
340 // svg-dynamically-added-to-iframe-does-not-render-correctly
340 // svg-dynamically-added-to-iframe-does-not-render-correctly
341 this.contentDocument.open();
341 this.contentDocument.open();
342
342
343 // Insert the subarea into the iframe
343 // Insert the subarea into the iframe
344 // We must directly write the html. When using Jquery's append
344 // We must directly write the html. When using Jquery's append
345 // method, javascript is evaluated in the parent document and
345 // method, javascript is evaluated in the parent document and
346 // not in the iframe document.
346 // not in the iframe document.
347 this.contentDocument.write(subarea.html());
347 this.contentDocument.write(subarea.html());
348
348
349 this.contentDocument.close();
349 this.contentDocument.close();
350
350
351 var body = this.contentDocument.body;
351 var body = this.contentDocument.body;
352 // Adjust the iframe height automatically
352 // Adjust the iframe height automatically
353 iframe.height(body.scrollHeight + 'px');
353 iframe.height(body.scrollHeight + 'px');
354 });
354 });
355
355
356 // Elements should be appended to the inner subarea and not to the
356 // Elements should be appended to the inner subarea and not to the
357 // iframe
357 // iframe
358 iframe.append = function(that) {
358 iframe.append = function(that) {
359 subarea.append(that);
359 subarea.append(that);
360 };
360 };
361
361
362 return iframe;
362 return iframe;
363 } else {
363 } else {
364 return subarea;
364 return subarea;
365 }
365 }
366 }
366 }
367
367
368
368
369 OutputArea.prototype._append_javascript_error = function (err, element) {
369 OutputArea.prototype._append_javascript_error = function (err, element) {
370 // display a message when a javascript error occurs in display output
370 // display a message when a javascript error occurs in display output
371 var msg = "Javascript error adding output!"
371 var msg = "Javascript error adding output!"
372 if ( element === undefined ) return;
372 if ( element === undefined ) return;
373 element.append(
373 element.append(
374 $('<div/>').html(msg + "<br/>" +
374 $('<div/>').html(msg + "<br/>" +
375 err.toString() +
375 err.toString() +
376 '<br/>See your browser Javascript console for more details.'
376 '<br/>See your browser Javascript console for more details.'
377 ).addClass('js-error')
377 ).addClass('js-error')
378 );
378 );
379 };
379 };
380
380
381 OutputArea.prototype._safe_append = function (toinsert) {
381 OutputArea.prototype._safe_append = function (toinsert) {
382 // safely append an item to the document
382 // safely append an item to the document
383 // this is an object created by user code,
383 // this is an object created by user code,
384 // and may have errors, which should not be raised
384 // and may have errors, which should not be raised
385 // under any circumstances.
385 // under any circumstances.
386 try {
386 try {
387 this.element.append(toinsert);
387 this.element.append(toinsert);
388 } catch(err) {
388 } catch(err) {
389 console.log(err);
389 console.log(err);
390 // Create an actual output_area and output_subarea, which creates
390 // Create an actual output_area and output_subarea, which creates
391 // the prompt area and the proper indentation.
391 // the prompt area and the proper indentation.
392 var toinsert = this.create_output_area();
392 var toinsert = this.create_output_area();
393 var subarea = $('<div/>').addClass('output_subarea');
393 var subarea = $('<div/>').addClass('output_subarea');
394 toinsert.append(subarea);
394 toinsert.append(subarea);
395 this._append_javascript_error(err, subarea);
395 this._append_javascript_error(err, subarea);
396 this.element.append(toinsert);
396 this.element.append(toinsert);
397 }
397 }
398 };
398 };
399
399
400
400
401 OutputArea.prototype.append_pyout = function (json) {
401 OutputArea.prototype.append_pyout = function (json) {
402 var n = json.prompt_number || ' ';
402 var n = json.prompt_number || ' ';
403 var toinsert = this.create_output_area();
403 var toinsert = this.create_output_area();
404 if (this.prompt_area) {
404 if (this.prompt_area) {
405 toinsert.find('div.prompt').addClass('output_prompt').text('Out[' + n + ']:');
405 toinsert.find('div.prompt').addClass('output_prompt').text('Out[' + n + ']:');
406 }
406 }
407 this.append_mime_type(json, toinsert);
407 this.append_mime_type(json, toinsert);
408 this._safe_append(toinsert);
408 this._safe_append(toinsert);
409 // If we just output latex, typeset it.
409 // If we just output latex, typeset it.
410 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
410 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
411 this.typeset();
411 this.typeset();
412 }
412 }
413 };
413 };
414
414
415
415
416 OutputArea.prototype.append_pyerr = function (json) {
416 OutputArea.prototype.append_pyerr = function (json) {
417 var tb = json.traceback;
417 var tb = json.traceback;
418 if (tb !== undefined && tb.length > 0) {
418 if (tb !== undefined && tb.length > 0) {
419 var s = '';
419 var s = '';
420 var len = tb.length;
420 var len = tb.length;
421 for (var i=0; i<len; i++) {
421 for (var i=0; i<len; i++) {
422 s = s + tb[i] + '\n';
422 s = s + tb[i] + '\n';
423 }
423 }
424 s = s + '\n';
424 s = s + '\n';
425 var toinsert = this.create_output_area();
425 var toinsert = this.create_output_area();
426 this.append_text(s, {}, toinsert);
426 this.append_text(s, {}, toinsert);
427 this._safe_append(toinsert);
427 this._safe_append(toinsert);
428 }
428 }
429 };
429 };
430
430
431
431
432 OutputArea.prototype.append_stream = function (json) {
432 OutputArea.prototype.append_stream = function (json) {
433 // temporary fix: if stream undefined (json file written prior to this patch),
433 // temporary fix: if stream undefined (json file written prior to this patch),
434 // default to most likely stdout:
434 // default to most likely stdout:
435 if (json.stream == undefined){
435 if (json.stream == undefined){
436 json.stream = 'stdout';
436 json.stream = 'stdout';
437 }
437 }
438 var text = json.text;
438 var text = json.text;
439 var subclass = "output_"+json.stream;
439 var subclass = "output_"+json.stream;
440 if (this.outputs.length > 0){
440 if (this.outputs.length > 0){
441 // have at least one output to consider
441 // have at least one output to consider
442 var last = this.outputs[this.outputs.length-1];
442 var last = this.outputs[this.outputs.length-1];
443 if (last.output_type == 'stream' && json.stream == last.stream){
443 if (last.output_type == 'stream' && json.stream == last.stream){
444 // latest output was in the same stream,
444 // latest output was in the same stream,
445 // so append directly into its pre tag
445 // so append directly into its pre tag
446 // escape ANSI & HTML specials:
446 // escape ANSI & HTML specials:
447 var pre = this.element.find('div.'+subclass).last().find('pre');
447 var pre = this.element.find('div.'+subclass).last().find('pre');
448 var html = utils.fixCarriageReturn(
448 var html = utils.fixCarriageReturn(
449 pre.html() + utils.fixConsole(text));
449 pre.html() + utils.fixConsole(text));
450 pre.html(html);
450 pre.html(html);
451 return;
451 return;
452 }
452 }
453 }
453 }
454
454
455 if (!text.replace("\r", "")) {
455 if (!text.replace("\r", "")) {
456 // text is nothing (empty string, \r, etc.)
456 // text is nothing (empty string, \r, etc.)
457 // so don't append any elements, which might add undesirable space
457 // so don't append any elements, which might add undesirable space
458 return;
458 return;
459 }
459 }
460
460
461 // If we got here, attach a new div
461 // If we got here, attach a new div
462 var toinsert = this.create_output_area();
462 var toinsert = this.create_output_area();
463 this.append_text(text, {}, toinsert, "output_stream "+subclass);
463 this.append_text(text, {}, toinsert, "output_stream "+subclass);
464 this._safe_append(toinsert);
464 this._safe_append(toinsert);
465 };
465 };
466
466
467
467
468 OutputArea.prototype.append_display_data = function (json) {
468 OutputArea.prototype.append_display_data = function (json) {
469 var toinsert = this.create_output_area();
469 var toinsert = this.create_output_area();
470 if (this.append_mime_type(json, toinsert)) {
470 if (this.append_mime_type(json, toinsert)) {
471 this._safe_append(toinsert);
471 this._safe_append(toinsert);
472 // If we just output latex, typeset it.
472 // If we just output latex, typeset it.
473 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
473 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
474 this.typeset();
474 this.typeset();
475 }
475 }
476 }
476 }
477 };
477 };
478
478
479
479
480 OutputArea.safe_outputs = {
480 OutputArea.safe_outputs = {
481 'text/plain' : true,
481 'text/plain' : true,
482 'image/png' : true,
482 'image/png' : true,
483 'image/jpeg' : true
483 'image/jpeg' : true
484 };
484 };
485
485
486 OutputArea.prototype.append_mime_type = function (json, element) {
486 OutputArea.prototype.append_mime_type = function (json, element) {
487 for (var type_i in OutputArea.display_order) {
487 for (var type_i in OutputArea.display_order) {
488 var type = OutputArea.display_order[type_i];
488 var type = OutputArea.display_order[type_i];
489 var append = OutputArea.append_map[type];
489 var append = OutputArea.append_map[type];
490 if ((json[type] !== undefined) && append) {
490 if ((json[type] !== undefined) && append) {
491 if (!this.trusted && !OutputArea.safe_outputs[type]) {
491 if (!this.trusted && !OutputArea.safe_outputs[type]) {
492 // not trusted show warning and do not display
492 // not trusted show warning and do not display
493 var content = {
493 var content = {
494 text : "Untrusted " + type + " output ignored.",
494 text : "Untrusted " + type + " output ignored.",
495 stream : "stderr"
495 stream : "stderr"
496 }
496 }
497 this.append_stream(content);
497 this.append_stream(content);
498 continue;
498 continue;
499 }
499 }
500 var md = json.metadata || {};
500 var md = json.metadata || {};
501 var toinsert = append.apply(this, [json[type], md, element]);
501 var toinsert = append.apply(this, [json[type], md, element]);
502 $([IPython.events]).trigger('output_appended.OutputArea', [type, json[type], md, toinsert]);
502 $([IPython.events]).trigger('output_appended.OutputArea', [type, json[type], md, toinsert]);
503 return true;
503 return true;
504 }
504 }
505 }
505 }
506 return false;
506 return false;
507 };
507 };
508
508
509
509
510 OutputArea.prototype.append_html = function (html, md, element) {
510 OutputArea.prototype.append_html = function (html, md, element) {
511 var type = 'text/html';
511 var type = 'text/html';
512 var toinsert = this.create_output_subarea(md, "output_html rendered_html", type);
512 var toinsert = this.create_output_subarea(md, "output_html rendered_html", type);
513 IPython.keyboard_manager.register_events(toinsert);
513 IPython.keyboard_manager.register_events(toinsert);
514 toinsert.append(html);
514 toinsert.append(html);
515 element.append(toinsert);
515 element.append(toinsert);
516 return toinsert;
516 return toinsert;
517 };
517 };
518
518
519
519
520 OutputArea.prototype.append_javascript = function (js, md, element) {
520 OutputArea.prototype.append_javascript = function (js, md, element) {
521 // We just eval the JS code, element appears in the local scope.
521 // We just eval the JS code, element appears in the local scope.
522 var type = 'application/javascript';
522 var type = 'application/javascript';
523 var toinsert = this.create_output_subarea(md, "output_javascript", type);
523 var toinsert = this.create_output_subarea(md, "output_javascript", type);
524 IPython.keyboard_manager.register_events(toinsert);
524 IPython.keyboard_manager.register_events(toinsert);
525 element.append(toinsert);
525 element.append(toinsert);
526 // FIXME TODO : remove `container element for 3.0`
526 // FIXME TODO : remove `container element for 3.0`
527 //backward compat, js should be eval'ed in a context where `container` is defined.
527 //backward compat, js should be eval'ed in a context where `container` is defined.
528 var container = element;
528 var container = element;
529 container.show = function(){console.log('Warning "container.show()" is deprecated.')};
529 container.show = function(){console.log('Warning "container.show()" is deprecated.')};
530 // end backward compat
530 // end backward compat
531 try {
531 try {
532 eval(js);
532 eval(js);
533 } catch(err) {
533 } catch(err) {
534 console.log(err);
534 console.log(err);
535 this._append_javascript_error(err, toinsert);
535 this._append_javascript_error(err, toinsert);
536 }
536 }
537 return toinsert;
537 return toinsert;
538 };
538 };
539
539
540
540
541 OutputArea.prototype.append_text = function (data, md, element, extra_class) {
541 OutputArea.prototype.append_text = function (data, md, element, extra_class) {
542 var type = 'text/plain';
542 var type = 'text/plain';
543 var toinsert = this.create_output_subarea(md, "output_text", type);
543 var toinsert = this.create_output_subarea(md, "output_text", type);
544 // escape ANSI & HTML specials in plaintext:
544 // escape ANSI & HTML specials in plaintext:
545 data = utils.fixConsole(data);
545 data = utils.fixConsole(data);
546 data = utils.fixCarriageReturn(data);
546 data = utils.fixCarriageReturn(data);
547 data = utils.autoLinkUrls(data);
547 data = utils.autoLinkUrls(data);
548 if (extra_class){
548 if (extra_class){
549 toinsert.addClass(extra_class);
549 toinsert.addClass(extra_class);
550 }
550 }
551 toinsert.append($("<pre/>").html(data));
551 toinsert.append($("<pre/>").html(data));
552 element.append(toinsert);
552 element.append(toinsert);
553 return toinsert;
553 return toinsert;
554 };
554 };
555
555
556
556
557 OutputArea.prototype.append_svg = function (svg, md, element) {
557 OutputArea.prototype.append_svg = function (svg, md, element) {
558 var type = 'image/svg+xml';
558 var type = 'image/svg+xml';
559 var toinsert = this.create_output_subarea(md, "output_svg", type);
559 var toinsert = this.create_output_subarea(md, "output_svg", type);
560 toinsert.append(svg);
560 toinsert.append(svg);
561 element.append(toinsert);
561 element.append(toinsert);
562 return toinsert;
562 return toinsert;
563 };
563 };
564
564
565
565
566 OutputArea.prototype._dblclick_to_reset_size = function (img) {
566 OutputArea.prototype._dblclick_to_reset_size = function (img) {
567 // schedule wrapping image in resizable after a delay,
567 // wrap image after it's loaded on the page,
568 // so we don't end up calling resize on a zero-size object
568 // otherwise the measured initial size will be incorrect
569 var that = this;
569 img.on("load", function (){
570 setTimeout(function () {
571 var h0 = img.height();
570 var h0 = img.height();
572 var w0 = img.width();
571 var w0 = img.width();
573 if (!(h0 && w0)) {
572 if (!(h0 && w0)) {
574 // zero size, schedule another timeout
573 // zero size, don't make it resizable
575 that._dblclick_to_reset_size(img);
576 return;
574 return;
577 }
575 }
578 img.resizable({
576 img.resizable({
579 aspectRatio: true,
577 aspectRatio: true,
580 autoHide: true
578 autoHide: true
581 });
579 });
582 img.dblclick(function () {
580 img.dblclick(function () {
583 // resize wrapper & image together for some reason:
581 // resize wrapper & image together for some reason:
584 img.parent().height(h0);
582 img.parent().height(h0);
585 img.height(h0);
583 img.height(h0);
586 img.parent().width(w0);
584 img.parent().width(w0);
587 img.width(w0);
585 img.width(w0);
588 });
586 });
589 }, 250);
587 });
590 };
588 };
591
589
592 var set_width_height = function (img, md, mime) {
590 var set_width_height = function (img, md, mime) {
593 // set width and height of an img element from metadata
591 // set width and height of an img element from metadata
594 var height = _get_metadata_key(md, 'height', mime);
592 var height = _get_metadata_key(md, 'height', mime);
595 if (height !== undefined) img.attr('height', height);
593 if (height !== undefined) img.attr('height', height);
596 var width = _get_metadata_key(md, 'width', mime);
594 var width = _get_metadata_key(md, 'width', mime);
597 if (width !== undefined) img.attr('width', width);
595 if (width !== undefined) img.attr('width', width);
598 };
596 };
599
597
600 OutputArea.prototype.append_png = function (png, md, element) {
598 OutputArea.prototype.append_png = function (png, md, element) {
601 var type = 'image/png';
599 var type = 'image/png';
602 var toinsert = this.create_output_subarea(md, "output_png", type);
600 var toinsert = this.create_output_subarea(md, "output_png", type);
603 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
601 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
604 set_width_height(img, md, 'image/png');
602 set_width_height(img, md, 'image/png');
605 this._dblclick_to_reset_size(img);
603 this._dblclick_to_reset_size(img);
606 toinsert.append(img);
604 toinsert.append(img);
607 element.append(toinsert);
605 element.append(toinsert);
608 return toinsert;
606 return toinsert;
609 };
607 };
610
608
611
609
612 OutputArea.prototype.append_jpeg = function (jpeg, md, element) {
610 OutputArea.prototype.append_jpeg = function (jpeg, md, element) {
613 var type = 'image/jpeg';
611 var type = 'image/jpeg';
614 var toinsert = this.create_output_subarea(md, "output_jpeg", type);
612 var toinsert = this.create_output_subarea(md, "output_jpeg", type);
615 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
613 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
616 set_width_height(img, md, 'image/jpeg');
614 set_width_height(img, md, 'image/jpeg');
617 this._dblclick_to_reset_size(img);
615 this._dblclick_to_reset_size(img);
618 toinsert.append(img);
616 toinsert.append(img);
619 element.append(toinsert);
617 element.append(toinsert);
620 return toinsert;
618 return toinsert;
621 };
619 };
622
620
623
621
624 OutputArea.prototype.append_pdf = function (pdf, md, element) {
622 OutputArea.prototype.append_pdf = function (pdf, md, element) {
625 var type = 'application/pdf';
623 var type = 'application/pdf';
626 var toinsert = this.create_output_subarea(md, "output_pdf", type);
624 var toinsert = this.create_output_subarea(md, "output_pdf", type);
627 var a = $('<a/>').attr('href', 'data:application/pdf;base64,'+pdf);
625 var a = $('<a/>').attr('href', 'data:application/pdf;base64,'+pdf);
628 a.attr('target', '_blank');
626 a.attr('target', '_blank');
629 a.text('View PDF')
627 a.text('View PDF')
630 toinsert.append(a);
628 toinsert.append(a);
631 element.append(toinsert);
629 element.append(toinsert);
632 return toinsert;
630 return toinsert;
633 }
631 }
634
632
635 OutputArea.prototype.append_latex = function (latex, md, element) {
633 OutputArea.prototype.append_latex = function (latex, md, element) {
636 // This method cannot do the typesetting because the latex first has to
634 // This method cannot do the typesetting because the latex first has to
637 // be on the page.
635 // be on the page.
638 var type = 'text/latex';
636 var type = 'text/latex';
639 var toinsert = this.create_output_subarea(md, "output_latex", type);
637 var toinsert = this.create_output_subarea(md, "output_latex", type);
640 toinsert.append(latex);
638 toinsert.append(latex);
641 element.append(toinsert);
639 element.append(toinsert);
642 return toinsert;
640 return toinsert;
643 };
641 };
644
642
645
643
646 OutputArea.prototype.append_raw_input = function (msg) {
644 OutputArea.prototype.append_raw_input = function (msg) {
647 var that = this;
645 var that = this;
648 this.expand();
646 this.expand();
649 var content = msg.content;
647 var content = msg.content;
650 var area = this.create_output_area();
648 var area = this.create_output_area();
651
649
652 // disable any other raw_inputs, if they are left around
650 // disable any other raw_inputs, if they are left around
653 $("div.output_subarea.raw_input").remove();
651 $("div.output_subarea.raw_input").remove();
654
652
655 area.append(
653 area.append(
656 $("<div/>")
654 $("<div/>")
657 .addClass("box-flex1 output_subarea raw_input")
655 .addClass("box-flex1 output_subarea raw_input")
658 .append(
656 .append(
659 $("<span/>")
657 $("<span/>")
660 .addClass("input_prompt")
658 .addClass("input_prompt")
661 .text(content.prompt)
659 .text(content.prompt)
662 )
660 )
663 .append(
661 .append(
664 $("<input/>")
662 $("<input/>")
665 .addClass("raw_input")
663 .addClass("raw_input")
666 .attr('type', 'text')
664 .attr('type', 'text')
667 .attr("size", 47)
665 .attr("size", 47)
668 .keydown(function (event, ui) {
666 .keydown(function (event, ui) {
669 // make sure we submit on enter,
667 // make sure we submit on enter,
670 // and don't re-execute the *cell* on shift-enter
668 // and don't re-execute the *cell* on shift-enter
671 if (event.which === utils.keycodes.ENTER) {
669 if (event.which === utils.keycodes.ENTER) {
672 that._submit_raw_input();
670 that._submit_raw_input();
673 return false;
671 return false;
674 }
672 }
675 })
673 })
676 )
674 )
677 );
675 );
678
676
679 this.element.append(area);
677 this.element.append(area);
680 var raw_input = area.find('input.raw_input');
678 var raw_input = area.find('input.raw_input');
681 // Register events that enable/disable the keyboard manager while raw
679 // Register events that enable/disable the keyboard manager while raw
682 // input is focused.
680 // input is focused.
683 IPython.keyboard_manager.register_events(raw_input);
681 IPython.keyboard_manager.register_events(raw_input);
684 // Note, the following line used to read raw_input.focus().focus().
682 // Note, the following line used to read raw_input.focus().focus().
685 // This seemed to be needed otherwise only the cell would be focused.
683 // This seemed to be needed otherwise only the cell would be focused.
686 // But with the modal UI, this seems to work fine with one call to focus().
684 // But with the modal UI, this seems to work fine with one call to focus().
687 raw_input.focus();
685 raw_input.focus();
688 }
686 }
689
687
690 OutputArea.prototype._submit_raw_input = function (evt) {
688 OutputArea.prototype._submit_raw_input = function (evt) {
691 var container = this.element.find("div.raw_input");
689 var container = this.element.find("div.raw_input");
692 var theprompt = container.find("span.input_prompt");
690 var theprompt = container.find("span.input_prompt");
693 var theinput = container.find("input.raw_input");
691 var theinput = container.find("input.raw_input");
694 var value = theinput.val();
692 var value = theinput.val();
695 var content = {
693 var content = {
696 output_type : 'stream',
694 output_type : 'stream',
697 name : 'stdout',
695 name : 'stdout',
698 text : theprompt.text() + value + '\n'
696 text : theprompt.text() + value + '\n'
699 }
697 }
700 // remove form container
698 // remove form container
701 container.parent().remove();
699 container.parent().remove();
702 // replace with plaintext version in stdout
700 // replace with plaintext version in stdout
703 this.append_output(content, false);
701 this.append_output(content, false);
704 $([IPython.events]).trigger('send_input_reply.Kernel', value);
702 $([IPython.events]).trigger('send_input_reply.Kernel', value);
705 }
703 }
706
704
707
705
708 OutputArea.prototype.handle_clear_output = function (msg) {
706 OutputArea.prototype.handle_clear_output = function (msg) {
709 // msg spec v4 had stdout, stderr, display keys
707 // msg spec v4 had stdout, stderr, display keys
710 // v4.1 replaced these with just wait
708 // v4.1 replaced these with just wait
711 // The default behavior is the same (stdout=stderr=display=True, wait=False),
709 // The default behavior is the same (stdout=stderr=display=True, wait=False),
712 // so v4 messages will still be properly handled,
710 // so v4 messages will still be properly handled,
713 // except for the rarely used clearing less than all output.
711 // except for the rarely used clearing less than all output.
714 this.clear_output(msg.content.wait || false);
712 this.clear_output(msg.content.wait || false);
715 };
713 };
716
714
717
715
718 OutputArea.prototype.clear_output = function(wait) {
716 OutputArea.prototype.clear_output = function(wait) {
719 if (wait) {
717 if (wait) {
720
718
721 // If a clear is queued, clear before adding another to the queue.
719 // If a clear is queued, clear before adding another to the queue.
722 if (this.clear_queued) {
720 if (this.clear_queued) {
723 this.clear_output(false);
721 this.clear_output(false);
724 };
722 };
725
723
726 this.clear_queued = true;
724 this.clear_queued = true;
727 } else {
725 } else {
728
726
729 // Fix the output div's height if the clear_output is waiting for
727 // Fix the output div's height if the clear_output is waiting for
730 // new output (it is being used in an animation).
728 // new output (it is being used in an animation).
731 if (this.clear_queued) {
729 if (this.clear_queued) {
732 var height = this.element.height();
730 var height = this.element.height();
733 this.element.height(height);
731 this.element.height(height);
734 this.clear_queued = false;
732 this.clear_queued = false;
735 }
733 }
736
734
737 // clear all, no need for logic
735 // clear all, no need for logic
738 this.element.html("");
736 this.element.html("");
739 this.outputs = [];
737 this.outputs = [];
740 this.trusted = true;
738 this.trusted = true;
741 this.unscroll_area();
739 this.unscroll_area();
742 return;
740 return;
743 };
741 };
744 };
742 };
745
743
746
744
747 // JSON serialization
745 // JSON serialization
748
746
749 OutputArea.prototype.fromJSON = function (outputs) {
747 OutputArea.prototype.fromJSON = function (outputs) {
750 var len = outputs.length;
748 var len = outputs.length;
751 var data;
749 var data;
752
750
753 for (var i=0; i<len; i++) {
751 for (var i=0; i<len; i++) {
754 data = outputs[i];
752 data = outputs[i];
755 var msg_type = data.output_type;
753 var msg_type = data.output_type;
756 if (msg_type === "display_data" || msg_type === "pyout") {
754 if (msg_type === "display_data" || msg_type === "pyout") {
757 // convert short keys to mime keys
755 // convert short keys to mime keys
758 // TODO: remove mapping of short keys when we update to nbformat 4
756 // TODO: remove mapping of short keys when we update to nbformat 4
759 data = this.rename_keys(data, OutputArea.mime_map_r);
757 data = this.rename_keys(data, OutputArea.mime_map_r);
760 data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map_r);
758 data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map_r);
761 }
759 }
762
760
763 this.append_output(data);
761 this.append_output(data);
764 }
762 }
765 };
763 };
766
764
767
765
768 OutputArea.prototype.toJSON = function () {
766 OutputArea.prototype.toJSON = function () {
769 var outputs = [];
767 var outputs = [];
770 var len = this.outputs.length;
768 var len = this.outputs.length;
771 var data;
769 var data;
772 for (var i=0; i<len; i++) {
770 for (var i=0; i<len; i++) {
773 data = this.outputs[i];
771 data = this.outputs[i];
774 var msg_type = data.output_type;
772 var msg_type = data.output_type;
775 if (msg_type === "display_data" || msg_type === "pyout") {
773 if (msg_type === "display_data" || msg_type === "pyout") {
776 // convert mime keys to short keys
774 // convert mime keys to short keys
777 data = this.rename_keys(data, OutputArea.mime_map);
775 data = this.rename_keys(data, OutputArea.mime_map);
778 data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map);
776 data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map);
779 }
777 }
780 outputs[i] = data;
778 outputs[i] = data;
781 }
779 }
782 return outputs;
780 return outputs;
783 };
781 };
784
782
785 /**
783 /**
786 * Class properties
784 * Class properties
787 **/
785 **/
788
786
789 /**
787 /**
790 * Threshold to trigger autoscroll when the OutputArea is resized,
788 * Threshold to trigger autoscroll when the OutputArea is resized,
791 * typically when new outputs are added.
789 * typically when new outputs are added.
792 *
790 *
793 * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold,
791 * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold,
794 * unless it is < 0, in which case autoscroll will never be triggered
792 * unless it is < 0, in which case autoscroll will never be triggered
795 *
793 *
796 * @property auto_scroll_threshold
794 * @property auto_scroll_threshold
797 * @type Number
795 * @type Number
798 * @default 100
796 * @default 100
799 *
797 *
800 **/
798 **/
801 OutputArea.auto_scroll_threshold = 100;
799 OutputArea.auto_scroll_threshold = 100;
802
800
803 /**
801 /**
804 * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas
802 * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas
805 * shorter than this are never scrolled.
803 * shorter than this are never scrolled.
806 *
804 *
807 * @property minimum_scroll_threshold
805 * @property minimum_scroll_threshold
808 * @type Number
806 * @type Number
809 * @default 20
807 * @default 20
810 *
808 *
811 **/
809 **/
812 OutputArea.minimum_scroll_threshold = 20;
810 OutputArea.minimum_scroll_threshold = 20;
813
811
814
812
815
813
816 OutputArea.mime_map = {
814 OutputArea.mime_map = {
817 "text/plain" : "text",
815 "text/plain" : "text",
818 "text/html" : "html",
816 "text/html" : "html",
819 "image/svg+xml" : "svg",
817 "image/svg+xml" : "svg",
820 "image/png" : "png",
818 "image/png" : "png",
821 "image/jpeg" : "jpeg",
819 "image/jpeg" : "jpeg",
822 "text/latex" : "latex",
820 "text/latex" : "latex",
823 "application/json" : "json",
821 "application/json" : "json",
824 "application/javascript" : "javascript",
822 "application/javascript" : "javascript",
825 };
823 };
826
824
827 OutputArea.mime_map_r = {
825 OutputArea.mime_map_r = {
828 "text" : "text/plain",
826 "text" : "text/plain",
829 "html" : "text/html",
827 "html" : "text/html",
830 "svg" : "image/svg+xml",
828 "svg" : "image/svg+xml",
831 "png" : "image/png",
829 "png" : "image/png",
832 "jpeg" : "image/jpeg",
830 "jpeg" : "image/jpeg",
833 "latex" : "text/latex",
831 "latex" : "text/latex",
834 "json" : "application/json",
832 "json" : "application/json",
835 "javascript" : "application/javascript",
833 "javascript" : "application/javascript",
836 };
834 };
837
835
838 OutputArea.display_order = [
836 OutputArea.display_order = [
839 'application/javascript',
837 'application/javascript',
840 'text/html',
838 'text/html',
841 'text/latex',
839 'text/latex',
842 'image/svg+xml',
840 'image/svg+xml',
843 'image/png',
841 'image/png',
844 'image/jpeg',
842 'image/jpeg',
845 'application/pdf',
843 'application/pdf',
846 'text/plain'
844 'text/plain'
847 ];
845 ];
848
846
849 OutputArea.append_map = {
847 OutputArea.append_map = {
850 "text/plain" : OutputArea.prototype.append_text,
848 "text/plain" : OutputArea.prototype.append_text,
851 "text/html" : OutputArea.prototype.append_html,
849 "text/html" : OutputArea.prototype.append_html,
852 "image/svg+xml" : OutputArea.prototype.append_svg,
850 "image/svg+xml" : OutputArea.prototype.append_svg,
853 "image/png" : OutputArea.prototype.append_png,
851 "image/png" : OutputArea.prototype.append_png,
854 "image/jpeg" : OutputArea.prototype.append_jpeg,
852 "image/jpeg" : OutputArea.prototype.append_jpeg,
855 "text/latex" : OutputArea.prototype.append_latex,
853 "text/latex" : OutputArea.prototype.append_latex,
856 "application/javascript" : OutputArea.prototype.append_javascript,
854 "application/javascript" : OutputArea.prototype.append_javascript,
857 "application/pdf" : OutputArea.prototype.append_pdf
855 "application/pdf" : OutputArea.prototype.append_pdf
858 };
856 };
859
857
860 IPython.OutputArea = OutputArea;
858 IPython.OutputArea = OutputArea;
861
859
862 return IPython;
860 return IPython;
863
861
864 }(IPython));
862 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now