Skip to content

Commit dd29d0a

Browse files
committed
Merge pull request hcientist#29 from cemc/iframe_resize
iframe-embed.html option resizeContainer: automatic resize iframe height
2 parents 5465898 + 292da5f commit dd29d0a

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

‎v3/js/iframe-embed.js‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ $(document).ready(function() {
7777
}
7878

7979

80+
var resizeContainer = ($.bbq.getState('resizeContainer') == 'true');
81+
82+
if (resizeContainer) {
83+
function findContainer() {
84+
var ifs = window.top.document.getElementsByTagName("iframe");
85+
for(var i = 0, len = ifs.length; i < len; i++) {
86+
var f = ifs[i];
87+
var fDoc = f.contentDocument || f.contentWindow.document;
88+
if(fDoc === document) {
89+
return f;
90+
}
91+
}
92+
}
93+
94+
var container = findContainer();
95+
96+
function resizeContainerNow() {
97+
$(container).height($("#vizDiv").height()+20);
98+
};
99+
100+
$("body").on("click", "button", resizeContainerNow);
101+
$("body").on("slide", ".ui-slider", resizeContainerNow);
102+
}
103+
104+
80105
$.get(backend_script,
81106
{user_script : preseededCode,
82107
options_json: JSON.stringify(options)},
@@ -116,6 +141,7 @@ $(document).ready(function() {
116141
textualMemoryLabels: textRefsBool,
117142
showOnlyOutputs: showOnlyOutputsBool,
118143
});
144+
if (resizeContainer) resizeContainerNow();
119145
}
120146
},
121147
"json");
@@ -129,7 +155,7 @@ $(document).ready(function() {
129155

130156
// redraw connector arrows on window resize
131157
$(window).resize(function() {
132-
if (appMode == 'display') {
158+
if (typeof appMode !== "undefined" && appMode == 'display') {
133159
myVisualizer.redrawConnectors();
134160
}
135161
});

0 commit comments

Comments
 (0)