diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index fe6422ca9..12f219f52 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -326,7 +326,51 @@ var IPython = (function (IPython) { } return oa; }; - + + + OutputArea.prototype.create_output_subarea = function(md, classes) { + var subarea = $('
').addClass('output_subarea').addClass(classes); + if (md['isolated']) { + // Create an iframe to isolate the subarea from the rest of the + // document + var iframe = $('').addClass('box-flex1'); + iframe.css({'height':1, 'width':'100%', 'display':'block'}); + iframe.attr('frameborder', 0); + iframe.attr('scrolling', 'auto'); + + // Once the iframe is loaded, the subarea is dynamically inserted + iframe.on('load', function() { + // Workaround needed by Firefox, to properly render svg inside + // iframes, see http://stackoverflow.com/questions/10177190/ + // svg-dynamically-added-to-iframe-does-not-render-correctly + this.contentDocument.open(); + + // Insert the subarea into the iframe + // We must directly write the html. When using Jquery's append + // method, javascript is evaluated in the parent document and + // not in the iframe document. + this.contentDocument.write(subarea.html()); + + this.contentDocument.close(); + + var body = this.contentDocument.body; + // Adjust the iframe height automatically + iframe.height(body.scrollHeight + 'px'); + }); + + // Elements should be appended to the inner subarea and not to the + // iframe + iframe.append = function(that) { + subarea.append(that); + }; + + return iframe; + } else { + return subarea; + } + } + + OutputArea.prototype._append_javascript_error = function (err, container) { // display a message when a javascript error occurs in display output var msg = "Javascript error adding output!" @@ -460,7 +504,7 @@ var IPython = (function (IPython) { OutputArea.prototype.append_html = function (html, md, element) { - var toinsert = $("").addClass("output_subarea output_html rendered_html"); + var toinsert = this.create_output_subarea(md, "output_html rendered_html"); toinsert.append(html); element.append(toinsert); }; @@ -468,7 +512,7 @@ var IPython = (function (IPython) { OutputArea.prototype.append_javascript = function (js, md, container) { // We just eval the JS code, element appears in the local scope. - var element = $("").addClass("output_subarea"); + var element = this.create_output_subarea(md, ""); container.append(element); // Div for js shouldn't be drawn, as it will add empty height to the area. container.hide(); @@ -483,7 +527,7 @@ var IPython = (function (IPython) { OutputArea.prototype.append_text = function (data, md, element, extra_class) { - var toinsert = $("").addClass("output_subarea output_text"); + var toinsert = this.create_output_subarea(md, "output_text"); // escape ANSI & HTML specials in plaintext: data = utils.fixConsole(data); data = utils.fixCarriageReturn(data); @@ -497,7 +541,7 @@ var IPython = (function (IPython) { OutputArea.prototype.append_svg = function (svg, md, element) { - var toinsert = $("").addClass("output_subarea output_svg"); + var toinsert = this.create_output_subarea(md, "output_svg"); toinsert.append(svg); element.append(toinsert); }; @@ -531,7 +575,7 @@ var IPython = (function (IPython) { OutputArea.prototype.append_png = function (png, md, element) { - var toinsert = $("").addClass("output_subarea output_png"); + var toinsert = this.create_output_subarea(md, "output_png"); var img = $("