@@ -40,6 +40,7 @@ module.exports = function(node) {
4040 show ( node . querySelector ( "[data-tab=js]" ) ) ;
4141 }
4242
43+ resizeIframe ( ) ;
4344 tabs ( ) ;
4445 }
4546
@@ -131,4 +132,30 @@ module.exports = function(node) {
131132 txt = txt . replace ( / < / g, "<" ) ;
132133 return typeof prettyPrintOne !== "undefined" ? prettyPrintOne ( txt ) : txt ;
133134 }
135+
136+ function resizeIframe ( ) {
137+ var frame = node . getElementsByTagName ( "iframe" ) [ 0 ] ;
138+ var height = frame . contentWindow . document . body . scrollHeight ;
139+
140+ var tolerance = 5 ; // pixels
141+ var low = height - tolerance ;
142+ var high = height + tolerance ;
143+
144+ // turns "150px" to 150, and "" to 0
145+ var getCssHeight = function ( ) {
146+ var h = frame . style . height ;
147+ return Number ( h . substr ( 0 , h . length - 2 ) || 0 ) ;
148+ } ;
149+
150+ var cssHeight = getCssHeight ( ) ;
151+
152+ // Setting the height causes the next resizeIframe call to get a different
153+ // height reading (lower); The range/tolerance logic is added to prevent the
154+ // continous shrinking of the iframe
155+ if ( cssHeight < low || cssHeight > high ) {
156+ iframe . style . height = Math . min ( high , 600 ) + "px" ;
157+ }
158+
159+ setTimeout ( resizeIframe , 1000 ) ;
160+ }
134161} ;
0 commit comments