@@ -40,6 +40,7 @@ module.exports = function(node) {
40
40
show ( node . querySelector ( "[data-tab=js]" ) ) ;
41
41
}
42
42
43
+ resizeIframe ( ) ;
43
44
tabs ( ) ;
44
45
}
45
46
@@ -131,4 +132,30 @@ module.exports = function(node) {
131
132
txt = txt . replace ( / < / g, "<" ) ;
132
133
return typeof prettyPrintOne !== "undefined" ? prettyPrintOne ( txt ) : txt ;
133
134
}
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
+ }
134
161
} ;
0 commit comments