Closed winstromming closed 10 years ago
would share piece of code, whenever useful or not...
In order to reduce dependencies to the parent template.hbs for setting the correct iframe height with the window.onload function(){}
. This ugly onload
-oneliner works also.
<iframe id="sassdown-iframe{{@index}}" height="0" src="about:blank" onload="javascript:this.height=this.contentWindow.document.body.scrollHeight;"></iframe>
just found pym.js while browsing the trending javascript repos. maybe useful in this context.
Using iframes in a responsive page can be frustrating. It’s easy enough to make an iframe’s width span 100% of its container, but sizing its height is tricky — especially if the content of the iframe changes height depending on page width (for example, because of text wrapping or media queries) or events within the iframe.
Pym.js embeds and resizes an iframe responsively (width and height) within its parent container. It also bypasses the usual cross-domain issues.
In order to reduce style conflicts and safely sandbox elements, examples currently render into an
iframe
. This process is slightly complicated by the need to preserve indentation, linebreaks, whitespace and syntax highlighting.We do this by writing the
{{ result }}
into ascript
element, then inserting thatinnerHTML
into theiframe
before removing the placeholder nodes from the DOM. This is messy and can be abstracted out of the actual .hbs file.Current:
Desired: